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
This commit is contained in:
timlinux 2004-06-09 10:46:12 +00:00
parent 4d87e98215
commit e9fa3ea782
4 changed files with 51 additions and 20 deletions

View File

@ -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()

View File

@ -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 */

View File

@ -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("<center><b>Raster Layer</b></center>") );
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("<center><b>Transparency</b></center>") );
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();
}

View File

@ -168,6 +168,7 @@ The [type] part of the variable should be the type class of the variable written
#include <qvaluevector.h>
#include <qvaluelist.h>
#include <qslider.h>
#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;