Skip to content
Permalink
Browse files
Merge pull request #1325 from 3nids/qtdesignerplugin
QGIS custom widgets plugins for Qt Designer
  • Loading branch information
3nids committed May 19, 2014
2 parents 2ff79d3 + f9d7aef commit a5b77b9b0e2dd8f5bc86ef832a3655c9a6fe4559
Showing with 1,374 additions and 499 deletions.
  1. +14 −3 CMakeLists.txt
  2. +3 −0 python/CMakeLists.txt
  3. +1 −0 python/__init__.py
  4. +49 −0 python/custom_widgets/qgis_customwidgets.py
  5. +7 −12 python/gui/qgsmaplayercombobox.sip
  6. +4 −0 src/CMakeLists.txt
  7. +9 −29 src/app/qgsrasterlayerproperties.cpp
  8. +0 −2 src/app/qgsrasterlayerproperties.h
  9. +10 −27 src/app/qgsvectorlayerproperties.cpp
  10. +1 −3 src/app/qgsvectorlayerproperties.h
  11. +77 −0 src/customwidgets/CMakeLists.txt
  12. +48 −0 src/customwidgets/qgiscustomwidgets.cpp
  13. +38 −0 src/customwidgets/qgiscustomwidgets.h
  14. +97 −0 src/customwidgets/qgscollapsiblegroupboxplugin.cpp
  15. +48 −0 src/customwidgets/qgscollapsiblegroupboxplugin.h
  16. +97 −0 src/customwidgets/qgsfieldcomboboxplugin.cpp
  17. +48 −0 src/customwidgets/qgsfieldcomboboxplugin.h
  18. +97 −0 src/customwidgets/qgsfieldexpressionwidgetplugin.cpp
  19. +48 −0 src/customwidgets/qgsfieldexpressionwidgetplugin.h
  20. +97 −0 src/customwidgets/qgsmaplayercomboboxplugin.cpp
  21. +49 −0 src/customwidgets/qgsmaplayercomboboxplugin.h
  22. +97 −0 src/customwidgets/qgsscalerangewidgetplugin.cpp
  23. +48 −0 src/customwidgets/qgsscalerangewidgetplugin.h
  24. +3 −0 src/gui/CMakeLists.txt
  25. +10 −13 src/gui/qgsmaplayercombobox.h
  26. +1 −0 src/gui/qgsmaplayerproxymodel.h
  27. +156 −0 src/gui/qgsscalerangewidget.cpp
  28. +85 −0 src/gui/qgsscalerangewidget.h
  29. +8 −6 src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
  30. +47 −162 src/ui/qgsrasterlayerpropertiesbase.ui
  31. +14 −57 src/ui/qgsrendererrulepropsdialogbase.ui
  32. +63 −185 src/ui/qgsvectorlayerpropertiesbase.ui
@@ -46,6 +46,9 @@ IF(WITH_MAPSERVER)
SET (MAPSERVER_SKIP_ECW FALSE CACHE BOOL "Determines whether QGIS mapserver should disable ECW (ECW in server apps requires a special license)")
ENDIF(WITH_MAPSERVER)

# Custom widgets
SET (WITH_CUSTOM_WIDGETS TRUE CACHE BOOL "Determines whether QGIS custom widgets for Qt Designer should be built")

# build our version of astyle
SET (WITH_ASTYLE FALSE CACHE BOOL "If you plan to contribute you should reindent with scripts/prepare-commit.sh (using 'our' astyle)")

@@ -226,10 +229,13 @@ SET(QT_USE_QTNETWORK 1)
SET(QT_USE_QTSVG 1)
SET(QT_USE_QTSQL 1)
SET(QT_USE_QTWEBKIT 1)
IF (WITH_CUSTOM_WIDGETS)
SET(QT_USE_QTDESIGNER 1)
ENDIF (WITH_CUSTOM_WIDGETS)

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)
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))
MESSAGE(SEND_ERROR "Some Qt4 modules haven't been found!")
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)
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))

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


INCLUDE( ${QT_USE_FILE} )

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

