Skip to content

Commit a5b77b9

Browse files
committed
Merge pull request #1325 from 3nids/qtdesignerplugin
QGIS custom widgets plugins for Qt Designer
2 parents 2ff79d3 + f9d7aef commit a5b77b9

32 files changed

Lines changed: 1374 additions & 499 deletions

‎CMakeLists.txt‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ IF(WITH_MAPSERVER)
4646
SET (MAPSERVER_SKIP_ECW FALSE CACHE BOOL "Determines whether QGIS mapserver should disable ECW (ECW in server apps requires a special license)")
4747
ENDIF(WITH_MAPSERVER)
4848

49+
# Custom widgets
50+
SET (WITH_CUSTOM_WIDGETS TRUE CACHE BOOL "Determines whether QGIS custom widgets for Qt Designer should be built")
51+
4952
# build our version of astyle
5053
SET (WITH_ASTYLE FALSE CACHE BOOL "If you plan to contribute you should reindent with scripts/prepare-commit.sh (using 'our' astyle)")
5154

@@ -226,10 +229,13 @@ SET(QT_USE_QTNETWORK 1)
226229
SET(QT_USE_QTSVG 1)
227230
SET(QT_USE_QTSQL 1)
228231
SET(QT_USE_QTWEBKIT 1)
232+
IF (WITH_CUSTOM_WIDGETS)
233+
SET(QT_USE_QTDESIGNER 1)
234+
ENDIF (WITH_CUSTOM_WIDGETS)
229235

230-
IF (NOT QT_QTXML_FOUND OR NOT QT_QTNETWORK_FOUND OR NOT QT_QTSVG_FOUND OR NOT QT_QTSQL_FOUND OR NOT QT_QTWEBKIT_FOUND)
236+
IF (NOT QT_QTXML_FOUND OR NOT QT_QTNETWORK_FOUND OR NOT QT_QTSVG_FOUND OR NOT QT_QTSQL_FOUND OR NOT QT_QTWEBKIT_FOUND OR (WITH_CUSTOM_WIDGETS AND NOT QT_QTDESIGNER_FOUND))
231237
MESSAGE(SEND_ERROR "Some Qt4 modules haven't been found!")
232-
ENDIF (NOT QT_QTXML_FOUND OR NOT QT_QTNETWORK_FOUND OR NOT QT_QTSVG_FOUND OR NOT QT_QTSQL_FOUND OR NOT QT_QTWEBKIT_FOUND)
238+
ENDIF (NOT QT_QTXML_FOUND OR NOT QT_QTNETWORK_FOUND OR NOT QT_QTSVG_FOUND OR NOT QT_QTSQL_FOUND OR NOT QT_QTWEBKIT_FOUND OR (WITH_CUSTOM_WIDGETS AND NOT QT_QTDESIGNER_FOUND))
233239

234240
IF (WITH_QTMOBILITY)
235241
FIND_PACKAGE(QtMobility 1.1.0)
@@ -279,7 +285,6 @@ IF (ENABLE_TESTS)
279285
add_custom_target(check-no-x COMMAND xvfb-run --server-args="-screen 10,1024x768x24" ctest --output-on-failure)
280286
ENDIF (ENABLE_TESTS)
281287

282-
283288
INCLUDE( ${QT_USE_FILE} )
284289

285290
# Disable automatic conversion from QString to ASCII 8-bit strings (char *)
@@ -530,6 +535,7 @@ SET (QGIS_LIBEXEC_DIR ${QGIS_LIBEXEC_SUBDIR})
530535
SET (QGIS_DATA_DIR ${QGIS_DATA_SUBDIR})
531536
SET (QGIS_PLUGIN_DIR ${QGIS_PLUGIN_SUBDIR})
532537
SET (QGIS_INCLUDE_DIR ${QGIS_INCLUDE_SUBDIR})
538+
SET (QGIS_CUSTOMWIDGETS_DIR ${QT_PLUGINS_DIR}/designer)
533539

534540
# set the default locations where the targets (executables, libraries) will land when compiled
535541
# this is to allow running qgis from the source tree without having to actually do a "make install"
@@ -549,6 +555,7 @@ IF (UNIX AND NOT APPLE)
549555
SET (QGIS_MANUAL_DIR ${CMAKE_INSTALL_PREFIX}/${QGIS_MANUAL_SUBDIR})
550556
ENDIF (UNIX AND NOT APPLE)
551557

558+
552559
#############################################################
553560
# Python bindings
554561

