From aa7085194dfb3a22d4c35133a4a68ab62e56cca2 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 19 May 2014 11:50:13 +0200 Subject: [PATCH] custom widgets: added color and data defined buttons, missing SIP for scale range and fix flags for field combo / expression widget --- python/gui/gui.sip | 1 + python/gui/qgsscalerangewidget.sip | 40 ++++++++ src/customwidgets/CMakeLists.txt | 6 ++ src/customwidgets/qgiscustomwidgets.cpp | 10 +- src/customwidgets/qgscolorbuttonplugin.cpp | 97 +++++++++++++++++++ src/customwidgets/qgscolorbuttonplugin.h | 48 +++++++++ .../qgsdatadefinedbuttonplugin.cpp | 97 +++++++++++++++++++ .../qgsdatadefinedbuttonplugin.h | 48 +++++++++ src/gui/qgscolorbutton.h | 5 + src/gui/qgsdatadefinedbutton.h | 1 + src/gui/qgsfieldcombobox.h | 1 + src/gui/qgsfieldexpressionwidget.h | 1 + src/gui/qgsfieldproxymodel.h | 2 + 13 files changed, 351 insertions(+), 6 deletions(-) create mode 100644 python/gui/qgsscalerangewidget.sip create mode 100644 src/customwidgets/qgscolorbuttonplugin.cpp create mode 100644 src/customwidgets/qgscolorbuttonplugin.h create mode 100644 src/customwidgets/qgsdatadefinedbuttonplugin.cpp create mode 100644 src/customwidgets/qgsdatadefinedbuttonplugin.h diff --git a/python/gui/gui.sip b/python/gui/gui.sip index cddf6efa9e4..b5e56373aa7 100644 --- a/python/gui/gui.sip +++ b/python/gui/gui.sip @@ -75,6 +75,7 @@ %Include qgsrasterpyramidsoptionswidget.sip %Include qgsrubberband.sip %Include qgsscalecombobox.sip +%Include qgsscalerangewidget.sip %Include qgssearchquerybuilder.sip %Include qgstextannotationitem.sip %Include qgsvertexmarker.sip diff --git a/python/gui/qgsscalerangewidget.sip b/python/gui/qgsscalerangewidget.sip new file mode 100644 index 00000000000..79120274644 --- /dev/null +++ b/python/gui/qgsscalerangewidget.sip @@ -0,0 +1,40 @@ + +class QgsScaleRangeWidget : QWidget +{ +%TypeHeaderCode +#include "qgsscalerangewidget.h" +%End + + public: + explicit QgsScaleRangeWidget( QWidget *parent /TransferThis/ = 0 ); + ~QgsScaleRangeWidget(); + + //! set the map canvas which will be used for the current scale buttons + /** + * @brief setMapCanvas set the map canvas which will be used for the current scale buttons + * if not set, the buttons are hidden. + */ + void setMapCanvas( QgsMapCanvas* mapCanvas ); + + //! return the minimum scale + double minimumScale(); + + //! return the maximum scale + double maximumScale(); + + //! return the minimum scale denominator ( = 1 / maximum scale ) + double minimumScaleDenom(); + + //! return the maximum scale denominator ( = 1 / minimum scale ) + double maximumScaleDenom(); + + //! call to reload the project scales and apply them to the 2 scales combo boxes + void reloadProjectScales(); + + public slots: + void setMinimumScale( double scale ); + + void setMaximumScale( double scale ); + + void setScaleRange( double min, double max ); +}; diff --git a/src/customwidgets/CMakeLists.txt b/src/customwidgets/CMakeLists.txt index 9bc63cb1b71..01aabd6b9ab 100644 --- a/src/customwidgets/CMakeLists.txt +++ b/src/customwidgets/CMakeLists.txt @@ -9,6 +9,8 @@ ADD_DEFINITIONS(-DQT_SHARED) SET (QGIS_CUSTOMWIDGETS_SRCS qgiscustomwidgets.cpp qgscollapsiblegroupboxplugin.cpp + qgscolorbuttonplugin.cpp + qgsdatadefinedbuttonplugin.cpp qgsfieldcomboboxplugin.cpp qgsfieldexpressionwidgetplugin.cpp qgsmaplayercomboboxplugin.cpp @@ -18,6 +20,8 @@ SET (QGIS_CUSTOMWIDGETS_SRCS SET (QGIS_CUSTOMWIDGETS_MOC_HDRS qgiscustomwidgets.h qgscollapsiblegroupboxplugin.h + qgscolorbuttonplugin.h + qgsdatadefinedbuttonplugin.h qgsfieldcomboboxplugin.h qgsfieldexpressionwidgetplugin.h qgsmaplayercomboboxplugin.h @@ -33,6 +37,8 @@ ENDIF(UNIX) SET(QGIS_CUSTOMWIDGETS_HDRS qgiscustomwidgets.h qgscollapsiblegroupboxplugin.h + qgscolorbuttonplugin.h + qgsdatadefinedbuttonplugin.h qgsfieldcomboboxplugin.h qgsfieldexpressionwidgetplugin.h qgsmaplayercomboboxplugin.h diff --git a/src/customwidgets/qgiscustomwidgets.cpp b/src/customwidgets/qgiscustomwidgets.cpp index becaf56a35c..be15bbf4311 100644 --- a/src/customwidgets/qgiscustomwidgets.cpp +++ b/src/customwidgets/qgiscustomwidgets.cpp @@ -18,6 +18,8 @@ #include "qgiscustomwidgets.h" #include "qgscollapsiblegroupboxplugin.h" +#include "qgscolorbuttonplugin.h" +#include "qgsdatadefinedbuttonplugin.h" #include "qgsfieldcomboboxplugin.h" #include "qgsfieldexpressionwidgetplugin.h" #include "qgsmaplayercomboboxplugin.h" @@ -27,13 +29,9 @@ QgisCustomWidgets::QgisCustomWidgets( QObject *parent ) : QObject( parent ) { - - // !!!!!!!!!!!!!!!!!!!!! - // do not forget to add the corresponding line in python/customwidgets.py - // to make the custom widget available from python - // !!!!!!!!!!!!!!!!!!!!! - mWidgets.append( new QgsCollapsibleGroupBoxPlugin ); + mWidgets.append( new QgsColorButtonPlugin ); + mWidgets.append( new QgsDataDefinedButtonPlugin ); mWidgets.append( new QgsFieldComboBoxPlugin ); mWidgets.append( new QgsFieldExpressionWidgetPlugin ); mWidgets.append( new QgsMapLayerComboBoxPlugin ); diff --git a/src/customwidgets/qgscolorbuttonplugin.cpp b/src/customwidgets/qgscolorbuttonplugin.cpp new file mode 100644 index 00000000000..d63f20b8b45 --- /dev/null +++ b/src/customwidgets/qgscolorbuttonplugin.cpp @@ -0,0 +1,97 @@ +/*************************************************************************** + qgscolorbuttonplugin.cpp + -------------------------------------- + Date : 25.04.2014 + Copyright : (C) 2014 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. * +* * +***************************************************************************/ + +#include "qgiscustomwidgets.h" +#include "qgscolorbuttonplugin.h" +#include "qgscolorbutton.h" + + +QgsColorButtonPlugin::QgsColorButtonPlugin( QObject *parent ) + : QObject( parent ) + , mInitialized( false ) +{ +} + + +QString QgsColorButtonPlugin::name() const +{ + return "QgsColorButton"; +} + +QString QgsColorButtonPlugin::group() const +{ + return QgisCustomWidgets::groupName(); +} + +QString QgsColorButtonPlugin::includeFile() const +{ + return "qgscolorbutton.h"; +} + +QIcon QgsColorButtonPlugin::icon() const +{ + return QIcon(); +} + +bool QgsColorButtonPlugin::isContainer() const +{ + return false; +} + +QWidget *QgsColorButtonPlugin::createWidget( QWidget *parent ) +{ + return new QgsColorButton( parent ); +} + +bool QgsColorButtonPlugin::isInitialized() const +{ + return mInitialized; +} + +void QgsColorButtonPlugin::initialize( QDesignerFormEditorInterface *core ) +{ + Q_UNUSED( core ); + if ( mInitialized ) + return; + mInitialized = true; +} + + +QString QgsColorButtonPlugin::toolTip() const +{ + return "A widget to define the scale range"; +} + +QString QgsColorButtonPlugin::whatsThis() const +{ + return "A widget to define the scale range."; +} + +QString QgsColorButtonPlugin::domXml() const +{ + return QString( "\n" + " \n" + " \n" + " \n" + " 0\n" + " 0\n" + " 27\n" + " 27\n" + " \n" + " \n" + " \n" + "\n" ) + .arg( name() ); +} diff --git a/src/customwidgets/qgscolorbuttonplugin.h b/src/customwidgets/qgscolorbuttonplugin.h new file mode 100644 index 00000000000..7c3674b3d7d --- /dev/null +++ b/src/customwidgets/qgscolorbuttonplugin.h @@ -0,0 +1,48 @@ +/*************************************************************************** + qgscolorbuttonplugin.h + -------------------------------------- + Date : 25.04.2014 + Copyright : (C) 2014 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. * +* * +***************************************************************************/ + +#ifndef QGSCOLORBUTTONPLUGIN_H +#define QGSCOLORBUTTONPLUGIN_H + +#include +#include + + +class QDESIGNER_WIDGET_EXPORT QgsColorButtonPlugin : public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES( QDesignerCustomWidgetInterface ) + + public: + explicit QgsColorButtonPlugin( QObject *parent = 0 ); + + private: + bool mInitialized; + + // QDesignerCustomWidgetInterface interface + public: + QString name() const; + QString group() const; + QString includeFile() const; + QIcon icon() const; + bool isContainer() const; + QWidget *createWidget( QWidget *parent ); + bool isInitialized() const; + void initialize( QDesignerFormEditorInterface *core ); + QString toolTip() const; + QString whatsThis() const; + QString domXml() const; +}; +#endif // QGSCOLORBUTTONPLUGIN_H diff --git a/src/customwidgets/qgsdatadefinedbuttonplugin.cpp b/src/customwidgets/qgsdatadefinedbuttonplugin.cpp new file mode 100644 index 00000000000..a3016c7186e --- /dev/null +++ b/src/customwidgets/qgsdatadefinedbuttonplugin.cpp @@ -0,0 +1,97 @@ +/*************************************************************************** + qgsdatadefinedbuttonplugin.cpp + -------------------------------------- + Date : 25.04.2014 + Copyright : (C) 2014 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. * +* * +***************************************************************************/ + +#include "qgiscustomwidgets.h" +#include "qgsdatadefinedbuttonplugin.h" +#include "qgsdatadefinedbutton.h" + + +QgsDataDefinedButtonPlugin::QgsDataDefinedButtonPlugin( QObject *parent ) + : QObject( parent ) + , mInitialized( false ) +{ +} + + +QString QgsDataDefinedButtonPlugin::name() const +{ + return "QgsDataDefinedButton"; +} + +QString QgsDataDefinedButtonPlugin::group() const +{ + return QgisCustomWidgets::groupName(); +} + +QString QgsDataDefinedButtonPlugin::includeFile() const +{ + return "qgsdatadefinedbutton.h"; +} + +QIcon QgsDataDefinedButtonPlugin::icon() const +{ + return QIcon(); +} + +bool QgsDataDefinedButtonPlugin::isContainer() const +{ + return false; +} + +QWidget *QgsDataDefinedButtonPlugin::createWidget( QWidget *parent ) +{ + return new QgsDataDefinedButton( parent ); +} + +bool QgsDataDefinedButtonPlugin::isInitialized() const +{ + return mInitialized; +} + +void QgsDataDefinedButtonPlugin::initialize( QDesignerFormEditorInterface *core ) +{ + Q_UNUSED( core ); + if ( mInitialized ) + return; + mInitialized = true; +} + + +QString QgsDataDefinedButtonPlugin::toolTip() const +{ + return "A widget to define the scale range"; +} + +QString QgsDataDefinedButtonPlugin::whatsThis() const +{ + return "A widget to define the scale range."; +} + +QString QgsDataDefinedButtonPlugin::domXml() const +{ + return QString( "\n" + " \n" + " \n" + " \n" + " 0\n" + " 0\n" + " 27\n" + " 27\n" + " \n" + " \n" + " \n" + "\n" ) + .arg( name() ); +} diff --git a/src/customwidgets/qgsdatadefinedbuttonplugin.h b/src/customwidgets/qgsdatadefinedbuttonplugin.h new file mode 100644 index 00000000000..3447de46c73 --- /dev/null +++ b/src/customwidgets/qgsdatadefinedbuttonplugin.h @@ -0,0 +1,48 @@ +/*************************************************************************** + qgsdatadefinedbuttonplugin.h + -------------------------------------- + Date : 25.04.2014 + Copyright : (C) 2014 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. * +* * +***************************************************************************/ + +#ifndef QGSDATADEFINEDBUTTONPLUGIN_H +#define QGSDATADEFINEDBUTTONPLUGIN_H + +#include +#include + + +class QDESIGNER_WIDGET_EXPORT QgsDataDefinedButtonPlugin : public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES( QDesignerCustomWidgetInterface ) + + public: + explicit QgsDataDefinedButtonPlugin( QObject *parent = 0 ); + + private: + bool mInitialized; + + // QDesignerCustomWidgetInterface interface + public: + QString name() const; + QString group() const; + QString includeFile() const; + QIcon icon() const; + bool isContainer() const; + QWidget *createWidget( QWidget *parent ); + bool isInitialized() const; + void initialize( QDesignerFormEditorInterface *core ); + QString toolTip() const; + QString whatsThis() const; + QString domXml() const; +}; +#endif // QGSDATADEFINEDBUTTONPLUGIN_H diff --git a/src/gui/qgscolorbutton.h b/src/gui/qgscolorbutton.h index 5679470a7a1..aad4447b016 100644 --- a/src/gui/qgscolorbutton.h +++ b/src/gui/qgscolorbutton.h @@ -30,6 +30,11 @@ class GUI_EXPORT QgsColorButton: public QPushButton { Q_OBJECT + Q_PROPERTY( QString colorDialogTitle READ colorDialogTitle WRITE setColorDialogTitle ) + Q_PROPERTY( bool acceptLiveUpdates READ acceptLiveUpdates WRITE setAcceptLiveUpdates ) + Q_PROPERTY( QColor color READ color WRITE setColor ) + Q_FLAGS( QColorDialog::ColorDialogOptions ) + Q_PROPERTY( QColorDialog::ColorDialogOptions colorDialogOptions READ colorDialogOptions WRITE setColorDialogOptions ) public: /** diff --git a/src/gui/qgsdatadefinedbutton.h b/src/gui/qgsdatadefinedbutton.h index 421596958c2..02d116a4aa7 100644 --- a/src/gui/qgsdatadefinedbutton.h +++ b/src/gui/qgsdatadefinedbutton.h @@ -34,6 +34,7 @@ class QgsVectorLayer; class GUI_EXPORT QgsDataDefinedButton: public QToolButton { Q_OBJECT + Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo ) public: enum DataType diff --git a/src/gui/qgsfieldcombobox.h b/src/gui/qgsfieldcombobox.h index 11de453a103..70fa1af7f2c 100644 --- a/src/gui/qgsfieldcombobox.h +++ b/src/gui/qgsfieldcombobox.h @@ -33,6 +33,7 @@ class QgsVectorLayer; class GUI_EXPORT QgsFieldComboBox : public QComboBox { Q_OBJECT + Q_FLAGS( QgsFieldProxyModel::Filters ) Q_PROPERTY( QgsFieldProxyModel::Filters filters READ filters WRITE setFilters ) public: diff --git a/src/gui/qgsfieldexpressionwidget.h b/src/gui/qgsfieldexpressionwidget.h index 9179e029ce7..92ef707d92c 100644 --- a/src/gui/qgsfieldexpressionwidget.h +++ b/src/gui/qgsfieldexpressionwidget.h @@ -41,6 +41,7 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget { Q_OBJECT Q_PROPERTY( QString expressionDialogTitle READ expressionDialogTitle WRITE setExpressionDialogTitle ) + Q_FLAGS( QgsFieldProxyModel::Filters ) Q_PROPERTY( QgsFieldProxyModel::Filters filters READ filters WRITE setFilters ) public: diff --git a/src/gui/qgsfieldproxymodel.h b/src/gui/qgsfieldproxymodel.h index c6b9b7439cf..f37a3d43cfd 100644 --- a/src/gui/qgsfieldproxymodel.h +++ b/src/gui/qgsfieldproxymodel.h @@ -27,6 +27,8 @@ class GUI_EXPORT QgsFieldProxyModel : public QSortFilterProxyModel { Q_OBJECT + Q_FLAGS( Filters ) + public: enum Filter {