Skip to content

Commit eade998

Browse files
committedJan 23, 2017
Start on GUI for properties
1 parent 4018863 commit eade998

File tree

6 files changed

+1527
-158
lines changed

6 files changed

+1527
-158
lines changed
 

‎src/app/qgsdiagramproperties.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
100100
mDiagramAttributesTreeWidget->setItemDelegateForColumn( ColumnAttributeExpression, new EditBlockerDelegate( this ) );
101101
mDiagramAttributesTreeWidget->setItemDelegateForColumn( ColumnColor, new EditBlockerDelegate( this ) );
102102

103-
connect( mFixedSizeRadio, SIGNAL( toggled( bool ) ), this, SLOT( scalingTypeChanged() ) );
104-
connect( mAttributeBasedScalingRadio, SIGNAL( toggled( bool ) ), this, SLOT( scalingTypeChanged() ) );
103+
connect( mFixedSizeRadio, &QRadioButton::toggled, this, &QgsDiagramProperties::scalingTypeChanged );
104+
connect( mAttributeBasedScalingRadio, &QRadioButton::toggled, this, &QgsDiagramProperties::scalingTypeChanged );
105105

106106
mDiagramUnitComboBox->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels
107107
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
@@ -382,6 +382,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
382382
chkLineOrientationDependent->setChecked( true );
383383

384384
mShowAllCheckBox->setChecked( dls->showAllDiagrams() );
385+
386+
mProperties = dls->properties();
385387
}
386388

387389
if ( dr->diagram() )
@@ -400,11 +402,32 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
400402
mDiagramTypeComboBox->setCurrentIndex( mDiagramTypeComboBox->findData( DIAGRAM_NAME_PIE ) );
401403
}
402404
}
403-
} // if ( !dr )
405+
}
404406

405-
connect( mAddAttributeExpression, SIGNAL( clicked() ), this, SLOT( showAddAttributeExpressionDialog() ) );
406-
connect( mTransparencySlider, SIGNAL( valueChanged( int ) ), mTransparencySpinBox, SLOT( setValue( int ) ) );
407-
connect( mTransparencySpinBox, SIGNAL( valueChanged( int ) ), mTransparencySlider, SLOT( setValue( int ) ) );
407+
connect( mAddAttributeExpression, &QPushButton::clicked, this, &QgsDiagramProperties::showAddAttributeExpressionDialog );
408+
connect( mTransparencySlider, &QSlider::valueChanged, mTransparencySpinBox, &QgsSpinBox::setValue );
409+
connect( mTransparencySpinBox, static_cast<void (QgsSpinBox::*)(int)>(&QSpinBox::valueChanged), mTransparencySlider, &QSlider::setValue );
410+
411+
registerDataDefinedButton( mBackgroundColorDDBtn, QgsDiagramLayerSettings::BackgroundColor,
412+
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::colorAlphaDesc() );
413+
registerDataDefinedButton( mLineColorDDBtn, QgsDiagramLayerSettings::OutlineColor,
414+
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::colorAlphaDesc() );
415+
registerDataDefinedButton( mLineWidthDDBtn, QgsDiagramLayerSettings::OutlineWidth,
416+
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::doublePosDesc() );
417+
registerDataDefinedButton( mCoordXDDBtn, QgsDiagramLayerSettings::PositionX,
418+
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::doubleDesc() );
419+
registerDataDefinedButton( mCoordYDDBtn, QgsDiagramLayerSettings::PositionY,
420+
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::doubleDesc() );
421+
registerDataDefinedButton( mPriorityDDBtn, QgsDiagramLayerSettings::Priority,
422+
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::doubleDesc() );
423+
registerDataDefinedButton( mZOrderDDBtn, QgsDiagramLayerSettings::ZIndex,
424+
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::doubleDesc() );
425+
registerDataDefinedButton( mShowDiagramDDBtn, QgsDiagramLayerSettings::Show,
426+
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::doubleDesc() );
427+
registerDataDefinedButton( mAlwaysShowDDBtn, QgsDiagramLayerSettings::AlwaysShow,
428+
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::doubleDesc() );
429+
registerDataDefinedButton( mStartAngleDDBtn, QgsDiagramLayerSettings::StartAngle,
430+
QgsDataDefinedButtonV2::String, QgsDataDefinedButtonV2::doubleDesc() );
408431
}
409432