@@ -574,6 +581,10 @@ IF (WITH_BINDINGS)
574581
SET(PYTHON_SITE_PACKAGES_DIR ${QGIS_DATA_DIR}/python)
575582
ENDIF (NOT BINDINGS_GLOBAL_INSTALL)
576583

584+
IF (WITH_CUSTOM_WIDGETS)
585+
SET(PYUIC_WIDGET_PLUGIN_DIRECTORY ${PYQT4_MOD_DIR}/uic/widget-plugins/)
586+
ENDIF (WITH_CUSTOM_WIDGETS)
587+
577588
ENDIF (WITH_BINDINGS)
578589

579590
# Set QSCINTILLA_VERSION_STR to that of module, if no headers found

‎python/CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ SET(PY_FILES
177177
__init__.py
178178
utils.py
179179
)
180+
IF(WITH_CUSTOM_WIDGETS)
181+
INSTALL(FILES custom_widgets/qgis_customwidgets.py DESTINATION "${PYUIC_WIDGET_PLUGIN_DIRECTORY}")
182+
ENDIF(WITH_CUSTOM_WIDGETS)
180183

181184
ADD_CUSTOM_TARGET(pyutils ALL)
182185
INSTALL(FILES ${PY_FILES} DESTINATION "${QGIS_PYTHON_DIR}")

‎python/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
__revision__ = '$Format:%H$'
2525

2626
import sip
27+
2728
try:
2829
apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]
2930
for api in apis:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
customwidgets.py
6+
---------------------
7+
Date : May 2014
8+
Copyright : (C) 2014 by Denis Rouzaud
9+
Email : denis.rouzaud@gmail.com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
"""
21+
This file is used by pyuic to redirect includes
22+
in custom widgets to the correct QGIS python packages.
23+
It is copied on installation in /pythonX/dist-packages/PyQt4/uic/widget-plugins/
24+
"""
25+
26+
#pluginType = CW_FILTER
27+
#def getFilter():
28+
# import qgis.gui
29+
#
30+
# QGIS_widgets = {}
31+
# for pyClass in dir(qgis.gui):
32+
# QGIS_widgets[pyClass] = 'qgis.gui'
33+
#
34+
# def _QGISfilter(widgetname, baseclassname, module):
35+
# print widgetname, baseclassname, module
36+
# if widgetname in QGIS_widgets:
37+
# return (MATCH, (widgetname, baseclassname, QGIS_widgets[widgetname]))
38+
# else:
39+
# return (NO_MATCH, None)
40+
#
41+
# return _QGISfilter
42+
43+
44+
45+
pluginType = MODULE
46+
def moduleInformation():
47+
import qgis.gui
48+
return "qgis.gui", dir(qgis.gui)
49+

‎python/gui/qgsmaplayercombobox.sip‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,20 @@ class QgsMapLayerComboBox : QComboBox
1616
*/
1717
explicit QgsMapLayerComboBox( QWidget *parent /TransferThis/ = 0 );
1818

19-
/**
20-
* @brief setFilters allows fitering according to layer type and/or geometry type.
21-
*/
19+
//! setFilters allows fitering according to layer type and/or geometry type.
2220
void setFilters( QgsMapLayerProxyModel::Filters filters );
2321

24-
/**
25-
* @brief currentLayer returns the current layer selected in the combo box
26-
*/
22+
//! currently used filter on list layers
23+
QgsMapLayerProxyModel::Filters filters();
24+
25+
///! currentLayer returns the current layer selected in the combo box
2726
QgsMapLayer* currentLayer();
2827

2928
public slots:
30-
/**
31-
* @brief setLayer set the current layer selected in the combo
32-
*/
29+
//! setLayer set the current layer selected in the combo
3330
void setLayer( QgsMapLayer* layer );
3431

3532
signals:
36-
/**
37-
* @brief layerChanged this signal is emitted whenever the currently selected layer changes
38-
*/
33+
//! layerChanged this signal is emitted whenever the currently selected layer changes
3934
void layerChanged( QgsMapLayer* layer );
4035
};

‎src/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ IF (WITH_MAPSERVER)
2020
ADD_SUBDIRECTORY(mapserver) # TODO: enable again once compilation is fixed
2121
ENDIF (WITH_MAPSERVER)
2222

23+
IF (WITH_CUSTOM_WIDGETS)
24+
ADD_SUBDIRECTORY(customwidgets)
25+
ENDIF (WITH_CUSTOM_WIDGETS)
26+
2327
IF (WITH_ASTYLE)
2428
ADD_SUBDIRECTORY(astyle)
2529
ENDIF(WITH_ASTYLE)

