Skip to content

Commit

Permalink
custom widgets: added color and data defined buttons, missing SIP for…
Browse files Browse the repository at this point in the history
… scale range and fix flags for field combo / expression widget
  • Loading branch information
3nids committed May 19, 2014
1 parent 74392f7 commit aa70851
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 6 deletions.
1 change: 1 addition & 0 deletions python/gui/gui.sip
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions 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 );
};
6 changes: 6 additions & 0 deletions src/customwidgets/CMakeLists.txt
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -33,6 +37,8 @@ ENDIF(UNIX)
SET(QGIS_CUSTOMWIDGETS_HDRS
qgiscustomwidgets.h
qgscollapsiblegroupboxplugin.h
qgscolorbuttonplugin.h
qgsdatadefinedbuttonplugin.h
qgsfieldcomboboxplugin.h
qgsfieldexpressionwidgetplugin.h
qgsmaplayercomboboxplugin.h
Expand Down
10 changes: 4 additions & 6 deletions src/customwidgets/qgiscustomwidgets.cpp
Expand Up @@ -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"
Expand All @@ -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 );
Expand Down
97 changes: 97 additions & 0 deletions 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( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mColorButton\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>27</width>\n"
" <height>27</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}
48 changes: 48 additions & 0 deletions 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 <QDesignerExportWidget>
#include <QDesignerCustomWidgetInterface>


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
97 changes: 97 additions & 0 deletions 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( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mDataDefinedButton\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>27</width>\n"
" <height>27</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}
48 changes: 48 additions & 0 deletions 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 <QDesignerExportWidget>
#include <QDesignerCustomWidgetInterface>


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

0 comments on commit aa70851

Please sign in to comment.