77 changes: 77 additions & 0 deletions src/customwidgets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
ADD_DEFINITIONS(-DQT_PLUGIN)
ADD_DEFINITIONS(-DQT_NO_DEBUG)
ADD_DEFINITIONS(-DQT_SHARED)


########################################################
# Files

SET (QGIS_CUSTOMWIDGETS_SRCS
qgiscustomwidgets.cpp
qgscollapsiblegroupboxplugin.cpp
qgsfieldcomboboxplugin.cpp
qgsfieldexpressionwidgetplugin.cpp
qgsmaplayercomboboxplugin.cpp
qgsscalerangewidgetplugin.cpp
)

SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
qgiscustomwidgets.h
qgscollapsiblegroupboxplugin.h
qgsfieldcomboboxplugin.h
qgsfieldexpressionwidgetplugin.h
qgsmaplayercomboboxplugin.h
qgsscalerangewidgetplugin.h
)

QT4_WRAP_CPP(QGIS_CUSTOMWIDGETS_MOC_SRCS ${QGIS_CUSTOMWIDGETS_MOC_HDRS})

IF(UNIX)
SET_SOURCE_FILES_PROPERTIES(${QGIS_CUSTOMWIDGETS_MOC_SRCS} PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations" )
ENDIF(UNIX)

SET(QGIS_CUSTOMWIDGETS_HDRS
qgiscustomwidgets.h
qgscollapsiblegroupboxplugin.h
qgsfieldcomboboxplugin.h
qgsfieldexpressionwidgetplugin.h
qgsmaplayercomboboxplugin.h
qgsscalerangewidgetplugin.h
)

# left commented as there is no UI file yet
# SET(QGIS_CUSTOMWIDGETS_UI_HDRS
# ${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsXXXwidget.h
# )

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../core/
${CMAKE_CURRENT_SOURCE_DIR}/../gui/
# ${CMAKE_CURRENT_BINARY_DIR}/../ui (no UI file yet)
)

#############################################################
# qgis_customwidgets library

ADD_LIBRARY(qgis_customwidgets SHARED ${QGIS_CUSTOMWIDGETS_SRCS} ${QGIS_CUSTOMWIDGETS_MOC_SRCS} ${QGIS_CUSTOMWIDGETS_HDRS})

# TODO: apple
INSTALL(FILES ${QGIS_CUSTOMWIDGETS_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})

SET_TARGET_PROPERTIES(qgis_customwidgets PROPERTIES
VERSION ${COMPLETE_VERSION}
SOVERSION ${COMPLETE_VERSION}
)

# make sure that UI files will be processed first
# left commented as there is no UI file yet
# ADD_DEPENDENCIES(qgis_customwidgets ui)

TARGET_LINK_LIBRARIES(qgis_customwidgets qgis_gui)

# install
INSTALL(TARGETS qgis_customwidgets
LIBRARY DESTINATION ${QGIS_CUSTOMWIDGETS_DIR})


48 changes: 48 additions & 0 deletions src/customwidgets/qgiscustomwidgets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***************************************************************************
qgscustomwidgets.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 "qplugin.h"

#include "qgiscustomwidgets.h"

#include "qgscollapsiblegroupboxplugin.h"
#include "qgsfieldcomboboxplugin.h"
#include "qgsfieldexpressionwidgetplugin.h"
#include "qgsmaplayercomboboxplugin.h"
#include "qgsscalerangewidgetplugin.h"


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 QgsFieldComboBoxPlugin );
mWidgets.append( new QgsFieldExpressionWidgetPlugin );
mWidgets.append( new QgsMapLayerComboBoxPlugin );
mWidgets.append( new QgsScaleRangeWidgetPlugin );
}

QList<QDesignerCustomWidgetInterface*> QgisCustomWidgets::customWidgets() const
{
return mWidgets;
}

