29
29
#include " qgscolorrampbutton.h"
30
30
#include " qgscolordialog.h"
31
31
32
+ #include < QCursor>
32
33
#include < QPushButton>
34
+ #include < QInputDialog>
33
35
#include < QFileDialog>
36
+ #include < QMenu>
34
37
#include < QMessageBox>
35
38
#include < QSettings>
36
39
#include < QTextStream>
40
+ #include < QTreeView>
37
41
38
42
QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget ( QgsRasterLayer* layer, const QgsRectangle &extent )
39
43
: QgsRasterRendererWidget( layer, extent )
@@ -44,7 +48,15 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
44
48
45
49
setupUi ( this );
46
50
51
+ contextMenu = new QMenu ( tr ( " Options" ), this );
52
+ contextMenu->addAction ( tr ( " Change color" ), this , SLOT ( changeColor () ) );
53
+ contextMenu->addAction ( tr ( " Change transparency" ), this , SLOT ( changeTransparency () ) );
54
+
47
55
mColormapTreeWidget ->setColumnWidth ( ColorColumn, 50 );
56
+ mColormapTreeWidget ->setContextMenuPolicy ( Qt::CustomContextMenu );
57
+ mColormapTreeWidget ->setSelectionMode ( QAbstractItemView::ExtendedSelection );
58
+ connect ( mColormapTreeWidget , &QTreeView::customContextMenuRequested, [=]( const QPoint& ) { contextMenu->exec ( QCursor::pos () ); }
59
+ );
48
60
49
61
QString defaultPalette = settings.value ( QStringLiteral ( " /Raster/defaultPalette" ), " " ).toString ();
50
62
btnColorRamp->setColorRampFromName ( defaultPalette );
@@ -303,10 +315,16 @@ void QgsSingleBandPseudoColorRendererWidget::on_mAddEntryButton_clicked()
303
315
304
316
void QgsSingleBandPseudoColorRendererWidget::on_mDeleteEntryButton_clicked ()
305
317
{
306
- QTreeWidgetItem* currentItem = mColormapTreeWidget ->currentItem ();
307
- if ( currentItem )
318
+ QList<QTreeWidgetItem *> itemList;
319
+ itemList = mColormapTreeWidget ->selectedItems ();
320
+ if ( itemList.isEmpty () )
321
+ {
322
+ return ;
323
+ }
324
+
325
+ Q_FOREACH ( QTreeWidgetItem *item, itemList )
308
326
{
309
- delete currentItem ;
327
+ delete item ;
310
328
}
311
329
emit widgetChanged ();
312
330
}
@@ -775,6 +793,7 @@ void QgsSingleBandPseudoColorRendererWidget::mColormapTreeWidget_itemEdited( QTr
775
793
{
776
794
// call autoLabel to fill when empty or gray out when same as autoLabel
777
795
autoLabel ();
796
+ emit widgetChanged ();
778
797
}
779
798
}
780
799
@@ -928,3 +947,51 @@ void QgsSingleBandPseudoColorRendererWidget::resetClassifyButton()
928
947
mClassifyButton ->setEnabled ( false );
929
948
}
930
949
}
950
+
951
+ void QgsSingleBandPseudoColorRendererWidget::changeColor ()
952
+ {
953
+ QList<QTreeWidgetItem *> itemList;
954
+ itemList = mColormapTreeWidget ->selectedItems ();
955
+ if ( itemList.isEmpty () )
956
+ {
957
+ return ;
958
+ }
959
+ QTreeWidgetItem* firstItem = itemList.first ();
960
+
961
+ QColor newColor = QgsColorDialog::getColor ( firstItem->background ( ColorColumn ).color (), this , QStringLiteral ( " Change color" ), true );
962
+ if ( newColor.isValid () )
963
+ {
964
+ Q_FOREACH ( QTreeWidgetItem *item, itemList )
965
+ {
966
+ item->setFlags ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
967
+ item->setBackground ( ColorColumn, QBrush ( newColor ) );
968
+ }
969
+ emit widgetChanged ();
970
+ }
971
+ }
972
+
973
+ void QgsSingleBandPseudoColorRendererWidget::changeTransparency ()
974
+ {
975
+ QList<QTreeWidgetItem *> itemList;
976
+ itemList = mColormapTreeWidget ->selectedItems ();
977
+ if ( itemList.isEmpty () )
978
+ {
979
+ return ;
980
+ }
981
+ QTreeWidgetItem* firstItem = itemList.first ();
982
+
983
+ bool ok;
984
+ double oldTransparency = firstItem->background ( ColorColumn ).color ().alpha () / 255 * 100 ;
985
+ double transparency = QInputDialog::getDouble ( this , tr ( " Transparency" ), tr ( " Change symbol transparency [%]" ), oldTransparency, 0.0 , 100.0 , 0 , &ok );
986
+ if ( ok )
987
+ {
988
+ int newTransparency = transparency / 100 * 255 ;
989
+ Q_FOREACH ( QTreeWidgetItem *item, itemList )
990
+ {
991
+ QColor newColor = item->background ( ColorColumn ).color ();
992
+ newColor.setAlpha ( newTransparency );
993
+ item->setBackground ( ColorColumn, QBrush ( newColor ) );
994
+ }
995
+ emit widgetChanged ();
996
+ }
997
+ }
0 commit comments