From e9fa3ea7820d6b18fd5073ce5fd12dfc4188d290 Mon Sep 17 00:00:00 2001 From: timlinux Date: Wed, 9 Jun 2004 10:46:12 +0000 Subject: [PATCH] fixed bug where pop transp. slider was not syncing when transp changed in raster props dialog. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@1542 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/qgsmaplayer.cpp | 12 ++++++++-- src/qgsmaplayer.h | 5 +++++ src/qgsrasterlayer.cpp | 51 +++++++++++++++++++++++++++--------------- src/qgsrasterlayer.h | 3 +++ 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/qgsmaplayer.cpp b/src/qgsmaplayer.cpp index abd17c9345f..7c05fa70add 100644 --- a/src/qgsmaplayer.cpp +++ b/src/qgsmaplayer.cpp @@ -30,6 +30,7 @@ m_legendItem(0) // until we learn otherwise valid = true; m_visible = true; + mShowInOverview = false; // Set the display name = internal name layerName = internalName; @@ -127,12 +128,19 @@ void QgsMapLayer::showInOverview(bool theFlag) { if (theFlag) { - //do me +#ifdef QGISDEBUG + std::cout << "Map layer " << ID << " requested to be added to the overview " << std::endl; +#endif + mShowInOverview=true; } else { - //do me +#ifdef QGISDEBUG + std::cout << "Map layer " << ID << " requested to be removed from the overview " << std::endl; +#endif + mShowInOverview=false; } + emit showInOverview(ID,mShowInOverview); } const int &QgsMapLayer::featureType() diff --git a/src/qgsmaplayer.h b/src/qgsmaplayer.h index 0d25339216b..f87a0212681 100644 --- a/src/qgsmaplayer.h +++ b/src/qgsmaplayer.h @@ -224,6 +224,8 @@ signals: /** This signal should be connected with the slot QgsMapCanvas::refresh() */ virtual void repaintRequested(); + /** This is used to notify the application whether this layer should be shown in overview or not. */ + void showInOverview(QString theLayerId, bool); protected: @@ -254,6 +256,9 @@ protected: //! context menu QPopupMenu *popMenu; + /** Whether this layer is to be shown in the overview map or not */ + bool mShowInOverview; + private: // Private attributes /** Unique ID of this layer - used to refer to this layer in QGIS code */ diff --git a/src/qgsrasterlayer.cpp b/src/qgsrasterlayer.cpp index 00be5d2d0d6..c2dc9bbbc2f 100644 --- a/src/qgsrasterlayer.cpp +++ b/src/qgsrasterlayer.cpp @@ -218,6 +218,13 @@ QgsRasterLayer::QgsRasterLayer(QString path, QString baseName):QgsMapLayer(RASTE stdDevsToPlotDouble = 0; // sensible default transparencyLevelInt = 255; //sensible default 0 is transparent showDebugOverlayFlag = false; //sensible default + // Transparency slider for popup meni + // QSlider ( int minValue, int maxValue, int pageStep, int value, Orientation orientation, QWidget * parent, const char * name = 0 ) + mTransparencySlider = new QSlider(0,255,5,255-transparencyLevelInt,QSlider::Horizontal,popMenu); + mTransparencySlider->setTickmarks(QSlider::Both); + mTransparencySlider->setTickInterval(25); + mTransparencySlider->setTracking(false); //stop slider emmitting a signal until mouse released + connect(mTransparencySlider, SIGNAL(valueChanged(int)), this, SLOT(popupTransparencySliderMoved(int))); // emit a signal asking for a repaint emit repaintRequested(); } @@ -336,6 +343,7 @@ void QgsRasterLayer::setTransparency(int theInt) { transparencyLevelInt = theInt; } + mTransparencySlider->setValue(transparencyLevelInt); } unsigned int QgsRasterLayer::getTransparency() { @@ -2181,40 +2189,47 @@ void QgsRasterLayer::initContextMenu(QgisApp * theApp) popMenu = new QPopupMenu(); popMenu->setCheckable ( true ); //create a heading label for the menu: + //If a widget is not focus-enabled (see QWidget::isFocusEnabled()), the menu treats it as a separator; + //this means that the item is not selectable and will never get focus. In this way you can, for example, + //simply insert a QLabel if you need a popup menu with a title. QLabel *myPopupLabel = new QLabel( popMenu ); myPopupLabel->setFrameStyle( QFrame::Panel | QFrame::Raised ); myPopupLabel->setText( tr("
Raster Layer
") ); - popMenu->insertItem(myPopupLabel,0); + popMenu->insertItem(myPopupLabel); // popMenu->insertItem(tr("&Zoom to extent of selected layer"), theApp, SLOT(zoomToLayerExtent())); popMenu->insertItem(tr("&Properties"), theApp, SLOT(layerProperties())); //show in overview slot is implemented in maplayer superclass! - popMenu->insertItem(tr("Show In &Overview"), theApp, SLOT(showInOverview(bool)),1);//1 is a user assigned id for the menu item - popMenu->setItemChecked(1,true); + int myShowInOverviewItemId = popMenu->insertItem(tr("Show In &Overview"), this, SLOT(showInOverview(bool))); + //set the checkbox using the property in the maplayer superclass + popMenu->setItemChecked(myShowInOverviewItemId,mShowInOverview); + popMenu->insertItem(tr("&Remove"), theApp, SLOT(removeLayer())); popMenu->insertSeparator(); - //If a widget is not focus-enabled (see QWidget::isFocusEnabled()), the menu treats it as a separator; - //this means that the item is not selectable and will never get focus. In this way you can, for example, - //simply insert a QLabel if you need a popup menu with a title. QLabel * myTransparencyLabel = new QLabel( popMenu ); myTransparencyLabel->setFrameStyle( QFrame::Panel | QFrame::Raised ); myTransparencyLabel->setText( tr("
Transparency
") ); - popMenu->insertItem(myTransparencyLabel,2); - popMenu->setItemEnabled(2,false); - // QSlider ( int minValue, int maxValue, int pageStep, int value, Orientation orientation, QWidget * parent, const char * name = 0 ) - QSlider * myTransparencySlider = new QSlider(0,255,5,255-transparencyLevelInt,QSlider::Horizontal,popMenu); - myTransparencySlider->setTickmarks(QSlider::Both); - myTransparencySlider->setTickInterval(25); - myTransparencySlider->setTracking(false); //stop slider emmitting a signal until mouse released - connect(myTransparencySlider, SIGNAL(valueChanged(int)), this, SLOT(popupTransparencySliderMoved(int))); - popMenu->insertItem(myTransparencySlider,3); + popMenu->insertItem(myTransparencyLabel); + popMenu->insertItem(mTransparencySlider); - popMenu->insertSeparator(); - popMenu->insertItem(tr("&Remove"), theApp, SLOT(removeLayer())); } void QgsRasterLayer::popupTransparencySliderMoved(int theInt) { - setTransparency(255-theInt); +#ifdef QGISDEBUG + std::cout << "popupTransparencySliderMoved called with : " << theInt << std::endl; +#endif + if (theInt > 255) + { + transparencyLevelInt = 255; + } + else if (theInt < 0) + { + transparencyLevelInt = 0; + } + else + { + transparencyLevelInt = 255-theInt; + } triggerRepaint(); } diff --git a/src/qgsrasterlayer.h b/src/qgsrasterlayer.h index f711251a589..f66a30d32de 100644 --- a/src/qgsrasterlayer.h +++ b/src/qgsrasterlayer.h @@ -168,6 +168,7 @@ The [type] part of the variable should be the type class of the variable written #include #include +#include #include "qgspoint.h" #include "qgsmaplayer.h" #include "qgsrasterlayer.h" @@ -862,6 +863,8 @@ private: /** \brief This list holds a series of RasterPyramid structs * which store infomation for each potential pyramid level for this raster.*/ RasterPyramidList mPyramidList; + //Transparency slider for popup menu + QSlider * mTransparencySlider; //we need to do the tr() stuff outside of the main drawing loops becauses tr() is a //time consuming operation nd we dont want to do it in the loop! QString redTranslatedQString;