Skip to content

Commit

Permalink
Wired in variable transparency to vector props dialog.
Browse files Browse the repository at this point in the history
Only implemented for polygons currently (I dont even know if its 
possible to do for lines and points)

Refactored transparency stuff in raster up into maplayer abc



git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4680 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jan 14, 2006
1 parent 31494eb commit 44f4e79
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 71 deletions.
1 change: 1 addition & 0 deletions src/gui/qgsmaplayer.cpp
Expand Up @@ -50,6 +50,7 @@
QgsMapLayer::QgsMapLayer(int type,
QString lyrname,
QString source) :
transparencyLevelInt(255), // 0 is completely transparent
valid(true), // assume the layer is valid (data source exists and
// can be used) until we learn otherwise
dataSource(source),
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmaplayer.h
Expand Up @@ -287,7 +287,11 @@ class QgsMapLayer : public QObject

virtual std::vector < QgsField > const &fields() const;

/** \brief accessor for transparency level. */
virtual unsigned int getTransparency()=0;
public slots:
/** \brief Mutator for transparency level. Should be between 0 and 255 */
virtual void setTransparency(int)=0; //
//! event handler for when a coordinate transofrm fails due to bad vertex error
virtual void invalidTransformInput();

Expand Down Expand Up @@ -372,6 +376,8 @@ public slots:

protected:

/** \brief Transparency level for this layer should be 0-255 (255 being opaque) */
unsigned int transparencyLevelInt;

/** called by readXML(), used by children to read state specific to them from
project files.
Expand Down
11 changes: 10 additions & 1 deletion src/gui/qgsvectorlayer.cpp
Expand Up @@ -745,7 +745,7 @@ std::cerr << i << ": " << ring->first[i]
//I have hardcoded it to opaque out for now
//until I make it user configurable
//and hopefully work out how to improve performance
myColor.setAlpha(255);
myColor.setAlpha(transparencyLevelInt);
myTransparentBrush.setColor(myColor);
p->setBrush(myTransparentBrush);
// draw the polygon fill
Expand Down Expand Up @@ -3609,3 +3609,12 @@ inline void QgsVectorLayer::transformPoints(
// position on map canvas
mtp->transformInPlace(x, y);
}
unsigned int QgsVectorLayer::getTransparency()
{
return transparencyLevelInt;
}
//should be between 0 and 255
void QgsVectorLayer::setTransparency(int theInt)
{
transparencyLevelInt=theInt;
} // QgsRasterLayer::setTransparency(int theInt)
6 changes: 6 additions & 0 deletions src/gui/qgsvectorlayer.h
Expand Up @@ -67,6 +67,9 @@ class QgsVectorLayer : public QgsMapLayer
//! Destructor
virtual ~QgsVectorLayer();

/** \brief accessor for transparency level. */
unsigned int getTransparency();

/**
* Returns the permanent storage type for this layer as a friendly name.
*/
Expand Down Expand Up @@ -164,6 +167,9 @@ const QString displayField() const { return fieldIndex; }

public slots:

/** \brief Mutator for transparency level. Should be between 0 and 255 */
void setTransparency(int); //

void inOverview( bool );

/**Sets the 'tabledisplay' to 0 again*/
Expand Down
12 changes: 12 additions & 0 deletions src/gui/qgsvectorlayerproperties.cpp
Expand Up @@ -73,13 +73,20 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(QgsVectorLayer * lyr,
{
leSpatialRefSys->setText(layer->coordinateTransform()->sourceSRS().proj4String());
}
connect(sliderTransparency, SIGNAL(valueChanged(int)), this, SLOT(sliderTransparency_valueChanged(int)));

} // QgsVectorLayerProperties ctor

QgsVectorLayerProperties::~QgsVectorLayerProperties()
{

}
void QgsVectorLayerProperties::sliderTransparency_valueChanged(int theValue)
{
//set the transparency percentage label to a suitable value
int myInt = static_cast < int >((theValue / 255.0) * 100); //255.0 to prevent integer division
lblTransparencyPercent->setText(tr("Transparency: ") + QString::number(myInt) + "%");
}//sliderTransparency_valueChanged

void QgsVectorLayerProperties::alterLayerDialog(const QString & dialogString)
{
Expand Down Expand Up @@ -230,6 +237,10 @@ void QgsVectorLayerProperties::reset( void )
actionDialog->init();
labelDialog->init();
labelCheckBox->setChecked(layer->labelOn());
//set the transparency slider
sliderTransparency->setValue(255 - layer->getTransparency());
//update the transparency percentage label
sliderTransparency_valueChanged(255 - layer->getTransparency());

} // reset()

Expand Down Expand Up @@ -305,6 +316,7 @@ void QgsVectorLayerProperties::on_pbnApply_clicked()
{
udialog->apply();
}
layer->setTransparency(static_cast < unsigned int >(255 - sliderTransparency->value()));

layer->triggerRepaint();

Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsvectorlayerproperties.h
Expand Up @@ -56,7 +56,8 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
void reset();
/** Get metadata about the layer in nice formatted html */
QString getMetadata();

/** Set transparency based on slider position */
void sliderTransparency_valueChanged(int theValue);