Q_EXPORT_PLUGIN2( customwidgetsplugin, QgisCustomWidgets )
38 changes: 38 additions & 0 deletions src/customwidgets/qgiscustomwidgets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/***************************************************************************
qgscustomwidgets.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 QGISCUSTOMWIDGETS_H
#define QGISCUSTOMWIDGETS_H

#include <QDesignerCustomWidgetCollectionInterface>
#include <qplugin.h>

class QgisCustomWidgets : public QObject, public QDesignerCustomWidgetCollectionInterface
{
Q_OBJECT
Q_INTERFACES( QDesignerCustomWidgetCollectionInterface )

public:
explicit QgisCustomWidgets( QObject *parent = 0 );

virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;

static QString groupName() {return "QGIS custom widgets";}

private:
QList<QDesignerCustomWidgetInterface*> mWidgets;
};

#endif // QGISCUSTOMWIDGETS_H
97 changes: 97 additions & 0 deletions src/customwidgets/qgscollapsiblegroupboxplugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/***************************************************************************
qgscollapsiblegroupboxplugin.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 "qgscollapsiblegroupbox.h"
#include "qgscollapsiblegroupboxplugin.h"


QgsCollapsibleGroupBoxPlugin::QgsCollapsibleGroupBoxPlugin( QObject *parent )
: QObject( parent )
, mInitialized( false )
{
}


QString QgsCollapsibleGroupBoxPlugin::name() const
{
return "QgsCollapsibleGroupBox";
}

QString QgsCollapsibleGroupBoxPlugin::group() const
{
return QgisCustomWidgets::groupName();
}

QString QgsCollapsibleGroupBoxPlugin::includeFile() const
{
return "qgscollapsiblegroupbox.h";
}

QIcon QgsCollapsibleGroupBoxPlugin::icon() const
{
return QIcon();
}

bool QgsCollapsibleGroupBoxPlugin::isContainer() const
{
return true;
}

QWidget *QgsCollapsibleGroupBoxPlugin::createWidget( QWidget *parent )
{
return new QgsCollapsibleGroupBox( parent );
}

bool QgsCollapsibleGroupBoxPlugin::isInitialized() const
{
return mInitialized;
}

void QgsCollapsibleGroupBoxPlugin::initialize( QDesignerFormEditorInterface *core )
{
Q_UNUSED( core );
if ( mInitialized )
return;
mInitialized = true;
}


QString QgsCollapsibleGroupBoxPlugin::toolTip() const
{
return "A collapsible group box";
}

QString QgsCollapsibleGroupBoxPlugin::whatsThis() const
{
return "A collapsible group box with save state capability";
}

QString QgsCollapsibleGroupBoxPlugin::domXml() const
{
return QString( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mGroupBox\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>300</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}
48 changes: 48 additions & 0 deletions src/customwidgets/qgscollapsiblegroupboxplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***************************************************************************
qgscollapsiblegroupboxplugin.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 QGSCOLLAPSIBLEGROUPBOXPLUGIN_H
#define QGSCOLLAPSIBLEGROUPBOXPLUGIN_H

#include <QDesignerExportWidget>
#include <QDesignerCustomWidgetInterface>


class QDESIGNER_WIDGET_EXPORT QgsCollapsibleGroupBoxPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES( QDesignerCustomWidgetInterface )

public:
explicit QgsCollapsibleGroupBoxPlugin( 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 // QGSCOLLAPSIBLEGROUPBOXPLUGIN_H
97 changes: 97 additions & 0 deletions src/customwidgets/qgsfieldcomboboxplugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/***************************************************************************
qgsfieldcomboboxplugin.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 "qgsfieldcombobox.h"
#include "qgsfieldcomboboxplugin.h"


QgsFieldComboBoxPlugin::QgsFieldComboBoxPlugin( QObject *parent )
: QObject( parent )
, mInitialized( false )
{
}


QString QgsFieldComboBoxPlugin::name() const
{
return "QgsFieldComboBox";
}

QString QgsFieldComboBoxPlugin::group() const
{
return QgisCustomWidgets::groupName();
}

QString QgsFieldComboBoxPlugin::includeFile() const
{
return "qgsfieldcombobox.h";
}

QIcon QgsFieldComboBoxPlugin::icon() const
{
return QIcon();
}

bool QgsFieldComboBoxPlugin::isContainer() const
{
return false;
}

QWidget *QgsFieldComboBoxPlugin::createWidget( QWidget *parent )
{
return new QgsFieldComboBox( parent );
}

bool QgsFieldComboBoxPlugin::isInitialized() const
{
return mInitialized;
}

void QgsFieldComboBoxPlugin::initialize( QDesignerFormEditorInterface *core )
{
Q_UNUSED( core );
if ( mInitialized )
return;
mInitialized = true;
}


QString QgsFieldComboBoxPlugin::toolTip() const
{
return "A combo box to list the fields of a layer";
}

QString QgsFieldComboBoxPlugin::whatsThis() const
{
return "A combo box to list the field of a layer.";
}

QString QgsFieldComboBoxPlugin::domXml() const
{
return QString( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mFieldComboBox\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>160</width>\n"
" <height>27</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}
48 changes: 48 additions & 0 deletions src/customwidgets/qgsfieldcomboboxplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***************************************************************************
qgsfieldcomboboxplugin.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 QGSFIELDCOMBOBOXPLUGIN_H
#define QGSFIELDCOMBOBOXPLUGIN_H

#include <QDesignerExportWidget>
#include <QDesignerCustomWidgetInterface>


class QDESIGNER_WIDGET_EXPORT QgsFieldComboBoxPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES( QDesignerCustomWidgetInterface )

public:
explicit QgsFieldComboBoxPlugin( 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 // QGSFIELDCOMBOBOXPLUGIN_H
97 changes: 97 additions & 0 deletions src/customwidgets/qgsfieldexpressionwidgetplugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/***************************************************************************
qgsfieldexpressionwidgetplugin.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 "qgsfieldexpressionwidgetplugin.h"
#include "qgsfieldexpressionwidget.h"


QgsFieldExpressionWidgetPlugin::QgsFieldExpressionWidgetPlugin( QObject *parent )
: QObject( parent )
, mInitialized( false )
{
}


QString QgsFieldExpressionWidgetPlugin::name() const
{
return "QgsFieldExpressionWidget";
}

QString QgsFieldExpressionWidgetPlugin::group() const
{
return QgisCustomWidgets::groupName();
}

QString QgsFieldExpressionWidgetPlugin::includeFile() const
{
return "qgsfieldexpressionwidget.h";
}

QIcon QgsFieldExpressionWidgetPlugin::icon() const
{
return QIcon();
}

bool QgsFieldExpressionWidgetPlugin::isContainer() const
{
return false;
}

QWidget *QgsFieldExpressionWidgetPlugin::createWidget( QWidget *parent )
{
return new QgsFieldExpressionWidget( parent );
}

bool QgsFieldExpressionWidgetPlugin::isInitialized() const
{
return mInitialized;
}

void QgsFieldExpressionWidgetPlugin::initialize( QDesignerFormEditorInterface *core )
{
Q_UNUSED( core );
if ( mInitialized )
return;
mInitialized = true;
}


QString QgsFieldExpressionWidgetPlugin::toolTip() const
{
return "An editable combo box to enter an expression";
}

QString QgsFieldExpressionWidgetPlugin::whatsThis() const
{
return "An editable combo box to enter an expression. A button allows opening the expression dialog. Expression are evaluated to detect errors.";
}

QString QgsFieldExpressionWidgetPlugin::domXml() const
{
return QString( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mFieldExpressionWidget\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>200</width>\n"
" <height>27</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}
48 changes: 48 additions & 0 deletions src/customwidgets/qgsfieldexpressionwidgetplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***************************************************************************
qgsfieldexpressionwidgetplugin.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 QGSFIELDEXPRESSIONWIDGETPLUGIN_H
#define QGSFIELDEXPRESSIONWIDGETPLUGIN_H

#include <QDesignerExportWidget>
#include <QDesignerCustomWidgetInterface>


class QDESIGNER_WIDGET_EXPORT QgsFieldExpressionWidgetPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES( QDesignerCustomWidgetInterface )

public:
explicit QgsFieldExpressionWidgetPlugin( 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 // QGSFIELDEXPRESSIONWIDGETPLUGIN_H
97 changes: 97 additions & 0 deletions src/customwidgets/qgsmaplayercomboboxplugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/***************************************************************************
qgsmaplayercomboboxplugin.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 "qgsmaplayercombobox.h"
#include "qgsmaplayercomboboxplugin.h"


QgsMapLayerComboBoxPlugin::QgsMapLayerComboBoxPlugin( QObject *parent )
: QObject( parent )
, mInitialized( false )
{
}


QString QgsMapLayerComboBoxPlugin::name() const
{
return "QgsMapLayerComboBox";
}

QString QgsMapLayerComboBoxPlugin::group() const
{
return QgisCustomWidgets::groupName();
}

QString QgsMapLayerComboBoxPlugin::includeFile() const
{
return "qgsmaplayercombobox.h";
}

QIcon QgsMapLayerComboBoxPlugin::icon() const
{
return QIcon();
}

bool QgsMapLayerComboBoxPlugin::isContainer() const
{
return false;
}

QWidget *QgsMapLayerComboBoxPlugin::createWidget( QWidget *parent )
{
return new QgsMapLayerComboBox( parent );
}

bool QgsMapLayerComboBoxPlugin::isInitialized() const
{
return mInitialized;
}

void QgsMapLayerComboBoxPlugin::initialize( QDesignerFormEditorInterface *core )
{
Q_UNUSED( core );
if ( mInitialized )
return;
mInitialized = true;
}


QString QgsMapLayerComboBoxPlugin::toolTip() const
{
return "A combo box to list the layers";
}

QString QgsMapLayerComboBoxPlugin::whatsThis() const
{
return "A combo box to list the layers registered in QGIS. Layers might be filtered according to their type.";
}

QString QgsMapLayerComboBoxPlugin::domXml() const
{
return QString( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mMapLayerComboBox\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>160</width>\n"
" <height>27</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}
49 changes: 49 additions & 0 deletions src/customwidgets/qgsmaplayercomboboxplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/***************************************************************************
qgsmaplayercomboboxplugin.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 QGSMAPLAYERCOMBOBOXPLUGIN_H
#define QGSMAPLAYERCOMBOBOXPLUGIN_H

#include <QDesignerExportWidget>
#include <QDesignerCustomWidgetInterface>


class QDESIGNER_WIDGET_EXPORT QgsMapLayerComboBoxPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES( QDesignerCustomWidgetInterface )

public:
explicit QgsMapLayerComboBoxPlugin( 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 // QGSMAPLAYERCOMBOBOXPLUGIN_H
97 changes: 97 additions & 0 deletions src/customwidgets/qgsscalerangewidgetplugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/***************************************************************************
qgsscalerangewidgetplugin.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 "qgsscalerangewidgetplugin.h"
#include "qgsscalerangewidget.h"


QgsScaleRangeWidgetPlugin::QgsScaleRangeWidgetPlugin( QObject *parent )
: QObject( parent )
, mInitialized( false )
{
}


QString QgsScaleRangeWidgetPlugin::name() const
{
return "QgsScaleRangeWidget";
}

QString QgsScaleRangeWidgetPlugin::group() const
{
return QgisCustomWidgets::groupName();
}

QString QgsScaleRangeWidgetPlugin::includeFile() const
{
return "qgsscalerangewidget.h";
}

QIcon QgsScaleRangeWidgetPlugin::icon() const
{
return QIcon();
}

bool QgsScaleRangeWidgetPlugin::isContainer() const
{
return false;
}

QWidget *QgsScaleRangeWidgetPlugin::createWidget( QWidget *parent )
{
return new QgsScaleRangeWidget( parent );
}

bool QgsScaleRangeWidgetPlugin::isInitialized() const
{
return mInitialized;
}

void QgsScaleRangeWidgetPlugin::initialize( QDesignerFormEditorInterface *core )
{
Q_UNUSED( core );
if ( mInitialized )
return;
mInitialized = true;
}


QString QgsScaleRangeWidgetPlugin::toolTip() const
{
return "A widget to define the scale range";
}

QString QgsScaleRangeWidgetPlugin::whatsThis() const
{
return "A widget to define the scale range.";
}

QString QgsScaleRangeWidgetPlugin::domXml() const
{
return QString( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mScaleRangeWidget\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>400</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}
48 changes: 48 additions & 0 deletions src/customwidgets/qgsscalerangewidgetplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***************************************************************************
qgsscalerangewidgetplugin.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 QGSSCALERANGEWIDGETPLUGIN_H
#define QGSSCALERANGEWIDGETPLUGIN_H

#include <QDesignerExportWidget>
#include <QDesignerCustomWidgetInterface>


class QDESIGNER_WIDGET_EXPORT QgsScaleRangeWidgetPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES( QDesignerCustomWidgetInterface )

public:
explicit QgsScaleRangeWidgetPlugin( 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 // QGSSCALERANGEWIDGETPLUGIN_H
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ qgsrelationeditor.cpp
qgsrelationmanagerdialog.cpp
qgsrubberband.cpp
qgsscalecombobox.cpp
qgsscalerangewidget.cpp
qgssearchquerybuilder.cpp
qgssublayersdialog.cpp
qgssvgannotationitem.cpp
Expand Down Expand Up @@ -276,6 +277,7 @@ qgsrelationadddlg.h
qgsrelationeditor.h
qgsrelationmanagerdialog.h
qgsscalecombobox.h
qgsscalerangewidget.h
qgssearchquerybuilder.h
qgssublayersdialog.h
qgsunitselectionwidget.h
Expand Down Expand Up @@ -340,6 +342,7 @@ qgsprojectionselector.h
qgsrelationeditor.h
qgsrubberband.h
qgsscalecombobox.h
qgsscalerangewidget.h
qgssearchquerybuilder.h
qgssublayersdialog.h
qgsvectorlayertools.h
Expand Down
23 changes: 10 additions & 13 deletions src/gui/qgsmaplayercombobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,38 @@ class QgsVectorLayer;
class GUI_EXPORT QgsMapLayerComboBox : public QComboBox
{
Q_OBJECT
Q_FLAGS( QgsMapLayerProxyModel::Filters )
Q_PROPERTY( QgsMapLayerProxyModel::Filters filters READ filters WRITE setFilters )

public:
/**
* @brief QgsMapLayerComboBox creates a combo box to dislpay the list of layers (currently in the registry).
* The layers can be filtered and/or ordered.
*/
explicit QgsMapLayerComboBox( QWidget *parent = 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() { return mProxyModel->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 );

protected slots:
void indexChanged( int i );

private:
QgsMapLayerProxyModel* mProxyModel;

};