410433
QgsDiagramProperties::~QgsDiagramProperties()
@@ -414,6 +437,21 @@ QgsDiagramProperties::~QgsDiagramProperties()
414437
settings.setValue( QStringLiteral( "/Windows/Diagrams/Tab" ), mDiagramOptionsListWidget->currentRow() );
415438
}
416439

440+
void QgsDiagramProperties::registerDataDefinedButton( QgsDataDefinedButtonV2 * button, QgsDiagramLayerSettings::Property key, QgsDataDefinedButtonV2::DataType type, const QString & description )
441+
{
442+
button->init( mLayer, mProperties.property( key ), type, description );
443+
button->setProperty( "propertyKey", key );
444+
connect( button, &QgsDataDefinedButtonV2::changed, this, &QgsDiagramProperties::updateProperty );
445+
button->registerExpressionContextGenerator( this );
446+
}
447+
448+
void QgsDiagramProperties::updateProperty()
449+
{
450+
QgsDataDefinedButtonV2* button = qobject_cast<QgsDataDefinedButtonV2*>( sender() );
451+
QgsDiagramLayerSettings::Property key = static_cast< QgsDiagramLayerSettings::Property >( button->property( "propertyKey" ).toInt() );
452+
mProperties.setProperty( key, button->toProperty() );
453+
}
454+
417455
void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( int index )
418456
{
419457
if ( index == 0 )
@@ -794,6 +832,7 @@ void QgsDiagramProperties::apply()
794832
mLayer->setDiagramRenderer( renderer );
795833

796834
QgsDiagramLayerSettings dls;
835+
dls.setProperties( mProperties );
797836
dls.setDistance( mDiagramDistanceSpinBox->value() );
798837
dls.setPriority( mPrioritySlider->value() );
799838
dls.setZIndex( mZIndexSpinBox->value() );

‎src/app/qgsdiagramproperties.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define QGSDIAGRAMPROPERTIES_H
2020

2121
#include <QDialog>
22+
#include "qgsdiagramrenderer.h"
2223
#include <ui_qgsdiagrampropertiesbase.h>
2324
#include <QStyledItemDelegate>
2425
#include "qgis_app.h"
@@ -75,6 +76,8 @@ class APP_EXPORT QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPr
7576

7677
QString showExpressionBuilder( const QString& initialExpression );
7778

79+
QgsPropertyCollection mProperties;
80+
7881
// Keeps track of the diagram type to properly save / restore settings when the diagram type combo box is set to no diagram.
7982
QString mDiagramType;
8083
QScopedPointer< QgsMarkerSymbol > mSizeLegendSymbol;
@@ -83,6 +86,12 @@ class APP_EXPORT QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPr
8386
QgsMapCanvas *mMapCanvas;
8487

8588
QgsExpressionContext createExpressionContext() const override;
89+
90+
void registerDataDefinedButton( QgsDataDefinedButtonV2 *button, QgsDiagramLayerSettings::Property key, QgsDataDefinedButtonV2::DataType type, const QString &description );
91+
92+
private slots:
93+
94+
void updateProperty();
8695
};
8796

8897
class EditBlockerDelegate: public QStyledItemDelegate