# set the default locations where the targets (executables, libraries) will land when compiled
# 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)
SET (QGIS_MANUAL_DIR ${CMAKE_INSTALL_PREFIX}/${QGIS_MANUAL_SUBDIR})
ENDIF (UNIX AND NOT APPLE)


#############################################################
# Python bindings

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

IF (WITH_CUSTOM_WIDGETS)
SET(PYUIC_WIDGET_PLUGIN_DIRECTORY ${PYQT4_MOD_DIR}/uic/widget-plugins/)
ENDIF (WITH_CUSTOM_WIDGETS)

ENDIF (WITH_BINDINGS)

# Set QSCINTILLA_VERSION_STR to that of module, if no headers found
@@ -177,6 +177,9 @@ SET(PY_FILES
__init__.py
utils.py
)
IF(WITH_CUSTOM_WIDGETS)
INSTALL(FILES custom_widgets/qgis_customwidgets.py DESTINATION "${PYUIC_WIDGET_PLUGIN_DIRECTORY}")
ENDIF(WITH_CUSTOM_WIDGETS)

ADD_CUSTOM_TARGET(pyutils ALL)
INSTALL(FILES ${PY_FILES} DESTINATION "${QGIS_PYTHON_DIR}")
@@ -24,6 +24,7 @@
__revision__ = '$Format:%H$'

import sip

try:
apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]
for api in apis:
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
customwidgets.py
---------------------
Date : May 2014
Copyright : (C) 2014 by Denis Rouzaud
Email : denis.rouzaud@gmail.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

"""
This file is used by pyuic to redirect includes
in custom widgets to the correct QGIS python packages.
It is copied on installation in /pythonX/dist-packages/PyQt4/uic/widget-plugins/
"""

#pluginType = CW_FILTER
#def getFilter():
# import qgis.gui
#
# QGIS_widgets = {}
# for pyClass in dir(qgis.gui):
# QGIS_widgets[pyClass] = 'qgis.gui'
#
# def _QGISfilter(widgetname, baseclassname, module):
# print widgetname, baseclassname, module
# if widgetname in QGIS_widgets:
# return (MATCH, (widgetname, baseclassname, QGIS_widgets[widgetname]))
# else:
# return (NO_MATCH, None)
#
# return _QGISfilter



pluginType = MODULE
def moduleInformation():
import qgis.gui
return "qgis.gui", dir(qgis.gui)

@@ -16,25 +16,20 @@ class QgsMapLayerComboBox : QComboBox
*/
explicit QgsMapLayerComboBox( QWidget *parent /TransferThis/ = 0 );

/**
* @brief setFilters allows fitering according to layer type and/or geometry type.
*/
//! setFilters allows fitering according to layer type and/or geometry type.
void setFilters( QgsMapLayerProxyModel::Filters filters );

/**
* @brief currentLayer returns the current layer selected in the combo box
*/
//! currently used filter on list layers
QgsMapLayerProxyModel::Filters filters();

///! currentLayer returns the current layer selected in the combo box
QgsMapLayer* currentLayer();

public slots:
/**
* @brief setLayer set the current layer selected in the combo
*/
//! setLayer set the current layer selected in the combo
void setLayer( QgsMapLayer* layer );

signals:
/**
* @brief layerChanged this signal is emitted whenever the currently selected layer changes
*/
//! layerChanged this signal is emitted whenever the currently selected layer changes
void layerChanged( QgsMapLayer* layer );
};
@@ -20,6 +20,10 @@ IF (WITH_MAPSERVER)
ADD_SUBDIRECTORY(mapserver) # TODO: enable again once compilation is fixed
ENDIF (WITH_MAPSERVER)

IF (WITH_CUSTOM_WIDGETS)
ADD_SUBDIRECTORY(customwidgets)
ENDIF (WITH_CUSTOM_WIDGETS)

IF (WITH_ASTYLE)
ADD_SUBDIRECTORY(astyle)
ENDIF(WITH_ASTYLE)
@@ -67,10 +67,11 @@
#include <QVector>

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

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

connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );

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

