Skip to content

Commit 2cf3e7c

Browse files
committedMay 12, 2014
custom widgets for Qt Designer, QgsScaleVisibilityGroupBox plugin
1 parent 156dc55 commit 2cf3e7c

16 files changed

+904
-218
lines changed
 

‎CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ 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+
SET (WITH_CUSTOM_WIDGETS FALSE CACHE BOOL "Determines whether QGIS custom widgets for Qt Designer should be built")
50+
4951
# build our version of astyle
5052
SET (WITH_ASTYLE FALSE CACHE BOOL "If you plan to contribute you should reindent with scripts/prepare-commit.sh (using 'our' astyle)")
5153

@@ -229,10 +231,13 @@ SET(QT_USE_QTNETWORK 1)
229231
SET(QT_USE_QTSVG 1)
230232
SET(QT_USE_QTSQL 1)
231233
SET(QT_USE_QTWEBKIT 1)
234+
IF (WITH_CUSTOM_WIDGETS)
235+
SET(QT_USE_QTDESIGNER 1)
236+
ENDIF (WITH_CUSTOM_WIDGETS)
232237

233-
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)
238+
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))
234239
MESSAGE(SEND_ERROR "Some Qt4 modules haven't been found!")
235-
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)
240+
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))
236241

237242
IF (WITH_QTMOBILITY)
238243
FIND_PACKAGE(QtMobility 1.1.0)
@@ -285,6 +290,12 @@ ENDIF (ENABLE_TESTS)
285290

286291
INCLUDE( ${QT_USE_FILE} )
287292

293+
IF (WITH_CUSTOM_WIDGETS)
294+
ADD_DEFINITIONS(-DQT_PLUGIN)
295+
ADD_DEFINITIONS(-DQT_NO_DEBUG)
296+
ADD_DEFINITIONS(-DQT_SHARED)
297+
ENDIF (WITH_CUSTOM_WIDGETS)
298+
288299
# Disable automatic conversion from QString to ASCII 8-bit strings (char *)
289300
# (Keeps code compatible with Qt/Mac/64bit)
290301
ADD_DEFINITIONS(-DQT_NO_CAST_TO_ASCII)
@@ -506,6 +517,7 @@ ADD_DEFINITIONS("-DCORE_EXPORT=${DLLIMPORT}")
506517
ADD_DEFINITIONS("-DGUI_EXPORT=${DLLIMPORT}")
507518
ADD_DEFINITIONS("-DPYTHON_EXPORT=${DLLIMPORT}")
508519
ADD_DEFINITIONS("-DANALYSIS_EXPORT=${DLLIMPORT}")
520+
ADD_DEFINITIONS("-DCUSTOMWIDGETS_EXPORT=${DLLIMPORT}")
509521
ADD_DEFINITIONS("-DAPP_EXPORT=${DLLIMPORT}")
510522

511523
#############################################################
@@ -533,6 +545,7 @@ SET (QGIS_LIBEXEC_DIR ${QGIS_LIBEXEC_SUBDIR})
533545
SET (QGIS_DATA_DIR ${QGIS_DATA_SUBDIR})
534546
SET (QGIS_PLUGIN_DIR ${QGIS_PLUGIN_SUBDIR})
535547
SET (QGIS_INCLUDE_DIR ${QGIS_INCLUDE_SUBDIR})
548+
SET (QGIS_CUSTOMWIDGETS_DIR ${QT_PLUGINS_DIR}/designer)
536549

537550
# set the default locations where the targets (executables, libraries) will land when compiled
538551
# this is to allow running qgis from the source tree without having to actually do a "make install"
@@ -589,7 +602,7 @@ ENDIF (NOT EXISTS QSCINTILLA_VERSION_STR AND EXISTS QSCI_MOD_VERSION_STR)
589602
# installed with app target
590603

591604
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake_templates/qgsconfig.h.in ${CMAKE_BINARY_DIR}/qgsconfig.h)
592-
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
605+
INCLUDE_DIRECTORIES(${QT_INCLUDES} ${CMAKE_BINARY_DIR})
593606

594607
# Added by Jef to prevent python core and gui libs linking to other qgisCore and qgisGui libs
595608
# that may be in the same install prefix

‎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/qgsvectorlayerproperties.cpp