‎src/app/qgsrasterlayerproperties.cpp‎

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@
6767
#include <QVector>
6868

6969
QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanvas* theCanvas, QWidget *parent, Qt::WindowFlags fl )
70-
: QgsOptionsDialogBase( "RasterLayerProperties", parent, fl ),
70+
: QgsOptionsDialogBase( "RasterLayerProperties", parent, fl )
7171
// Constant that signals property not used.
72-
TRSTRING_NOT_SET( tr( "Not Set" ) ),
73-
mRasterLayer( qobject_cast<QgsRasterLayer *>( lyr ) ), mRendererWidget( 0 )
72+
, TRSTRING_NOT_SET( tr( "Not Set" ) )
73+
, mRasterLayer( qobject_cast<QgsRasterLayer *>( lyr ) ), mRendererWidget( 0 )
74+
, mMapCanvas( theCanvas )
7475
{
7576
mGrayMinimumMaximumEstimated = true;
7677
mRGBMinimumMaximumEstimated = true;
@@ -81,9 +82,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
8182
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
8283
initOptionsBase( false );
8384

84-
mMaximumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomIn.svg" ) );
85-
mMinimumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomOut.svg" ) );
86-
8785
connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
8886
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
8987

@@ -116,17 +114,9 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
116114
connect( lbxPyramidResolutions, SIGNAL( itemSelectionChanged() ), this, SLOT( toggleBuildPyramidsButton() ) );
117115

118116
// set up the scale based layer visibility stuff....
117+
mScaleRangeWidget->setMapCanvas( mMapCanvas );
119118
chkUseScaleDependentRendering->setChecked( lyr->hasScaleBasedVisibility() );
120-
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
121-
if ( projectScales )
122-
{
123-
QStringList scalesList = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
124-
cbMinimumScale->updateScales( scalesList );
125-
cbMaximumScale->updateScales( scalesList );
126-
}
127-
cbMinimumScale->setScale( 1.0 / lyr->minimumScale() );
128-
cbMaximumScale->setScale( 1.0 / lyr->maximumScale() );
129-
119+
mScaleRangeWidget->setScaleRange( 1.0 / lyr->maximumScale(), 1.0 / lyr->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
130120

131121
leNoDataValue->setValidator( new QDoubleValidator( -std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), 1000, this ) );
132122

@@ -141,7 +131,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
141131
pbnImportTransparentPixelValues->setIcon( QgsApplication::getThemeIcon( "/mActionFileOpen.svg" ) );
142132
pbnExportTransparentPixelValues->setIcon( QgsApplication::getThemeIcon( "/mActionFileSave.svg" ) );
143133

144-
mMapCanvas = theCanvas;
145134
mPixelSelectorTool = 0;
146135
if ( mMapCanvas )
147136
{
@@ -856,8 +845,9 @@ void QgsRasterLayerProperties::apply()
856845

857846
// set up the scale based layer visibility stuff....
858847
mRasterLayer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
859-
mRasterLayer->setMinimumScale( 1.0 / cbMinimumScale->scale() );
860-
mRasterLayer->setMaximumScale( 1.0 / cbMaximumScale->scale() );
848+
// caution: layer uses scale denoms, widget uses true scales
849+
mRasterLayer->setMaximumScale( 1.0 / mScaleRangeWidget->minimumScale() );
850+
mRasterLayer->setMinimumScale( 1.0 / mScaleRangeWidget->maximumScale() );
861851

862852
//update the legend pixmap
863853
// pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
@@ -1722,16 +1712,6 @@ void QgsRasterLayerProperties::toggleBuildPyramidsButton()
17221712
}
17231713
}
17241714

1725-
void QgsRasterLayerProperties::on_mMinimumScaleSetCurrentPushButton_clicked()
1726-
{
1727-
cbMinimumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapSettings().scale() );
1728-
}
1729-
1730-
void QgsRasterLayerProperties::on_mMaximumScaleSetCurrentPushButton_clicked()
1731-
{
1732-
cbMaximumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapSettings().scale() );
1733-
}
1734-
17351715
void QgsRasterLayerProperties::on_mResetColorRenderingBtn_clicked()
17361716
{
17371717
mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );

‎src/app/qgsrasterlayerproperties.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
9898
void on_pbnSaveStyleAs_clicked();
9999
/** Help button */
100100
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
101-
void on_mMinimumScaleSetCurrentPushButton_clicked();
102-
void on_mMaximumScaleSetCurrentPushButton_clicked();
103101

