QGIS API Documentation 3.37.0-Master (614ebf5f6b2)
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
43 Q_OBJECT
44
45 public:
46
47 ColorDelegate( QObject *parent = nullptr ): QStyledItemDelegate( parent ) {};
48
49 // QAbstractItemDelegate interface
50 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
51 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
52 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
53};
54
55class ColorAlphaDelegate: public ColorDelegate
56{
57
58 Q_OBJECT
59
60 public:
61
62 ColorAlphaDelegate( QObject *parent = nullptr ): ColorDelegate( parent ) {};
63
64 // QAbstractItemDelegate interface
65 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
66};
67
68class ColorRampDelegate: public QStyledItemDelegate
69{
70
71 Q_OBJECT
72
73 public:
74
75 ColorRampDelegate( QObject *parent = nullptr ): QStyledItemDelegate( parent ) {};
76
77 // QAbstractItemDelegate interface
78 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
79 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
80 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
81 void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
82
83 protected:
84
86
87};
88
89class ColorRampAlphaDelegate: public ColorRampDelegate
90{
91
92 Q_OBJECT
93
94 public:
95
96 ColorRampAlphaDelegate( QObject *parent = nullptr ): ColorRampDelegate( parent ) {};
97
98 // QAbstractItemDelegate interface
99 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
100};
101
102
103class LocalizedDoubleDelegate: public QgsLocaleAwareNumericLineEditDelegate
104{
105
106 Q_OBJECT
107
108 public:
109
110 LocalizedDoubleDelegate( QWidget *parent = nullptr ): QgsLocaleAwareNumericLineEditDelegate( Qgis::DataType::Float64, parent ) {};
111
112 // QStyledItemDelegate interface
113 QString displayText( const QVariant &value, const QLocale &locale ) const override;
114};
115
116
117
118#endif
120
126class GUI_EXPORT QgsRasterAttributeTableWidget : public QgsPanelWidget, private Ui::QgsRasterAttributeTableWidgetBase
127{
128 Q_OBJECT
129
130 public:
131
138 explicit QgsRasterAttributeTableWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsRasterLayer *rasterLayer = nullptr, const int bandNumber = 0 );
139
145 void setRasterLayer( QgsRasterLayer *rasterLayer, const int bandNumber = 0 );
146
150 bool isDirty( ) const;
151
156 void setMessageBar( QgsMessageBar *bar );
157
158 signals:
159
163 void rendererChanged( );
164
165 public slots:
166
170 void saveChanges();
171
177 bool setEditable( bool editable, bool allowCancel = true );
178
179 private:
180
181 void classify();
182 void addColumn();
183 void removeColumn();
184 void addRow();
185 void removeRow();
186 void bandChanged( const int index );
187 void notify( const QString &title, const QString &message, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
188 void setDelegates( );
189
190 QgsRasterLayer *mRasterLayer = nullptr;
191 std::unique_ptr<QgsRasterAttributeTable> mAttributeTableBuffer;
192 // Default to invalid (bands are 1-indexed)
193 int mCurrentBand = 0;
194 bool mEditable = false;
195
196 std::unique_ptr<QgsRasterAttributeTableModel> mModel;
197
198 QAction *mActionToggleEditing = nullptr;
199 QAction *mActionAddColumn = nullptr;
200 QAction *mActionRemoveColumn = nullptr;
201 QAction *mActionAddRow = nullptr;
202 QAction *mActionRemoveRow = nullptr;
203 QAction *mActionSaveChanges = nullptr;
204
205 QgsMessageBar *mMessageBar = nullptr;
206 QSortFilterProxyModel *mProxyModel = nullptr;
207
208 void init( int bandNumber = 0 );
209 void updateButtons();
210
211 // QgsPanelWidget interface
212 public:
213 void setDockMode( bool dockMode ) override;
214};
215
216#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:99
@ Info
Information message.
Definition qgis.h:100
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