QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsrasterattributetablewidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasterattributetablewidget.h - QgsRasterAttributeTableWidget
3
4 ---------------------
5 begin : 6.10.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 QGSRASTERATTRIBUTETABLEWIDGET_H
17#define QGSRASTERATTRIBUTETABLEWIDGET_H
18
19#include "qgis_gui.h"
20#include "ui_qgsrasterattributetablewidgetbase.h"
22#include "qgscolorrampimpl.h"
23#include "qgspanelwidget.h"
25
26#include <QWidget>
27#include <QStyledItemDelegate>
28
29
30#ifndef SIP_RUN
31class QgsRasterLayer;
33class QgsMessageBar;
34class QSortFilterProxyModel;
35#endif
36
37
39#ifndef SIP_RUN
40class ColorDelegate : public QStyledItemDelegate
41{
42 Q_OBJECT
43
44 public:
45 ColorDelegate( QObject *parent = nullptr )
46 : QStyledItemDelegate( parent ) {};
47
48 // QAbstractItemDelegate interface
49 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
50 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
51 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
52};
53
54class ColorAlphaDelegate : public ColorDelegate
55{
56 Q_OBJECT
57
58 public:
59 ColorAlphaDelegate( QObject *parent = nullptr )
60 : ColorDelegate( parent ) {};
61
62 // QAbstractItemDelegate interface
63 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
64};
65
66class ColorRampDelegate : public QStyledItemDelegate
67{
68 Q_OBJECT
69
70 public:
71 ColorRampDelegate( QObject *parent = nullptr )
72 : QStyledItemDelegate( parent ) {};
73
74 // QAbstractItemDelegate interface
75 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
76 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
77 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
78 void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
79
80 protected:
82};
83
84class ColorRampAlphaDelegate : public ColorRampDelegate
85{
86 Q_OBJECT
87
88 public:
89 ColorRampAlphaDelegate( QObject *parent = nullptr )
90 : ColorRampDelegate( parent ) {};
91
92 // QAbstractItemDelegate interface
93 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
94};
95
96
97class LocalizedDoubleDelegate : public QgsLocaleAwareNumericLineEditDelegate
98{
99 Q_OBJECT
100
101 public:
102 LocalizedDoubleDelegate( QWidget *parent = nullptr )
103 : QgsLocaleAwareNumericLineEditDelegate( Qgis::DataType::Float64, parent ) {};
104
105 // QStyledItemDelegate interface
106 QString displayText( const QVariant &value, const QLocale &locale ) const override;
107};
108
109
110#endif
112
118class GUI_EXPORT QgsRasterAttributeTableWidget : public QgsPanelWidget, private Ui::QgsRasterAttributeTableWidgetBase
119{
120 Q_OBJECT
121
122 public:
129 explicit QgsRasterAttributeTableWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsRasterLayer *rasterLayer = nullptr, const int bandNumber = 0 );
130
136 void setRasterLayer( QgsRasterLayer *rasterLayer, const int bandNumber = 0 );
137
141 bool isDirty() const;
142
147 void setMessageBar( QgsMessageBar *bar );
148
149 signals:
150
154 void rendererChanged();
155
156 public slots:
157
161 void saveChanges();
162
168 bool setEditable( bool editable, bool allowCancel = true );
169
170 private:
171 void classify();
172 void addColumn();
173 void removeColumn();
174 void addRow();
175 void removeRow();
176 void bandChanged( const int index );
177 void notify( const QString &title, const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
178 void setDelegates();
179
180 QgsRasterLayer *mRasterLayer = nullptr;
181 std::unique_ptr<QgsRasterAttributeTable> mAttributeTableBuffer;
182 // Default to invalid (bands are 1-indexed)
183 int mCurrentBand = 0;
184 bool mEditable = false;
185
186 std::unique_ptr<QgsRasterAttributeTableModel> mModel;
187
188 QAction *mActionToggleEditing = nullptr;
189 QAction *mActionAddColumn = nullptr;
190 QAction *mActionRemoveColumn = nullptr;
191 QAction *mActionAddRow = nullptr;
192 QAction *mActionRemoveRow = nullptr;
193 QAction *mActionSaveChanges = nullptr;
194
195 QgsMessageBar *mMessageBar = nullptr;
196 QSortFilterProxyModel *mProxyModel = nullptr;
197
198 void init( int bandNumber = 0 );
199 void updateButtons();
200
201 // QgsPanelWidget interface
202 public:
203 void setDockMode( bool dockMode ) override;
204};
205
206#endif // QGSRASTERATTRIBUTETABLEWIDGET_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:154
@ Info
Information message.
Definition qgis.h:155
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
A bar for displaying non-blocking messages to the user.
Base class for any widget that can be shown as a inline panel.
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
The QgsRasterAttributeTable class represents a Raster Attribute Table (RAT).
Represents a raster layer.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53