104102
/** Slot to reset all color rendering options to default
105103
* @note added in 1.9

‎src/app/qgsvectorlayerproperties.cpp‎

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
8181
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
8282
initOptionsBase( false );
8383

84-
mMaximumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomIn.svg" ) );
85-
mMinimumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomOut.svg" ) );
84+
8685

8786
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
8887
connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
@@ -360,7 +359,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
360359
"layer is shown here. To enter or modify the query, click on the Query Builder button" ) );
361360

362361
//see if we are dealing with a pg layer here
363-
grpSubset->setEnabled( true );
362+
mSubsetGroupBox->setEnabled( true );
364363
txtSubsetSQL->setText( layer->subsetString() );
365364
// if the user is allowed to type an adhoc query, the app will crash if the query
366365
// is bad. For this reason, the sql box is disabled and the query must be built
@@ -386,16 +385,9 @@ void QgsVectorLayerProperties::syncToLayer( void )
386385
setDisplayField( layer-> displayField() );
387386

388387
// set up the scale based layer visibility stuff....
389-
chkUseScaleDependentRendering->setChecked( layer->hasScaleBasedVisibility() );
390-
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
391-
if ( projectScales )
392-
{
393-
QStringList scalesList = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
394-
cbMinimumScale->updateScales( scalesList );
395-
cbMaximumScale->updateScales( scalesList );
396-
}
397-
cbMinimumScale->setScale( 1.0 / layer->minimumScale() );
398-
cbMaximumScale->setScale( 1.0 / layer->maximumScale() );
388+
mScaleRangeWidget->setScaleRange( 1.0 / layer->maximumScale(), 1.0 / layer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
389+
mScaleVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
390+
mScaleRangeWidget->setMapCanvas( QgisApp::instance()->mapCanvas() );
399391

400392
// get simplify drawing configuration
401393
const QgsVectorSimplifyMethod& simplifyMethod = layer->simplifyMethod();
@@ -491,7 +483,7 @@ void QgsVectorLayerProperties::apply()
491483
//
492484
// Set up sql subset query if applicable
493485
//
494-
grpSubset->setEnabled( true );
486+
mSubsetGroupBox->setEnabled( true );
495487

496488
if ( txtSubsetSQL->toPlainText() != layer->subsetString() )
497489
{
@@ -501,9 +493,10 @@ void QgsVectorLayerProperties::apply()
501493
}
502494

503495
// set up the scale based layer visibility stuff....
504-
layer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
505-
layer->setMinimumScale( 1.0 / cbMinimumScale->scale() );
506-
layer->setMaximumScale( 1.0 / cbMaximumScale->scale() );
496+
layer->toggleScaleBasedVisibility( mScaleVisibilityGroupBox->isChecked() );
497+
// caution: layer uses scale denoms, widget uses true scales
498+
layer->setMaximumScale( 1.0 / mScaleRangeWidget->minimumScale() );
499+
layer->setMinimumScale( 1.0 / mScaleRangeWidget->maximumScale() );
507500

508501
// provider-specific options
509502
if ( layer->dataProvider() )
@@ -1110,16 +1103,6 @@ void QgsVectorLayerProperties::enableLabelOptions( bool theFlag )
11101103
labelOptionsFrame->setEnabled( theFlag );
11111104
}
11121105

1113-
void QgsVectorLayerProperties::on_mMinimumScaleSetCurrentPushButton_clicked()
1114-
{
1115-
cbMinimumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapSettings().scale() );
1116-
}
1117-
1118-
void QgsVectorLayerProperties::on_mMaximumScaleSetCurrentPushButton_clicked()
1119-
{
1120-
cbMaximumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapSettings().scale() );
1121-
}
1122-
11231106
void QgsVectorLayerProperties::on_mSimplifyDrawingGroupBox_toggled( bool checked )
11241107
{
11251108
if ( !( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SimplifyGeometries ) )

‎src/app/qgsvectorlayerproperties.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define QGSVECTORLAYERPROPERTIES
2121

2222
#include "qgsoptionsdialogbase.h"
23+
#include "qgsscalerangewidget.h"
2324
#include "ui_qgsvectorlayerpropertiesbase.h"
2425
#include "qgisgui.h"
2526
#include "qgsaddattrdialog.h"
@@ -116,9 +117,6 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
116117
void on_mButtonAddJoin_clicked();
117118
void on_mButtonRemoveJoin_clicked();
118119

119-
void on_mMinimumScaleSetCurrentPushButton_clicked();
120-
void on_mMaximumScaleSetCurrentPushButton_clicked();
121-
122120
void on_mSimplifyDrawingGroupBox_toggled( bool checked );
123121

124122
signals:

0 commit comments

Comments
 (0)