-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgspropertyassistantwidget.h
156 lines (107 loc) · 5.36 KB
/
qgspropertyassistantwidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/***************************************************************************
qgspropertyassistantwidget.h
----------------------------
begin : February, 2017
copyright : (C) 2017 Nyall Dawson
email : nyall dot dawson at gmail dot 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 QGSPROPERTYASSISTANTWIDGET_H
#define QGSPROPERTYASSISTANTWIDGET_H
#include "qgspanelwidget.h"
#include "ui_qgspropertyassistantwidgetbase.h"
#include "ui_qgspropertysizeassistantwidget.h"
#include "ui_qgspropertycolorassistantwidget.h"
#include "qgsproperty.h"
#include "qgslayertreegroup.h"
#include "qgssymbol.h"
#include "qgslayertreemodellegendnode.h"
#include "qgis_gui.h"
#include <QStandardItemModel>
#include <QItemDelegate>
class QgsMapCanvas;
///@cond PRIVATE
class GUI_EXPORT QgsPropertyAbstractTransformerWidget : public QWidget
{
Q_OBJECT
public:
QgsPropertyAbstractTransformerWidget( QWidget* parent = nullptr, const QgsPropertyDefinition& definition = QgsPropertyDefinition() )
: QWidget( parent )
, mDefinition( definition )
{}
virtual QgsPropertyTransformer* createTransformer( double minValue, double maxValue ) const = 0;
virtual QList< QgsSymbolLegendNode* > generatePreviews( const QList<double>& breaks, QgsLayerTreeLayer* parent, const QgsSymbol* symbol, double minValue, double maxValue ) const;
signals:
void widgetChanged();
protected:
QgsPropertyDefinition mDefinition;
};
class GUI_EXPORT QgsPropertySizeAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertySizeAssistant
{
Q_OBJECT
public:
QgsPropertySizeAssistantWidget( QWidget* parent = nullptr, const QgsPropertyDefinition& definition = QgsPropertyDefinition(), const QgsProperty& initialState = QgsProperty() );
virtual QgsSizeScaleTransformer* createTransformer( double minValue, double maxValue ) const override;
QList< QgsSymbolLegendNode* > generatePreviews( const QList<double>& breaks, QgsLayerTreeLayer* parent, const QgsSymbol* symbol, double minValue, double maxValue ) const override;
};
class GUI_EXPORT QgsPropertyColorAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertyColorAssistant
{
Q_OBJECT
public:
QgsPropertyColorAssistantWidget( QWidget* parent = nullptr, const QgsPropertyDefinition& definition = QgsPropertyDefinition(), const QgsProperty& initialState = QgsProperty() );
virtual QgsColorRampTransformer* createTransformer( double minValue, double maxValue ) const override;
QList< QgsSymbolLegendNode* > generatePreviews( const QList<double>& breaks, QgsLayerTreeLayer* parent, const QgsSymbol* symbol, double minValue, double maxValue ) const override;
};
///@endcond PRIVATE
class GUI_EXPORT QgsPropertyAssistantWidget : public QgsPanelWidget, private Ui::PropertyAssistantBase
{
Q_OBJECT
public:
QgsPropertyAssistantWidget( QWidget* parent = nullptr, const QgsPropertyDefinition& definition = QgsPropertyDefinition(),
const QgsProperty& initialState = QgsProperty(),
const QgsVectorLayer* layer = nullptr );
/**
* Register an expression context generator class that will be used to retrieve
* an expression context for the button when required.
*/
void registerExpressionContextGenerator( QgsExpressionContextGenerator* generator );
void updateProperty( QgsProperty& property );
void setSymbol( std::shared_ptr< QgsSymbol > symbol ) { mSymbol = symbol; updatePreview(); }
void setDockMode( bool dockMode ) override;
private slots:
void computeValuesFromLayer();
void updatePreview();
private:
QgsPropertyDefinition mDefinition;
const QgsVectorLayer* mLayer = nullptr;
QgsExpressionContextGenerator* mExpressionContextGenerator = nullptr;
QgsPropertyAbstractTransformerWidget* mTransformerWidget = nullptr;
QgsLayerTreeLayer* mLayerTreeLayer = nullptr;
QgsLayerTreeGroup mRoot;
QStandardItemModel mPreviewList;
std::shared_ptr< QgsSymbol > mSymbol;
bool computeValuesFromExpression( const QString& expression, double& minValue, double& maxValue ) const;
bool computeValuesFromField( const QString& fieldName, double& minValue, double& maxValue ) const;
};
/// @cond PRIVATE
class ItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
explicit ItemDelegate( QStandardItemModel* model ) : mModel( model ) {}
QSize sizeHint( const QStyleOptionViewItem& /*option*/, const QModelIndex & index ) const override
{
return mModel->item( index.row() )->icon().actualSize( QSize( 512, 512 ) );
}
private:
QStandardItemModel* mModel = nullptr;
};
///@endcond
#endif // QGSPROPERTYASSISTANTWIDGET_H