#endif // QGSMAPLAYERCOMBOBOX_H
1 change: 1 addition & 0 deletions src/gui/qgsmaplayerproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class QgsMapLayerModel;
class GUI_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_FLAGS( Filters )
public:
enum Filter
{
Expand Down
156 changes: 156 additions & 0 deletions src/gui/qgsscalerangewidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/***************************************************************************
qgsscalerangewidget.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 "qgsscalerangewidget.h"
#include "qgsapplication.h"
#include "qgsproject.h"


QgsScaleRangeWidget::QgsScaleRangeWidget( QWidget *parent )
: QWidget( parent )
, mCanvas( 0 )
, mMaximumScaleSetCurrentPushButton( 0 )
, mMinimumScaleSetCurrentPushButton( 0 )
{
mLayout = new QGridLayout( this );
mLayout->setContentsMargins( 0, 0, 0, 0 );

QLabel* minLbl = new QLabel( tr( "Minimimum\n(exclusive)" ), this );
minLbl->setWordWrap( true );
minLbl->setAlignment( Qt::AlignTop );
minLbl->setToolTip( tr( "Minimum scale, i.e. maximum scale denominator. "
"This limit is exclusive, that means the layer will not be displayed on this scale." ) );
QLabel* maxLbl = new QLabel( tr( "Maximimum\n(inclusive)" ), this );
maxLbl->setWordWrap( true );
maxLbl->setAlignment( Qt::AlignTop );
maxLbl->setToolTip( tr( "Maximum scale, i.e. minimum scale denominator. "
"This limit is inclusive, that means the layer will be displayed on this scale." ) );

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

mMinimumScaleComboBox = new QgsScaleComboBox( this );
mMaximumScaleComboBox = new QgsScaleComboBox( this );
reloadProjectScales();
// add start, add comprehension of scales by settings fake ordered values
mMinimumScaleComboBox->setCurrentIndex( 2 );
mMaximumScaleComboBox->setCurrentIndex( mMinimumScaleComboBox->currentIndex() + 2 );

mLayout->addWidget( minLbl, 0, 0, 2, 1 );
mLayout->addWidget( mMinimumScaleIconLabel, 0, 1 );
mLayout->addWidget( mMinimumScaleComboBox, 0, 2 );
mLayout->addWidget( maxLbl, 0, 3, 2, 1 );
mLayout->addWidget( mMaximumScaleIconLabel, 0, 4 );
mLayout->addWidget( mMaximumScaleComboBox, 0, 5 );

mLayout->setColumnStretch( 0, 0 );
mLayout->setColumnStretch( 1, 0 );
mLayout->setColumnStretch( 2, 3 );
mLayout->setColumnStretch( 3, 0 );
mLayout->setColumnStretch( 4, 0 );
mLayout->setColumnStretch( 5, 3 );
}

QgsScaleRangeWidget::~QgsScaleRangeWidget()
{
}

void QgsScaleRangeWidget::reloadProjectScales()
{
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
if ( projectScales )
{
QStringList scalesList = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
mMinimumScaleComboBox->updateScales( scalesList );
mMaximumScaleComboBox->updateScales( scalesList );
}
}

void QgsScaleRangeWidget::setMapCanvas( QgsMapCanvas *mapCanvas )
{
if ( mMinimumScaleSetCurrentPushButton )
{
delete mMinimumScaleSetCurrentPushButton;
mMinimumScaleSetCurrentPushButton = 0;
}
if ( mMaximumScaleSetCurrentPushButton )
{
delete mMaximumScaleSetCurrentPushButton;
mMaximumScaleSetCurrentPushButton = 0;
}

if ( !mapCanvas )
return;

mCanvas = mapCanvas;

mMinimumScaleSetCurrentPushButton = new QPushButton( tr( "current" ), this );
connect( mMinimumScaleSetCurrentPushButton, SIGNAL( clicked() ), this, SLOT( setMinScaleFromCanvas() ) );
mMaximumScaleSetCurrentPushButton = new QPushButton( tr( "current" ), this );
connect( mMaximumScaleSetCurrentPushButton, SIGNAL( clicked() ), this, SLOT( setMaxScaleFromCanvas() ) );

mLayout->addWidget( mMinimumScaleSetCurrentPushButton, 1, 2 );
mLayout->addWidget( mMaximumScaleSetCurrentPushButton, 1, 5 );
}

void QgsScaleRangeWidget::setMinimumScale( double scale )
{
mMinimumScaleComboBox->setScale( scale );
}

double QgsScaleRangeWidget::minimumScale()
{
return mMinimumScaleComboBox->scale();
}

void QgsScaleRangeWidget::setMaximumScale( double scale )
{
mMaximumScaleComboBox->setScale( scale );
}

double QgsScaleRangeWidget::maximumScale()
{
return mMaximumScaleComboBox->scale();
}

double QgsScaleRangeWidget::minimumScaleDenom()
{
return qRound( 1.0 / maximumScale() );
}

double QgsScaleRangeWidget::maximumScaleDenom()
{
return qRound( 1.0 / minimumScale() );
}

void QgsScaleRangeWidget::setScaleRange( double min, double max )
{
setMaximumScale( max );
setMinimumScale( min );
}

void QgsScaleRangeWidget::setMinScaleFromCanvas()
{
mMinimumScaleComboBox->setScale( 1.0 / mCanvas->mapSettings().scale() );
}

void QgsScaleRangeWidget::setMaxScaleFromCanvas()
{
mMaximumScaleComboBox->setScale( 1.0 / mCanvas->mapSettings().scale() );
}


85 changes: 85 additions & 0 deletions src/gui/qgsscalerangewidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/***************************************************************************
qgsscalerangewidget.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 QGSSCALERANGEWIDGET_H
#define QGSSCALERANGEWIDGET_H

#include <QGridLayout>
#include <QLabel>
#include <QPushButton>


#include "qgscollapsiblegroupbox.h"
#include "qgsmaplayer.h"
#include "qgsmapcanvas.h"
#include "qgsscalecombobox.h"


class GUI_EXPORT QgsScaleRangeWidget : public QWidget
{
Q_OBJECT

public:
explicit QgsScaleRangeWidget( QWidget *parent = 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 );

private slots:
void setMaxScaleFromCanvas();
void setMinScaleFromCanvas();

private:
//! pointer to the map canvas used for current buttons.
QgsMapCanvas* mCanvas;

// ui
QGridLayout* mLayout;
QLabel* mMaximumScaleIconLabel;
QLabel* mMinimumScaleIconLabel;
QPushButton* mMaximumScaleSetCurrentPushButton;
QPushButton* mMinimumScaleSetCurrentPushButton;
QgsScaleComboBox* mMaximumScaleComboBox;
QgsScaleComboBox* mMinimumScaleComboBox;
};

#endif // QGSSCALERANGEWIDGET_H
14 changes: 8 additions & 6 deletions src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,9 @@ QgsRendererRulePropsDialog::QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::
if ( mRule->dependsOnScale() )
{
groupScale->setChecked( true );
spinMinScale->setValue( rule->scaleMinDenom() );
spinMaxScale->setValue( rule->scaleMaxDenom() );
// caution: rule uses scale denom, scale widget uses true scales
mScaleRangeWidget->setMaximumScale( 1.0 / rule->scaleMinDenom() );
mScaleRangeWidget->setMinimumScale( 1.0 / rule->scaleMaxDenom() );
}

if ( mRule->symbol() )
Expand Down Expand Up @@ -655,8 +656,9 @@ void QgsRendererRulePropsDialog::accept()
mRule->setFilterExpression( editFilter->text() );
mRule->setLabel( editLabel->text() );
mRule->setDescription( editDescription->text() );
mRule->setScaleMinDenom( groupScale->isChecked() ? spinMinScale->value() : 0 );
mRule->setScaleMaxDenom( groupScale->isChecked() ? spinMaxScale->value() : 0 );
// caution: rule uses scale denom, scale widget uses true scales
mRule->setScaleMinDenom( groupScale->isChecked() ? mScaleRangeWidget->minimumScaleDenom() : 0 );
mRule->setScaleMaxDenom( groupScale->isChecked() ? mScaleRangeWidget->maximumScaleDenom() : 0 );
mRule->setSymbol( groupSymbol->isChecked() ? mSymbol->clone() : NULL );

QDialog::accept();
Expand Down Expand Up @@ -723,8 +725,8 @@ QVariant QgsRuleBasedRendererV2Model::data( const QModelIndex &index, int role )
{
return rule->filterExpression().isEmpty() ? tr( "(no filter)" ) : rule->filterExpression();
}
case 2: return rule->dependsOnScale() ? _formatScale( rule->scaleMinDenom() ) : QVariant();
case 3: return rule->dependsOnScale() ? _formatScale( rule->scaleMaxDenom() ) : QVariant();
case 2: return rule->dependsOnScale() ? _formatScale( rule->scaleMaxDenom() ) : QVariant();
case 3: return rule->dependsOnScale() ? _formatScale( rule->scaleMinDenom() ) : QVariant();
case 4:
if ( mFeatureCountMap.count( rule ) == 1 )
{
Expand Down
209 changes: 47 additions & 162 deletions src/ui/qgsrasterlayerpropertiesbase.ui

Large diffs are not rendered by default.

71 changes: 14 additions & 57 deletions src/ui/qgsrendererrulepropsdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>558</width>
<height>298</height>
<width>489</width>
<height>261</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -88,60 +88,12 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Min. scale</string>
<widget class="QgsScaleRangeWidget" name="mScaleRangeWidget">
<property name="toolTip">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinMinScale">
<property name="prefix">
<string>1 : </string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
<property name="singleStep">
<number>1000</number>
</property>
<property name="value">
<number>1000</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Max. scale</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinMaxScale">
<property name="prefix">
<string>1 : </string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
<property name="singleStep">
<number>1000</number>
</property>
<property name="value">
<number>1000</number>
<property name="whatsThis">
<string/>
</property>
</widget>
</item>
Expand Down Expand Up @@ -176,15 +128,20 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsScaleRangeWidget</class>
<extends>QWidget</extends>
<header>qgsscalerangewidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>editLabel</tabstop>
<tabstop>editFilter</tabstop>
<tabstop>btnExpressionBuilder</tabstop>
<tabstop>btnTestFilter</tabstop>
<tabstop>editDescription</tabstop>
<tabstop>groupScale</tabstop>
<tabstop>spinMinScale</tabstop>
<tabstop>spinMaxScale</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
Expand Down
248 changes: 63 additions & 185 deletions src/ui/qgsvectorlayerpropertiesbase.ui

Large diffs are not rendered by default.