1 /*************************************************************************** 2 qgsrastertransparencywidget.h 3 --------------------- 4 begin : May 2016 5 copyright : (C) 2016 by Nathan Woodrow 6 email : woodrow dot nathan at gmail dot com 7 *************************************************************************** 8 * * 9 * This program is free software; you can redistribute it and/or modify * 10 * it under the terms of the GNU General Public License as published by * 11 * the Free Software Foundation; either version 2 of the License, or * 12 * (at your option) any later version. * 13 * * 14 ***************************************************************************/ 15 #ifndef QGSRASTERTRANSPARENCYWIDGET_H 16 #define QGSRASTERTRANSPARENCYWIDGET_H 17 18 #include <QWidget> 19 20 #include "ui_qgsrastertransparencywidget.h" 21 22 #include "qgsmaplayerconfigwidget.h" 23 #include "qgsrasterpipe.h" 24 #include "qgssymbolwidgetcontext.h" 25 26 #include "qgis_gui.h" 27 28 class QgsRasterLayer; 29 class QgsRasterRenderer; 30 class QgsMapCanvas; 31 class QgsMapToolEmitPoint; 32 class QgsPointXY; 33 34 /** 35 * \ingroup gui 36 * \brief Widget to control a layers transparency and related options 37 */ 38 class GUI_EXPORT QgsRasterTransparencyWidget : public QgsMapLayerConfigWidget, private QgsExpressionContextGenerator, public Ui::QgsRasterTransparencyWidget 39 { 40 Q_OBJECT 41 public: 42 43 /** 44 * \brief Widget to control a layers transparency and related options 45 */ 46 QgsRasterTransparencyWidget( QgsRasterLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr ); 47 48 /** 49 * Sets the \a context in which the dialog is shown, e.g., the associated map canvas and expression contexts. 50 * \since QGIS 3.22 51 */ 52 void setContext( const QgsSymbolWidgetContext &context ); 53 54 QgsExpressionContext createExpressionContext() const override; 55 56 /** 57 * Returns the (possibly nullptr) map pixel selector tool. 58 * \since QGIS 3.22 59 */ 60 QgsMapToolEmitPoint *pixelSelectorTool() const; 61 62 public slots: 63 64 #ifdef __clang__ 65 #pragma clang diagnostic push 66 #pragma clang diagnostic ignored "-Woverloaded-virtual" 67 #endif 68 69 /** 70 * Sync the widget state to the layer set for the widget. 71 */ 72 void syncToLayer(); 73 #ifdef __clang__ 74 #pragma clang diagnostic pop 75 #endif 76 77 /** 78 * Apply any changes on the widget to the set layer. 79 */ 80 void apply() override; 81 82 protected: 83 84 #ifndef SIP_RUN 85 86 // TODO -- consider moving these to a common raster widget base class 87 88 /** 89 * Registers a property override button, setting up its initial value, connections and description. 90 * \param button button to register 91 * \param key corresponding data defined property key 92 * \note Not available in Python bindings 93 * \since QGIS 3.22 94 */ 95 void initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsRasterPipe::Property key ); 96 97 /** 98 * Updates all property override buttons to reflect the widgets's current properties. 99 * \note Not available in Python bindings 100 * \since QGIS 3.22 101 */ 102 void updateDataDefinedButtons(); 103 104 /** 105 * Updates a specific property override \a button to reflect the widgets's current properties. 106 * \note Not available in Python bindings 107 * \since QGIS 3.22 108 */ 109 void updateDataDefinedButton( QgsPropertyOverrideButton *button ); 110 111 //! Temporary property collection 112 QgsPropertyCollection mPropertyCollection; 113 114 #endif 115 116 private slots: 117 118 void updateProperty(); 119 120 void pixelSelected( const QgsPointXY &canvasPoint ); 121 122 //! Transparency cell changed 123 void transparencyCellTextEdited( const QString &text ); 124 125 //! \brief slot executed when user presses "Add Values From Display" button on the transparency page 126 void pbnAddValuesFromDisplay_clicked(); 127 128 //! \brief slot executed when user presses "Add Values Manually" button on the transparency page 129 void pbnAddValuesManually_clicked(); 130 131 //! \brief slot executed when user wishes to reset noNoDataValue and transparencyTable to default value 132 void pbnDefaultValues_clicked(); 133 134 //! \brief slot executed when user wishes to export transparency values 135 void pbnExportTransparentPixelValues_clicked(); 136 137 //! \brief slow executed when user wishes to import transparency values 138 void pbnImportTransparentPixelValues_clicked(); 139 //! \brief slot executed when user presses "Remove Selected Row" button on the transparency page 140 void pbnRemoveSelectedRow_clicked(); 141 142 private: 143 //! \brief A constant that signals property not used 144 const QString TRSTRING_NOT_SET; 145 146 bool rasterIsMultiBandColor(); 147 148 //! \brief Clear the current transparency table and populate the table with the correct types for current drawing mode and data type 149 void populateTransparencyTable( QgsRasterRenderer *renderer ); 150 151 void setupTransparencyTable( int nBands ); 152 153 void setTransparencyCell( int row, int column, double value ); 154 155 void adjustTransparencyCellWidth( int row, int column ); 156 157 void setTransparencyToEdited( int row ); 158 159 double transparencyCellValue( int row, int column ); 160 161 QgsRasterLayer *mRasterLayer = nullptr; 162 163 QgsMapCanvas *mMapCanvas = nullptr; 164 165 QgsMapToolEmitPoint *mPixelSelectorTool = nullptr; 166 167 QVector<bool> mTransparencyToEdited; 168 169 //! Context in which widget is shown 170 QgsSymbolWidgetContext mContext; 171 }; 172 #endif // QGSRASTERTRANSPARENCYWIDGET_H 173