Lines changed: 9 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+
mScaleVisibilityWidget->setFromLayer( layer );
389+
mScaleVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
390+
mScaleVisibilityWidget->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,9 @@ 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+
layer->setMinimumScale( 1.0 / mScaleVisibilityWidget->minimumScale() );
498+
layer->setMaximumScale( 1.0 / mScaleVisibilityWidget->maximumScale() );
507499

508500
// provider-specific options
509501
if ( layer->dataProvider() )
@@ -1110,16 +1102,6 @@ void QgsVectorLayerProperties::enableLabelOptions( bool theFlag )
11101102
labelOptionsFrame->setEnabled( theFlag );
11111103
}
11121104

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-
11231105
void QgsVectorLayerProperties::on_mSimplifyDrawingGroupBox_toggled( bool checked )
11241106
{
11251107
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 "qgsscalevisibilitywidget.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:

‎src/customwidgets/CMakeLists.txt

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
2+
########################################################
3+
# Files
4+
5+
SET (QGIS_CUSTOMWIDGETS_SRCS
6+
qgiscustomwidgets.cpp
7+
qgscollapsiblegroupboxplugin.cpp
8+
qgsscalevisibilitywidgetplugin.cpp
9+
)
10+
11+
SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
12+
qgiscustomwidgets.h
13+
qgscollapsiblegroupboxplugin.h
14+
qgsscalevisibilitywidgetplugin.h
15+
)
16+
17+
QT4_WRAP_CPP(QGIS_CUSTOMWIDGETS_MOC_SRCS ${QGIS_CUSTOMWIDGETS_MOC_HDRS})
18+
19+
IF(UNIX)
20+
SET_SOURCE_FILES_PROPERTIES(${QGIS_CUSTOMWIDGETS_MOC_SRCS} PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations" )
21+
ENDIF(UNIX)
22+
23+
SET(QGIS_CUSTOMWIDGETS_HDRS
24+
qgiscustomwidgets.h
25+
qgscollapsiblegroupboxplugin.h
26+
qgsscalevisibilitywidgetplugin.h
27+
)
28+
29+
SET(QGIS_CUSTOMWIDGETS_UI_HDRS
30+
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsscalevisibilitygroupbox.h
31+
)
32+
33+
INCLUDE_DIRECTORIES(
34+
${CMAKE_CURRENT_SOURCE_DIR}
35+
${CMAKE_CURRENT_SOURCE_DIR}/../core/
36+
${CMAKE_CURRENT_SOURCE_DIR}/../gui/
37+
${CMAKE_CURRENT_BINARY_DIR}/../ui
38+
)
39+
40+
IF (WIN32)
41+
IF (MSVC)
42+
ADD_DEFINITIONS("-DCUSTOMWIDGETS_EXPORT=${DLLEXPORT}")
43+
ELSE (MSVC)
44+
ADD_DEFINITIONS("-UCUSTOMWIDGETS_EXPORT \"-DCUSTOMWIDGETS_EXPORT=${DLLEXPORT}\"")
45+
ENDIF (MSVC)
46+
ENDIF (WIN32)
47+
48+
49+
#############################################################
50+
# qgis_customwidgets library
51+
52+
ADD_LIBRARY(qgis_customwidgets SHARED ${QGIS_CUSTOMWIDGETS_SRCS} ${QGIS_CUSTOMWIDGETS_MOC_SRCS} ${QGIS_CUSTOMWIDGETS_HDRS})
53+
54+
IF(NOT APPLE)
55+
INSTALL(FILES ${QGIS_CUSTOMWIDGETS_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
56+
ELSE(NOT APPLE)
57+
SET_TARGET_PROPERTIES(qgis_customwidgets PROPERTIES
58+
# no moc headers, messes up PROPERTIES syntax
59+
CLEAN_DIRECT_OUTPUT 1
60+
FRAMEWORK 1
61+
FRAMEWORK_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}"
62+
MACOSX_FRAMEWORK_INFO_PLIST "${CMAKE_SOURCE_DIR}/mac/framework.info.plist.in"
63+
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${COMPLETE_VERSION}
64+
MACOSX_FRAMEWORK_IDENTIFIER org.qgis.qgis2_customwidgets
65+
BUILD_WITH_INSTALL_RPATH TRUE
66+
PUBLIC_HEADER "${QGIS_CUSTOMWIDGETS_HDRS}"
67+
LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}"
68+
)
69+
ENDIF(NOT APPLE)
70+
71+
#generate unversioned libs for android
72+
IF (NOT ANDROID)
73+
SET_TARGET_PROPERTIES(qgis_customwidgets PROPERTIES
74+
VERSION ${COMPLETE_VERSION}
75+
SOVERSION ${COMPLETE_VERSION}
76+
)
77+
ENDIF (NOT ANDROID)
78+
79+
# make sure that UI files will be processed first
80+
ADD_DEPENDENCIES(qgis_customwidgets ui)
81+
82+
TARGET_LINK_LIBRARIES(qgis_customwidgets qgis_gui)
83+
84+
85+
# install
86+
87+
INSTALL(TARGETS qgis_customwidgets
88+
LIBRARY DESTINATION ${QGIS_CUSTOMWIDGETS_DIR}
89+
PUBLIC_HEADER DESTINATION ${QGIS_INCLUDE_DIR})
90+
91+
# ui headers to install, don't exist at target definition time, install manually
92+
IF (APPLE)
93+
INSTALL(FILES ${QGIS_CUSTOMWIDGETS_UI_HDRS} DESTINATION ${QGIS_FW_SUBDIR}/qgis_gui.framework/Headers)
94+
ELSE (APPLE)
95+
INSTALL(FILES ${QGIS_CUSTOMWIDGETS_UI_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
96+
ENDIF (APPLE)
97+
98+
# Mac dev frameworks
99+
#IF (APPLE AND QGIS_MACAPP_INSTALL_DEV)
100+
# INSTALL(TARGETS qgis_customwidgets FRAMEWORK DESTINATION ${QGIS_MACAPP_DEV_PREFIX})
101+
# INSTALL(CODE "EXECUTE_PROCESS(COMMAND install_name_tool -id \"${QGIS_MACAPP_DEV_PREFIX}/qgis_customwidgets.framework/Versions/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}/qgis_customwidgets\" \"$ENV{DESTDIR}${QGIS_MACAPP_DEV_PREFIX}/qgis_customwidgets.framework/qgis_customwidgets\")")
102+
# INSTALL(CODE "EXECUTE_PROCESS(COMMAND install_name_tool -change \"${CMAKE_INSTALL_NAME_DIR}/qgis_core.framework/Versions/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}/qgis_core\" \"${QGIS_MACAPP_DEV_PREFIX}/qgis_core.framework/Versions/${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}/qgis_core\" \"$ENV{DESTDIR}${QGIS_MACAPP_DEV_PREFIX}/qgis_customwidgets.framework/qgis_customwidgets\")")
103+
#ENDIF (APPLE AND QGIS_MACAPP_INSTALL_DEV)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/***************************************************************************
2+
qgscustomwidgets.cpp
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qplugin.h"
17+
18+
#include "qgiscustomwidgets.h"
19+
20+
#include "qgscollapsiblegroupboxplugin.h"
21+
#include "qgsscalevisibilitywidgetplugin.h"
22+
23+
24+
QgisCustomWidgets::QgisCustomWidgets( QObject *parent )
25+
: QObject( parent )
26+
{
27+
mWidgets.append( new QgsCollapsibleGroupBoxPlugin );
28+
mWidgets.append( new QgsScaleVisibilityWidgetPlugin );
29+
}
30+
31+
QList<QDesignerCustomWidgetInterface*> QgisCustomWidgets::customWidgets() const
32+
{
33+
return mWidgets;
34+
}
35+
36+
Q_EXPORT_PLUGIN2( customwidgetsplugin, QgisCustomWidgets )

‎src/customwidgets/qgiscustomwidgets.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/***************************************************************************
2+
qgscustomwidgets.h
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGISCUSTOMWIDGETS_H
17+
#define QGISCUSTOMWIDGETS_H
18+
19+
#include <QDesignerCustomWidgetCollectionInterface>
20+
#include <qplugin.h>
21+
22+
class QgisCustomWidgets : public QObject, public QDesignerCustomWidgetCollectionInterface
23+
{
24+
Q_OBJECT
25+
Q_INTERFACES( QDesignerCustomWidgetCollectionInterface )
26+
27+
public:
28+
explicit QgisCustomWidgets( QObject *parent = 0 );
29+
30+
virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;
31+
32+
static QString groupName() {return "QGIS custom widgets";}
33+
34+
private:
35+
QList<QDesignerCustomWidgetInterface*> mWidgets;
36+
};
37+
38+
#endif // QGISCUSTOMWIDGETS_H
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/***************************************************************************
2+
qgscollapsiblegroupboxplugin.cpp
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgiscustomwidgets.h"
17+
#include "qgscollapsiblegroupbox.h"
18+
#include "qgscollapsiblegroupboxplugin.h"
19+
20+
21+
QgsCollapsibleGroupBoxPlugin::QgsCollapsibleGroupBoxPlugin( QObject *parent )
22+
: QObject( parent )
23+
, mInitialized( false )
24+
{
25+
}
26+
27+
28+
QString QgsCollapsibleGroupBoxPlugin::name() const
29+
{
30+
return "QgsCollapsibleGroupBox";
31+
}
32+
33+
QString QgsCollapsibleGroupBoxPlugin::group() const
34+
{
35+
return QgisCustomWidgets::groupName();
36+
}
37+
38+
QString QgsCollapsibleGroupBoxPlugin::includeFile() const
39+
{
40+
return "qgscollapsiblegroupbox.h";
41+
}
42+
43+
QIcon QgsCollapsibleGroupBoxPlugin::icon() const
44+
{
45+
return QIcon();
46+
}
47+
48+
bool QgsCollapsibleGroupBoxPlugin::isContainer() const
49+
{
50+
return true;
51+
}
52+
53+
QWidget *QgsCollapsibleGroupBoxPlugin::createWidget( QWidget *parent )
54+
{
55+
return new QgsCollapsibleGroupBox( parent );
56+
}
57+
58+
bool QgsCollapsibleGroupBoxPlugin::isInitialized() const
59+
{
60+
return mInitialized;
61+
}
62+
63+
void QgsCollapsibleGroupBoxPlugin::initialize( QDesignerFormEditorInterface *core )
64+
{
65+
Q_UNUSED( core );
66+
if ( mInitialized )
67+
return;
68+
mInitialized = true;
69+
}
70+
71+
72+
QString QgsCollapsibleGroupBoxPlugin::toolTip() const
73+
{
74+
return "A collapsible group box";
75+
}
76+
77+
QString QgsCollapsibleGroupBoxPlugin::whatsThis() const
78+
{
79+
return "A collapsible group box with save state capability";
80+
}
81+
82+
QString QgsCollapsibleGroupBoxPlugin::domXml() const
83+
{
84+
return QString( "<ui language=\"c++\">\n"
85+
" <widget class=\"%1\" name=\"mGroupBox\">\n"
86+
" <property name=\"geometry\">\n"
87+
" <rect>\n"
88+
" <x>0</x>\n"
89+
" <y>0</y>\n"
90+
" <width>300</width>\n"
91+
" <height>100</height>\n"
92+
" </rect>\n"
93+
" </property>\n"
94+
" <property name=\"toolTip\" >\n"
95+
" <string>%2</string>\n"
96+
" </property>\n"
97+
" <property name=\"whatsThis\" >\n"
98+
" <string>%3.</string>\n"
99+
" </property>\n"
100+
" </widget>\n"
101+
"</ui>\n" )
102+
.arg( name() )
103+
.arg( toolTip() )
104+
.arg( whatsThis() );
105+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/***************************************************************************
2+
qgscollapsiblegroupboxplugin.h
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSCOLLAPSIBLEGROUPBOXPLUGIN_H
17+
#define QGSCOLLAPSIBLEGROUPBOXPLUGIN_H
18+
19+
#include <QDesignerCustomWidgetInterface>
20+
21+
class CUSTOMWIDGETS_EXPORT QgsCollapsibleGroupBoxPlugin : public QObject, public QDesignerCustomWidgetInterface
22+
{
23+
Q_OBJECT
24+
Q_INTERFACES( QDesignerCustomWidgetInterface )
25+
26+
public:
27+
explicit QgsCollapsibleGroupBoxPlugin( QObject *parent = 0 );
28+
29+
private:
30+
bool mInitialized;
31+
32+
// QDesignerCustomWidgetInterface interface
33+
public:
34+
QString name() const;
35+
QString group() const;
36+
QString includeFile() const;
37+
QIcon icon() const;
38+
bool isContainer() const;
39+
QWidget *createWidget( QWidget *parent );
40+
bool isInitialized() const;
41+
void initialize( QDesignerFormEditorInterface *core );
42+
QString toolTip() const;
43+
QString whatsThis() const;
44+
QString domXml() const;
45+
};
46+
#endif // QGSCOLLAPSIBLEGROUPBOXPLUGIN_H
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/***************************************************************************
2+
qgsscalevisibilitywidgetplugin.cpp
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgiscustomwidgets.h"
17+
#include "qgsscalevisibilitywidgetplugin.h"
18+
#include "qgsscalevisibilitywidget.h"
19+
20+
21+
QgsScaleVisibilityWidgetPlugin::QgsScaleVisibilityWidgetPlugin( QObject *parent )
22+
: QObject( parent )
23+
, mInitialized( false )
24+
{
25+
}
26+
27+
28+
QString QgsScaleVisibilityWidgetPlugin::name() const
29+
{
30+
return "QgsScaleVisibilityWidget";
31+
}
32+
33+
QString QgsScaleVisibilityWidgetPlugin::group() const
34+
{
35+
return QgisCustomWidgets::groupName();
36+
}
37+
38+
QString QgsScaleVisibilityWidgetPlugin::includeFile() const
39+
{
40+
return "qgsscalevisibilitywidget.h";
41+
}
42+
43+
QIcon QgsScaleVisibilityWidgetPlugin::icon() const
44+
{
45+
return QIcon();
46+
}
47+
48+
bool QgsScaleVisibilityWidgetPlugin::isContainer() const
49+
{
50+
return false;
51+
}
52+
53+
QWidget *QgsScaleVisibilityWidgetPlugin::createWidget( QWidget *parent )
54+
{
55+
return new QgsScaleVisibilityWidget( parent );
56+
}
57+
58+
bool QgsScaleVisibilityWidgetPlugin::isInitialized() const
59+
{
60+
return mInitialized;
61+
}
62+
63+
void QgsScaleVisibilityWidgetPlugin::initialize( QDesignerFormEditorInterface *core )
64+
{
65+
Q_UNUSED( core );
66+
if ( mInitialized )
67+
return;
68+
mInitialized = true;
69+
}
70+
71+
72+
QString QgsScaleVisibilityWidgetPlugin::toolTip() const
73+
{
74+
return "A widget to define the scale visibility";
75+
}
76+
77+
QString QgsScaleVisibilityWidgetPlugin::whatsThis() const
78+
{
79+
return "A widget to define the scale visibility";
80+
}
81+
82+
QString QgsScaleVisibilityWidgetPlugin::domXml() const
83+
{
84+
return QString( "<ui language=\"c++\">\n"
85+
" <widget class=\"%1\" name=\"mScaleVisibilityWidget\">\n"
86+
" <property name=\"geometry\">\n"
87+
" <rect>\n"
88+
" <x>0</x>\n"
89+
" <y>0</y>\n"
90+
" <width>300</width>\n"
91+
" <height>100</height>\n"
92+
" </rect>\n"
93+
" </property>\n"
94+
" <property name=\"toolTip\" >\n"
95+
" <string>%2</string>\n"
96+
" </property>\n"
97+
" <property name=\"whatsThis\" >\n"
98+
" <string>%3.</string>\n"
99+
" </property>\n"
100+
" </widget>\n"
101+
"</ui>\n" )
102+
.arg( name() )
103+
.arg( toolTip() )
104+
.arg( whatsThis() );
105+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/***************************************************************************
2+
qgsscalevisibilitywidgetplugin.h
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSSCALEVISIBILITYWIDGETPLUGIN_H
17+
#define QGSSCALEVISIBILITYWIDGETPLUGIN_H
18+
19+
#include <QDesignerCustomWidgetInterface>
20+
21+
class CUSTOMWIDGETS_EXPORT QgsScaleVisibilityWidgetPlugin : public QObject, public QDesignerCustomWidgetInterface
22+
{
23+
Q_OBJECT
24+
Q_INTERFACES( QDesignerCustomWidgetInterface )
25+
26+
public:
27+
explicit QgsScaleVisibilityWidgetPlugin( QObject *parent = 0 );
28+
29+
private:
30+
bool mInitialized;
31+
32+
// QDesignerCustomWidgetInterface interface
33+
public:
34+
QString name() const;
35+
QString group() const;
36+
QString includeFile() const;
37+
QIcon icon() const;
38+
bool isContainer() const;
39+
QWidget *createWidget( QWidget *parent );
40+
bool isInitialized() const;
41+
void initialize( QDesignerFormEditorInterface *core );
42+
QString toolTip() const;
43+
QString whatsThis() const;
44+
QString domXml() const;
45+
};
46+
#endif // QGSSCALEVISIBILITYWIDGETPLUGIN_H

‎src/gui/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ qgsrelationeditor.cpp
138138
qgsrelationmanagerdialog.cpp
139139
qgsrubberband.cpp
140140
qgsscalecombobox.cpp
141+
qgsscalevisibilitywidget.cpp
141142
qgssearchquerybuilder.cpp
142143
qgssublayersdialog.cpp
143144
qgssvgannotationitem.cpp
@@ -276,6 +277,7 @@ qgsrelationadddlg.h
276277
qgsrelationeditor.h
277278
qgsrelationmanagerdialog.h
278279
qgsscalecombobox.h
280+
qgsscalevisibilitywidget.h
279281
qgssearchquerybuilder.h
280282
qgssublayersdialog.h
281283
qgsunitselectionwidget.h
@@ -340,6 +342,7 @@ qgsprojectionselector.h
340342
qgsrelationeditor.h
341343
qgsrubberband.h
342344
qgsscalecombobox.h
345+
qgsscalevisibilitywidget.h
343346
qgssearchquerybuilder.h
344347
qgssublayersdialog.h
345348
qgsvectorlayertools.h

‎src/gui/qgsscalevisibilitywidget.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/***************************************************************************
2+
qgsscalevisibilitywidget.cpp
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgsscalevisibilitywidget.h"
17+
#include "qgsapplication.h"
18+
#include "qgsproject.h"
19+
20+
QgsScaleVisibilityWidget::QgsScaleVisibilityWidget( QWidget *parent )
21+
: QWidget( parent )
22+
, mCanvas( 0 )
23+
{
24+
setupUi( this );
25+
26+
mMaximumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomIn.svg" ) );
27+
mMinimumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomOut.svg" ) );
28+
29+
mMinimumScaleSetCurrentPushButton->hide();
30+
mMaximumScaleSetCurrentPushButton->hide();
31+
}
32+
33+
QgsScaleVisibilityWidget::~QgsScaleVisibilityWidget()
34+
{
35+
}
36+
37+
void QgsScaleVisibilityWidget::showEvent( QShowEvent * )
38+
{
39+
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
40+
if ( projectScales )
41+
{
42+
QStringList scalesList = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
43+
mMinimumScaleComboBox->updateScales( scalesList );
44+
mMaximumScaleComboBox->updateScales( scalesList );
45+
}
46+
}
47+
48+
void QgsScaleVisibilityWidget::setMapCanvas( QgsMapCanvas *mapCanvas )
49+
{
50+
if ( !mapCanvas )
51+
return;
52+
53+
mCanvas = mapCanvas;
54+
mMinimumScaleSetCurrentPushButton->show();
55+
mMaximumScaleSetCurrentPushButton->show();
56+
}
57+
58+
void QgsScaleVisibilityWidget::setMinimumScale( double scale )
59+
{
60+
mMinimumScaleComboBox->setScale( scale );
61+
}
62+
63+
double QgsScaleVisibilityWidget::minimumScale()
64+
{
65+
return mMinimumScaleComboBox->scale();
66+
}
67+
68+
void QgsScaleVisibilityWidget::setMaximumScale( double scale )
69+
{
70+
mMaximumScaleComboBox->setScale( scale );
71+
}
72+
73+
double QgsScaleVisibilityWidget::maximumScale()
74+
{
75+
return mMaximumScaleComboBox->scale();
76+
}
77+
78+
void QgsScaleVisibilityWidget::on_mMinimumScaleSetCurrentPushButton_clicked()
79+
{
80+
mMinimumScaleComboBox->setScale( 1.0 / mCanvas->mapSettings().scale() );
81+
}
82+
83+
void QgsScaleVisibilityWidget::on_mMaximumScaleSetCurrentPushButton_clicked()
84+
{
85+
mMaximumScaleComboBox->setScale( 1.0 / mCanvas->mapSettings().scale() );
86+
}
87+
88+
void QgsScaleVisibilityWidget::setFromLayer( QgsMapLayer *layer )
89+
{
90+
mMinimumScaleComboBox->setScale( 1.0 / layer->minimumScale() );
91+
mMaximumScaleComboBox->setScale( 1.0 / layer->maximumScale() );
92+
}

‎src/gui/qgsscalevisibilitywidget.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/***************************************************************************
2+
qgsscalevisibilitywidget.h
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSSCALEVISIBILITYWIDGET_H
17+
#define QGSSCALEVISIBILITYWIDGET_H
18+
19+
#include "ui_qgsscalevisibilitywidget.h"
20+
#include "qgscollapsiblegroupbox.h"
21+
#include "qgsmaplayer.h"
22+
#include "qgsmapcanvas.h"
23+
24+
25+
class GUI_EXPORT QgsScaleVisibilityWidget : public QWidget, private Ui::QgsScaleVisibilityWidget
26+
{
27+
Q_OBJECT
28+
29+
public:
30+
explicit QgsScaleVisibilityWidget( QWidget *parent = 0 );
31+
~QgsScaleVisibilityWidget();
32+
33+
void showEvent( QShowEvent * );
34+
35+
//! set the map canvas which will be used for the current scale buttons
36+
/**
37+
* @brief setMapCanvas set the map canvas which will be used for the current scale buttons
38+
* if not set, the buttons are hidden.
39+
*/
40+
void setMapCanvas( QgsMapCanvas* mapCanvas );
41+
42+
public slots:
43+
void setMinimumScale( double scale );
44+
double minimumScale();
45+
46+
void setMaximumScale( double scale );
47+
double maximumScale();
48+
49+
void setFromLayer( QgsMapLayer* layer );
50+
51+
private slots:
52+
void on_mMinimumScaleSetCurrentPushButton_clicked();
53+
void on_mMaximumScaleSetCurrentPushButton_clicked();
54+
55+
private:
56+
//! pointer to the map canvas used for current buttons.
57+
QgsMapCanvas* mCanvas;
58+
};
59+
60+
#endif // QGSSCALEVISIBILITYWIDGET_H

‎src/ui/qgsscalevisibilitywidget.ui

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsScaleVisibilityWidget</class>
4+
<widget class="QWidget" name="QgsScaleVisibilityWidget">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>423</width>
10+
<height>87</height>
11+
</rect>
12+
</property>
13+
<property name="sizePolicy">
14+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
15+
<horstretch>0</horstretch>
16+
<verstretch>0</verstretch>
17+
</sizepolicy>
18+
</property>
19+
<property name="windowTitle">
20+
<string>Form</string>
21+
</property>
22+
<layout class="QGridLayout" name="gridLayout_2">
23+
<item row="0" column="0">
24+
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,3,0,0,3">
25+
<item row="0" column="5">
26+
<widget class="QgsScaleComboBox" name="mMaximumScaleComboBox">
27+
<property name="sizePolicy">
28+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
29+
<horstretch>0</horstretch>
30+
<verstretch>0</verstretch>
31+
</sizepolicy>
32+
</property>
33+
</widget>
34+
</item>
35+
<item row="0" column="3">
36+
<widget class="QLabel" name="textLabel1_2_2_2">
37+
<property name="toolTip">
38+
<string>Minimum scale, i.e. maximum scale denominator. This limit is exclusive, that means the layer will not be displayed on this scale.</string>
39+
</property>
40+
<property name="layoutDirection">
41+
<enum>Qt::LeftToRight</enum>
42+
</property>
43+
<property name="text">
44+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:0.75em;&quot;&gt;Minimum&lt;br&gt;(exclusive)&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
45+
</property>
46+
</widget>
47+
</item>
48+
<item row="1" column="5">
49+
<widget class="QPushButton" name="mMaximumScaleSetCurrentPushButton">
50+
<property name="sizePolicy">
51+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
52+
<horstretch>0</horstretch>
53+
<verstretch>0</verstretch>
54+
</sizepolicy>
55+
</property>
56+
<property name="text">
57+
<string>Current</string>
58+
</property>
59+
</widget>
60+
</item>
61+
<item row="0" column="2">
62+
<widget class="QgsScaleComboBox" name="mMinimumScaleComboBox">
63+
<property name="sizePolicy">
64+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
65+
<horstretch>0</horstretch>
66+
<verstretch>0</verstretch>
67+
</sizepolicy>
68+
</property>
69+
<property name="minimumSize">
70+
<size>
71+
<width>100</width>
72+
<height>0</height>
73+
</size>
74+
</property>
75+
</widget>
76+
</item>
77+
<item row="0" column="4">
78+
<widget class="QLabel" name="mMinimumScaleIconLabel">
79+
<property name="sizePolicy">
80+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
81+
<horstretch>0</horstretch>
82+
<verstretch>0</verstretch>
83+
</sizepolicy>
84+
</property>
85+
<property name="minimumSize">
86+
<size>
87+
<width>0</width>
88+
<height>0</height>
89+
</size>
90+
</property>
91+
<property name="maximumSize">
92+
<size>
93+
<width>22</width>
94+
<height>22</height>
95+
</size>
96+
</property>
97+
<property name="text">
98+
<string/>
99+
</property>
100+
<property name="pixmap">
101+
<pixmap resource="../../images/images.qrc">:/images/themes/default/mActionZoomOut.svg</pixmap>
102+
</property>
103+
<property name="scaledContents">
104+
<bool>true</bool>
105+
</property>
106+
</widget>
107+
</item>
108+
<item row="0" column="1">
109+
<widget class="QLabel" name="mMaximumScaleIconLabel">
110+
<property name="sizePolicy">
111+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
112+
<horstretch>0</horstretch>
113+
<verstretch>0</verstretch>
114+
</sizepolicy>
115+
</property>
116+
<property name="minimumSize">
117+
<size>
118+
<width>0</width>
119+
<height>0</height>
120+
</size>
121+
</property>
122+
<property name="maximumSize">
123+
<size>
124+
<width>22</width>
125+
<height>22</height>
126+
</size>
127+
</property>
128+
<property name="text">
129+
<string/>
130+
</property>
131+
<property name="pixmap">
132+
<pixmap resource="../../images/images.qrc">:/images/themes/default/mActionZoomIn.svg</pixmap>
133+
</property>
134+
<property name="scaledContents">
135+
<bool>true</bool>
136+
</property>
137+
</widget>
138+
</item>
139+
<item row="1" column="2">
140+
<widget class="QPushButton" name="mMinimumScaleSetCurrentPushButton">
141+
<property name="sizePolicy">
142+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
143+
<horstretch>0</horstretch>
144+
<verstretch>0</verstretch>
145+
</sizepolicy>
146+
</property>
147+
<property name="text">
148+
<string>Current</string>
149+
</property>
150+
</widget>
151+
</item>
152+
<item row="0" column="0">
153+
<widget class="QLabel" name="textLabel1_3">
154+
<property name="toolTip">
155+
<string>Maximum scale, i.e. minimum scale denominator. This limit is inclusive, that means the layer will be displayed on this scale.</string>
156+
</property>
157+
<property name="text">
158+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:0.75em;&quot;&gt;Maximum&lt;br&gt;(inclusive)&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
159+
</property>
160+
</widget>
161+
</item>
162+
</layout>
163+
</item>
164+
</layout>
165+
</widget>
166+
<customwidgets>
167+
<customwidget>
168+
<class>QgsScaleComboBox</class>
169+
<extends>QComboBox</extends>
170+
<header>qgsscalecombobox.h</header>
171+
</customwidget>
172+
</customwidgets>
173+
<resources>
174+
<include location="../../images/images.qrc"/>
175+
</resources>
176+
<connections/>
177+
</ui>

‎src/ui/qgsvectorlayerpropertiesbase.ui

Lines changed: 63 additions & 185 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.