//
//methods reimplemented from qt designer base class
Expand Down
2 changes: 0 additions & 2 deletions src/raster/qgsrasterlayer.cpp
Expand Up @@ -455,7 +455,6 @@ QgsRasterLayer::QgsRasterLayer(QString const & path, QString const & baseName)
showDebugOverlayFlag(false),
invertHistogramFlag(false),
stdDevsToPlotDouble(0),
transparencyLevelInt(255), // 0 is completely transparent
mTransparencySlider(0x0),
mLayerProperties(0x0),
mIdentifyResults(0),
Expand Down Expand Up @@ -4964,7 +4963,6 @@ QgsRasterLayer::QgsRasterLayer(int dummy,
showDebugOverlayFlag(false),
invertHistogramFlag(false),
stdDevsToPlotDouble(0),
transparencyLevelInt(255), // 0 is completely transparent
mTransparencySlider(0x0),
mLayerProperties(0x0),
mIdentifyResults(0),
Expand Down
6 changes: 2 additions & 4 deletions src/raster/qgsrasterlayer.h
Expand Up @@ -383,8 +383,6 @@ class QgsRasterLayer : public QgsMapLayer
bool hasBand(QString const & theBandName);
/** \brief accessor for transparency level. */
unsigned int getTransparency();
/** \brief Mutator for transparency level. Should be between 0 and 255 */
void setTransparency(int); //
/** \brief Call any inline image manipulation filters */
void filterLayer(QImage * theQImage);
/** \brief Accessor for red band name (allows alternate mappings e.g. map blue as red colour). */
Expand Down Expand Up @@ -754,6 +752,8 @@ class QgsRasterLayer : public QgsMapLayer
bool isSymbologyCompatible(const QgsMapLayer& other) const {return false;} //todo

public slots:
/** \brief Mutator for transparency level. Should be between 0 and 255 */
void setTransparency(int); //
/**
* Convert this raster to another format
*/
Expand Down Expand Up @@ -956,8 +956,6 @@ public slots:
* The typedef for this is defined above before class declaration
*/
RasterStatsVector rasterStatsVector;
/** \brief Transparency level for this layer should be 0-255. */
unsigned int transparencyLevelInt;
/** \brief The band to be associated with the color red - usually 1. */
QString redBandNameQString;
/** \brief The band to be associated with the color green - usually 2. */
Expand Down
146 changes: 83 additions & 63 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -26,58 +26,11 @@
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>8</number>
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>270</width>
<height>29</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2" >
<widget class="QPushButton" name="pbnApply" >
<property name="text" >
<string>Apply</string>
</property>
</widget>
</item>
<item row="1" column="3" >
<widget class="QPushButton" name="pbnOK" >
<property name="text" >
<string>OK</string>
</property>
</widget>
</item>
<item row="1" column="4" >
<widget class="QPushButton" name="pbnCancel" >
<property name="text" >
<string>Cancel</string>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QPushButton" name="btnHelp" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>Help</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="5" >
<widget class="QTabWidget" name="tabWidget2" >
<property name="tabShape" >
Expand All @@ -89,12 +42,32 @@
</attribute>
<layout class="QGridLayout" >
<property name="margin" >
<number>8</number>
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="0" colspan="2" >
<item row="1" column="1" >
<widget class="QSlider" name="sliderTransparency" >
<property name="maximum" >
<number>255</number>
</property>
<property name="value" >
<number>0</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="lblTransparencyPercent" >
<property name="text" >
<string>Transparency:</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2" >
<widget class="Q3WidgetStack" name="widgetStackRenderers" >
<property name="sizePolicy" >
<sizepolicy>
Expand Down Expand Up @@ -127,33 +100,33 @@
<widget class="QWidget" name="qt_dead_widget_WStackPage" />
</widget>
</item>
<item row="0" column="1" >
<widget class="QComboBox" name="legendtypecombobox" >
<property name="minimumSize" >
<size>
<width>270</width>
<height>24</height>
</size>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="legendtypelabel" >
<property name="maximumSize" >
<size>
<width>32767</width>
<height>22</height>
</size>
</property>
<property name="text" >
<string>Legend type:</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="legendtypelabel" >
<item row="0" column="1" >
<widget class="QComboBox" name="legendtypecombobox" >
<property name="minimumSize" >
<size>
<width>270</width>
<height>24</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>32767</width>
<height>22</height>
</size>
</property>
<property name="text" >
<string>Legend type:</string>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -505,6 +478,53 @@
</widget>
</widget>
</item>
<item row="1" column="0" >
<widget class="QPushButton" name="btnHelp" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>Help</string>
</property>
</widget>
</item>
<item row="1" column="4" >
<widget class="QPushButton" name="pbnCancel" >
<property name="text" >
<string>Cancel</string>
</property>
</widget>
</item>
<item row="1" column="3" >
<widget class="QPushButton" name="pbnOK" >
<property name="text" >
<string>OK</string>
</property>
</widget>
</item>
<item row="1" column="2" >
<widget class="QPushButton" name="pbnApply" >
<property name="text" >
<string>Apply</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>270</width>
<height>29</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
Expand Down

0 comments on commit 44f4e79

Please sign in to comment.