QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsrasterattributetablemodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasterattributetablemodel.h - QgsRasterAttributeTableModel
3
4 ---------------------
5 begin : 29.9.2022
6 copyright : (C) 2022 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSRASTERATTRIBUTETABLEMODEL_H
17#define QGSRASTERATTRIBUTETABLEMODEL_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
22
23#include <QAbstractTableModel>
24#include <QObject>
25
31class GUI_EXPORT QgsRasterAttributeTableModel : public QAbstractTableModel
32{
33 Q_OBJECT
34
35 public:
36
40 explicit QgsRasterAttributeTableModel( QgsRasterAttributeTable *rat, QObject *parent SIP_TRANSFERTHIS = nullptr );
41
45 bool editable() const;
46
50 void setEditable( bool editable );
51
55 bool hasColor() const;
56
60 bool hasRamp() const;
61
65 QStringList headerNames() const;
66
70 QString headerTooltip( const int section ) const;
71
75 bool isValid( QString *errorMessage SIP_OUT = nullptr );
76
80 bool isDirty();
81
82 // Raster Attribute Table operations
83
93 bool insertField( const int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QMetaType::Type type, QString *errorMessage SIP_OUT = nullptr );
94
105 Q_DECL_DEPRECATED bool insertField( const int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage SIP_OUT = nullptr ) SIP_DEPRECATED;
106
110 bool removeField( const int position, QString *errorMessage SIP_OUT = nullptr );
111
115 bool removeColorOrRamp( QString *errorMessage SIP_OUT = nullptr );
116
120 bool insertRow( const int position, const QVariantList &rowData, QString *errorMessage SIP_OUT = nullptr );
121
125 bool insertColor( int position, QString *errorMessage SIP_OUT = nullptr );
126
130 bool insertRamp( int position, QString *errorMessage SIP_OUT = nullptr );
131
135 bool removeRow( const int position, QString *errorMessage SIP_OUT = nullptr );
136
137 private:
138 QgsRasterAttributeTable *mRat = nullptr;
139 bool mEditable = false;
140
141 // Checks for rat not nullptr and editable state
142 bool editChecks( QString *errorMessage = nullptr );
143
144 QString ratColorHeaderName() const;
145
146 // QAbstractItemModel interface
147 public:
148 int rowCount( const QModelIndex &parent ) const override;
149 int columnCount( const QModelIndex &parent ) const override;
150 QVariant data( const QModelIndex &index, int role ) const override;
151 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
152 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
153 Qt::ItemFlags flags( const QModelIndex &index ) const override;
154};
155
156#endif // QGSRASTERATTRIBUTETABLEMODEL_H
RasterAttributeTableFieldUsage
The RasterAttributeTableFieldUsage enum represents the usage of a Raster Attribute Table field.
Definition qgis.h:1587
QStringList headerNames() const
Returns all the header names, including the "virtual" color header if the Raster Attribute Table has ...
bool removeColorOrRamp(QString *errorMessage=nullptr)
Removes all color or ramp information, optionally reporting any error in errorMessage,...
bool hasRamp() const
Returns true if the Raster Attribute Table has ramp information.
int rowCount(const QModelIndex &parent) const override
bool isDirty()
Returns true if the Raster Attribute Table was modified since it was last saved or read.
bool hasColor() const
Returns true if the Raster Attribute Table has color information.
bool removeField(const int position, QString *errorMessage=nullptr)
Remove the field at given position, optionally reporting any error in errorMessage,...
bool insertColor(int position, QString *errorMessage=nullptr)
Create RGBA fields and inserts them at position, optionally reporting any error in errorMessage,...
bool insertRow(const int position, const QVariantList &rowData, QString *errorMessage=nullptr)
Inserts a new row before position, optionally reporting any error in errorMessage,...
int columnCount(const QModelIndex &parent) const override
bool editable() const
Returns true if the Raster Attribute Table is editable.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
QString headerTooltip(const int section) const
Returns the tooltip for the given section.
bool setData(const QModelIndex &index, const QVariant &value, int role) override
void setEditable(bool editable)
Sets the Raster Attribute Table editable state to editable.
QgsRasterAttributeTableModel(QgsRasterAttributeTable *rat, QObject *parent=nullptr)
Creates a new QgsRasterAttributeTableModel from raster attribute table rat and optional parent.
bool insertField(const int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QMetaType::Type type, QString *errorMessage=nullptr)
Inserts a field at the given position.
bool isValid(QString *errorMessage=nullptr)
Checks if the Raster Attribute Table is valid, optionally returns validation errors in errorMessage.
QVariant data(const QModelIndex &index, int role) const override
bool insertRamp(int position, QString *errorMessage=nullptr)
Create RGBA minimum and maximum fields and inserts them at position, optionally reporting any error i...
Qt::ItemFlags flags(const QModelIndex &index) const override
bool removeRow(const int position, QString *errorMessage=nullptr)
Removes the row at position, optionally reporting any error in errorMessage, returns true on success.
Represents a Raster Attribute Table (RAT).
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_OUT
Definition qgis_sip.h:58