// set up the scale based layer visibility stuff....
mScaleRangeWidget->setMapCanvas( mMapCanvas );
chkUseScaleDependentRendering->setChecked( lyr->hasScaleBasedVisibility() );
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
if ( projectScales )
{
QStringList scalesList = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
cbMinimumScale->updateScales( scalesList );
cbMaximumScale->updateScales( scalesList );
}
cbMinimumScale->setScale( 1.0 / lyr->minimumScale() );
cbMaximumScale->setScale( 1.0 / lyr->maximumScale() );

mScaleRangeWidget->setScaleRange( 1.0 / lyr->maximumScale(), 1.0 / lyr->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales

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

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

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

// set up the scale based layer visibility stuff....
mRasterLayer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
mRasterLayer->setMinimumScale( 1.0 / cbMinimumScale->scale() );
mRasterLayer->setMaximumScale( 1.0 / cbMaximumScale->scale() );
// caution: layer uses scale denoms, widget uses true scales
mRasterLayer->setMaximumScale( 1.0 / mScaleRangeWidget->minimumScale() );
mRasterLayer->setMinimumScale( 1.0 / mScaleRangeWidget->maximumScale() );

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

void QgsRasterLayerProperties::on_mMinimumScaleSetCurrentPushButton_clicked()
{
cbMinimumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapSettings().scale() );
}

void QgsRasterLayerProperties::on_mMaximumScaleSetCurrentPushButton_clicked()
{
cbMaximumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapSettings().scale() );
}

void QgsRasterLayerProperties::on_mResetColorRenderingBtn_clicked()
{
mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
@@ -98,8 +98,6 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
void on_pbnSaveStyleAs_clicked();
/** Help button */
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
void on_mMinimumScaleSetCurrentPushButton_clicked();
void on_mMaximumScaleSetCurrentPushButton_clicked();

/** Slot to reset all color rendering options to default
* @note added in 1.9
@@ -81,8 +81,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
initOptionsBase( false );

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


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

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

// set up the scale based layer visibility stuff....
chkUseScaleDependentRendering->setChecked( layer->hasScaleBasedVisibility() );
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
if ( projectScales )
{
QStringList scalesList = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
cbMinimumScale->updateScales( scalesList );
cbMaximumScale->updateScales( scalesList );
}
cbMinimumScale->setScale( 1.0 / layer->minimumScale() );
cbMaximumScale->setScale( 1.0 / layer->maximumScale() );
mScaleRangeWidget->setScaleRange( 1.0 / layer->maximumScale(), 1.0 / layer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
mScaleVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
mScaleRangeWidget->setMapCanvas( QgisApp::instance()->mapCanvas() );

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

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

// set up the scale based layer visibility stuff....
layer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
layer->setMinimumScale( 1.0 / cbMinimumScale->scale() );
layer->setMaximumScale( 1.0 / cbMaximumScale->scale() );
layer->toggleScaleBasedVisibility( mScaleVisibilityGroupBox->isChecked() );
// caution: layer uses scale denoms, widget uses true scales
layer->setMaximumScale( 1.0 / mScaleRangeWidget->minimumScale() );
layer->setMinimumScale( 1.0 / mScaleRangeWidget->maximumScale() );

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

void QgsVectorLayerProperties::on_mMinimumScaleSetCurrentPushButton_clicked()
{
cbMinimumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapSettings().scale() );
}

void QgsVectorLayerProperties::on_mMaximumScaleSetCurrentPushButton_clicked()
{
cbMaximumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapSettings().scale() );
}

void QgsVectorLayerProperties::on_mSimplifyDrawingGroupBox_toggled( bool checked )
{
if ( !( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SimplifyGeometries ) )
@@ -20,6 +20,7 @@
#define QGSVECTORLAYERPROPERTIES

#include "qgsoptionsdialogbase.h"
#include "qgsscalerangewidget.h"
#include "ui_qgsvectorlayerpropertiesbase.h"
#include "qgisgui.h"
#include "qgsaddattrdialog.h"
@@ -116,9 +117,6 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
void on_mButtonAddJoin_clicked();
void on_mButtonRemoveJoin_clicked();

void on_mMinimumScaleSetCurrentPushButton_clicked();
void on_mMaximumScaleSetCurrentPushButton_clicked();

void on_mSimplifyDrawingGroupBox_toggled( bool checked );

signals:

0 comments on commit a5b77b9

Please sign in to comment.