QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgssmartgroupeditordialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssmartgroupeditordialog.cpp
3 -----------------------------
4 begin : July 2012
5 copyright : (C) 2012 by Arunmozhi
6 email : aruntheguy at 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
17
18#include "qgsapplication.h"
19#include "qgsgui.h"
20#include "qgsstyle.h"
21
22#include <QMessageBox>
23#include <QVariant>
24
25#include "moc_qgssmartgroupeditordialog.cpp"
26
27// -------------------------- //
28// Condition Widget functions //
29// -------------------------- //
31 : QWidget( parent )
32{
33 setupUi( this );
34
35 mConditionId = id;
36
37 mCondCombo->addItem( tr( "has the tag" ), QVariant( "tag" ) );
38 mCondCombo->addItem( tr( "has a part of name matching" ), QVariant( "name" ) );
39 mCondCombo->addItem( tr( "does NOT have the tag" ), QVariant( "!tag" ) );
40 mCondCombo->addItem( tr( "has NO part of name matching" ), QVariant( "!name" ) );
41
42 mRemoveBtn->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.svg" ) ) );
43
44 connect( mRemoveBtn, &QAbstractButton::clicked, this, &QgsSmartGroupCondition::destruct );
45}
46
51
53{
54 return mCondCombo->currentData().toString();
55}
56
58{
59 return mCondLineEdit->text();
60}
61
63{
64 mCondCombo->setCurrentIndex( mCondCombo->findData( QVariant( constraint ) ) );
65}
66
67void QgsSmartGroupCondition::setParameter( const QString &param )
68{
69 mCondLineEdit->setText( param );
70}
71
73{
74 mRemoveBtn->setVisible( !hide );
75}
76
77
78// ------------------------ //
79// Editor Dialog Functions //
80// ------------------------ //
82 : QDialog( parent )
83 , mStyle( style )
84{
85 setupUi( this );
87
88 connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsSmartGroupEditorDialog::buttonBox_accepted );
89
90 mCondCount = 0;
91
92 mAndOrCombo->addItem( tr( "ALL the constraints" ), QVariant( "AND" ) );
93 mAndOrCombo->addItem( tr( "any ONE of the constraints" ), QVariant( "OR" ) );
94
95 mLayout = new QGridLayout( mConditionsBox );
97
98 connect( mAddConditionBtn, &QAbstractButton::clicked, this, &QgsSmartGroupEditorDialog::addCondition );
99}
100
102{
103 return mNameLineEdit->text();
104}
105
107{
108 // enable the remove buttons when 2nd condition is added
109 if ( mConditionMap.count() == 1 )
110 {
111 const auto constMConditionMap = mConditionMap;
112 for ( QgsSmartGroupCondition *condition : constMConditionMap )
113 {
114 condition->hideRemoveButton( false );
115 }
116 }
118 mLayout->addWidget( cond, mCondCount, 0, 1, 1 );
119
121 if ( mConditionMap.isEmpty() )
122 {
123 cond->hideRemoveButton( true );
124 }
125 mConditionMap.insert( mCondCount, cond );
126 ++mCondCount;
127}
128
130{
131 // hide the remove button of the last condition when 2nd last is removed
132 if ( mConditionMap.count() == 2 )
133 {
134 const auto constMConditionMap = mConditionMap;
135 for ( QgsSmartGroupCondition *condition : constMConditionMap )
136 {
137 condition->hideRemoveButton( true );
138 }
139 }
140
141 QgsSmartGroupCondition *cond = mConditionMap.take( id );
142 delete cond;
143}
144
146{
147 QgsSmartConditionMap conditions;
148
149 const auto constMConditionMap = mConditionMap;
150 for ( QgsSmartGroupCondition *condition : constMConditionMap )
151 {
152 conditions.insert( condition->constraint(), condition->parameter() );
153 }
154
155 return conditions;
156}
157
159{
160 return mAndOrCombo->currentData().toString();
161}
162
164{
165 QStringList constraints;
166 constraints << QStringLiteral( "tag" ) << QStringLiteral( "name" ) << QStringLiteral( "!tag" ) << QStringLiteral( "!name" );
167
168 // clear any defaults
169 qDeleteAll( mConditionMap );
170 mConditionMap.clear();
171
172 //set the constraints
173 const auto constConstraints = constraints;
174 for ( const QString &constr : constConstraints )
175 {
176 const QStringList params = map.values( constr );
177 const auto constParams = params;
178 for ( const QString &param : constParams )
179 {
181 mLayout->addWidget( cond, mCondCount, 0, 1, 1 );
182
183 cond->setConstraint( constr );
184 cond->setParameter( param );
185
187
188 mConditionMap.insert( mCondCount, cond );
189 ++mCondCount;
190 }
191 }
192}
193
195{
196 mAndOrCombo->setCurrentIndex( mAndOrCombo->findData( QVariant( op ) ) );
197}
198
200{
201 mNameLineEdit->setText( name );
202}
203
204void QgsSmartGroupEditorDialog::buttonBox_accepted()
205{
206 if ( mNameLineEdit->text().isEmpty() )
207 {
208 QMessageBox::critical( this, tr( "Edit Smart Group" ), tr( "The smart group name field is empty. Kindly provide a name." ) );
209 return;
210 }
211 accept();
212}
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:221
A widget for configuring the conditions attached to a style smart group.
void setConstraint(const QString &constraint)
sets the given constraint
QgsSmartGroupCondition(int id, QWidget *parent=nullptr)
QString parameter()
returns the parameter
void setParameter(const QString &param)
sets the given param
void removed(int id)
Emitted when the group with the specified id is removed.
void hideRemoveButton(bool hide)
sets the remove button hidden state to 'hide'
QString constraint()
returns the constraint key
void setConditionMap(const QgsSmartConditionMap &)
sets up the GUI for the given conditionmap
QMap< int, QgsSmartGroupCondition * > mConditionMap
QgsSmartConditionMap conditionMap()
returns the condition map
QString smartgroupName()
returns the value from mNameLineEdit
QgsSmartGroupEditorDialog(QgsStyle *style, QWidget *parent=nullptr)
void addCondition()
function to create a new ConditionBox and update UI
void removeCondition(int)
slot to remove the condition with id int
void setSmartgroupName(const QString &)
sets the smart group Name
void setOperator(const QString &)
sets the operator AND/OR
QString conditionOperator()
returns the AND/OR condition
A database of saved style entities, including symbols, color ramps, text formats and others.
Definition qgsstyle.h:88
QMultiMap< QString, QString > QgsSmartConditionMap
A multimap to hold the smart group conditions as constraint and parameter pairs.
Definition qgsstyle.h:79