‎src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ SET(QGIS_GUI_SRCS
196196
qgscursors.cpp
197197
qgscustomdrophandler.cpp
198198
qgsdatadefinedbutton.cpp
199+
qgsdatadefinedbuttonv2.cpp
199200
qgsdatumtransformdialog.cpp
200201
qgsdetaileditemdata.cpp
201202
qgsdetaileditemdelegate.cpp
@@ -366,6 +367,7 @@ SET(QGIS_GUI_MOC_HDRS
366367
qgsconfigureshortcutsdialog.h
367368
qgscredentialdialog.h
368369
qgsdatadefinedbutton.h
370+
qgsdatadefinedbuttonv2.h
369371
qgsdatumtransformdialog.h
370372
qgsdetaileditemdelegate.h
371373
qgsdetaileditemwidget.h

‎src/gui/qgsdatadefinedbuttonv2.cpp

Lines changed: 781 additions & 0 deletions
Large diffs are not rendered by default.

‎src/gui/qgsdatadefinedbuttonv2.h

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/***************************************************************************
2+
qgsdatadefinedbuttonv2.h
3+
------------------------
4+
Date : March 2016
5+
Copyright : (C) 2016 by Nyall Dawson
6+
Email : nyall dot dawson at gmail dot 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+
#ifndef QGSDATADEFINEDBUTTONV2_H
16+
#define QGSDATADEFINEDBUTTONV2_H
17+
18+
#include "qgis_gui.h"
19+
#include <QDialog>
20+
#include <QFlags>
21+
#include <QMap>
22+
#include <QPointer>
23+
#include <QToolButton>
24+
#include <QScopedPointer>
25+
#include "qgsproperty.h"
26+
#include "qgsexpressioncontext.h"
27+
#include "qgsexpressioncontextgenerator.h"
28+
29+
class QgsVectorLayer;
30+
class QgsDataDefined;
31+
class QgsMapCanvas;
32+
33+
/** \ingroup gui
34+
* \class QgsDataDefinedButtonV2
35+
* A button for defining data source field mappings or expressions.
36+
*/
37+
38+
class GUI_EXPORT QgsDataDefinedButtonV2: public QToolButton
39+
{
40+
Q_OBJECT
41+
Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
42+
43+
public:
44+
45+
//! Valid data types accepted by property
46+
enum DataType
47+
{
48+
String = 1,
49+
Int = 1 << 1,
50+
Double = 1 << 2,
51+
AnyType = String | Int | Double
52+
};
53+
Q_DECLARE_FLAGS( DataTypes, DataType )
54+
55+
/**
56+
* Constructor for QgsDataDefinedButtonV2.
57+
* @param parent parent widget
58+
* @param layer associated vector layer
59+
* @param propertyCollection associated property collection
60+
* @param propertyKey key for corresponding property
61+
* @param dataTypes expected data type for property values
62+
* @param description string description of expected input data
63+
*/
64+
QgsDataDefinedButtonV2( QWidget* parent = nullptr,
65+
const QgsVectorLayer* layer = nullptr,
66+
const QgsAbstractProperty* property = nullptr,
67+
const QgsDataDefinedButtonV2::DataTypes& dataTypes = AnyType,
68+
const QString& description = QString() );
69+
70+
/**
71+
* Initialize a newly constructed data defined button (useful if button was included in a form layout).
72+
* @param layer associated vector layer
73+
* @param propertyCollection associated property collection
74+
* @param propertyKey key for corresponding property
75+
* @param dataTypes expected data type for property values
76+
* @param description string description of expected input data
77+
*/
78+
void init( const QgsVectorLayer* layer,
79+
const QgsAbstractProperty* property = nullptr,
80+
const QgsDataDefinedButtonV2::DataTypes& dataTypes = AnyType,
81+
const QString& description = QString() );
82+
83+
QgsAbstractProperty* toProperty();
84+
85+
/**
86+
* The valid data types that will work for the definition (QVariant-coercible to expected type)
87+
* Compared against the variant type of the QgsField from data source and expression result
88+
*/
89+
const DataTypes& validDataTypes() const { return mDataTypes; }
90+
91+
/**
92+
* The full definition description and current definition (internally generated on a contextual basis)
93+
*/
94+
QString fullDescription() const { return mFullDescription; }
95+
96+
/**
97+
* The usage information about this data definition
98+
*/
99+
QString usageInfo() const { return mUsageInfo; }
100+
101+
/**
102+
* Set the usage information about this data definition
103+
*/
104+
void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
105+
106+
//! Callback function for retrieving the expression context for the button
107+
typedef QgsExpressionContext( *ExpressionContextCallback )( const void* context );
108+
109+
/**
110+
* Register an expression context generator class that will be used to retrieve
111+
* an expression context for the button.
112+
* @param generator A QgsExpressionContextGenerator class that will be used to
113+
* create an expression context when required.
114+
*/
115+
void registerExpressionContextGenerator( QgsExpressionContextGenerator* generator );
116+
117+
/**
118+
* Common descriptions for expected input values
119+
*/
120+
static QString trString();
121+
static QString charDesc();
122+
static QString boolDesc();
123+
static QString anyStringDesc();
124+
static QString intDesc();
125+
static QString intPosDesc();
126+
static QString intPosOneDesc();
127+
static QString doubleDesc();
128+
static QString doublePosDesc();
129+
static QString double0to1Desc();
130+
static QString doubleXYDesc();
131+
static QString double180RotDesc();
132+
static QString intTranspDesc();
133+
static QString unitsMmMuDesc();
134+
static QString unitsMmMuPercentDesc();
135+
static QString colorNoAlphaDesc();
136+
static QString colorAlphaDesc();
137+
static QString textHorzAlignDesc();
138+
static QString textVertAlignDesc();
139+
static QString penJoinStyleDesc();
140+
static QString blendModesDesc();
141+
static QString svgPathDesc();
142+
static QString filePathDesc();
143+
static QString paperSizeDesc();
144+
static QString paperOrientationDesc();
145+
static QString horizontalAnchorDesc();
146+
static QString verticalAnchorDesc();
147+
static QString gradientTypeDesc();
148+
static QString gradientCoordModeDesc();
149+
static QString gradientSpreadDesc();
150+
static QString lineStyleDesc();
151+
static QString capStyleDesc();
152+
static QString fillStyleDesc();
153+
static QString markerStyleDesc();
154+
static QString customDashDesc();
155+
156+
public slots:
157+
158+
/**
159+
* Set whether the current data definition or expression is to be used
160+
*/
161+
void setActive( bool active );
162+
163+
signals:
164+
165+
//! Emitted when property definition changes
166+
void changed();
167+
168+
protected:
169+
void mouseReleaseEvent( QMouseEvent *event ) override;
170+
171+
private:
172+
173+
void updateFieldLists();
174+
void setToProperty( const QgsAbstractProperty* property );
175+
void showDescriptionDialog();
176+
void showExpressionDialog();
177+
void updateGui();
178+
179+
const QgsVectorLayer* mVectorLayer;
180+
181+
QStringList mFieldNameList;
182+
QStringList mFieldTypeList;
183+
184+
bool mActive;
185+
bool mUseExpression;
186+
QString mExpressionString;
187+
QString mFieldName;
188+
189+
QMenu* mDefineMenu;
190+
QAction* mActionDataTypes;
191+
QMenu* mFieldsMenu;
192+
QMenu* mVariablesMenu;
193+
QAction* mActionVariables;
194+
195+
QAction* mActionActive;
196+
QAction* mActionDescription;
197+
QAction* mActionExpDialog;
198+
QAction* mActionExpression;
199+
QAction* mActionPasteExpr;
200+
QAction* mActionCopyExpr;
201+
QAction* mActionClearExpr;
202+
QAction* mActionAssistant;
203+
204+
DataTypes mDataTypes;
205+
QString mDataTypesString;
206+
QString mInputDescription;
207+
QString mFullDescription;
208+
QString mUsageInfo;
209+
210+
QgsExpressionContextGenerator* mExpressionContextGenerator;
211+
212+
private slots:
213+
void aboutToShowMenu();
214+
void menuActionTriggered( QAction* action );
215+
};
216+
217+
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButtonV2::DataTypes )
218+
219+
220+
#endif // QGSDATADEFINEDBUTTONV2_H

‎src/ui/qgsdiagrampropertiesbase.ui

Lines changed: 470 additions & 152 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.