QGIS API Documentation 3.99.0-Master (d270888f95f)
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 <QString>
24#include <QVariant>
25
26#include "moc_qgssmartgroupeditordialog.cpp"
27
28using namespace Qt::StringLiterals;
29
30// -------------------------- //
31// Condition Widget functions //
32// -------------------------- //
34 : QWidget( parent )
35{
36 setupUi( this );
37
38 mConditionId = id;
39
40 mCondCombo->addItem( tr( "has the tag" ), QVariant( "tag" ) );
41 mCondCombo->addItem( tr( "has a part of name matching" ), QVariant( "name" ) );
42 mCondCombo->addItem( tr( "does NOT have the tag" ), QVariant( "!tag" ) );
43 mCondCombo->addItem( tr( "has NO part of name matching" ), QVariant( "!name" ) );
44
45 mRemoveBtn->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.svg" ) ) );
46
47 connect( mRemoveBtn, &QAbstractButton::clicked, this, &QgsSmartGroupCondition::destruct );
48}
49
54
56{
57 return mCondCombo->currentData().toString();
58}
59
61{
62 return mCondLineEdit->text();
63}
64
66{
67 mCondCombo->setCurrentIndex( mCondCombo->findData( QVariant( constraint ) ) );
68}
69
70void QgsSmartGroupCondition::setParameter( const QString &param )
71{
72 mCondLineEdit->setText( param );
73}
74
76{
77 mRemoveBtn->setVisible( !hide );
78}
79
80
81// ------------------------ //
82// Editor Dialog Functions //
83// ------------------------ //
85 : QDialog( parent )
86 , mStyle( style )
87{
88 setupUi( this );
90
91 connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsSmartGroupEditorDialog::buttonBox_accepted );
92
93 mCondCount = 0;
94
95 mAndOrCombo->addItem( tr( "ALL the constraints" ), QVariant( "AND" ) );
96 mAndOrCombo->addItem( tr( "any ONE of the constraints" ), QVariant( "OR" ) );
97
98 mLayout = new QGridLayout( mConditionsBox );
100
101 connect( mAddConditionBtn, &QAbstractButton::clicked, this, &QgsSmartGroupEditorDialog::addCondition );
102}
103
105{
106 return mNameLineEdit->text();
107}
108
110{
111 // enable the remove buttons when 2nd condition is added
112 if ( mConditionMap.count() == 1 )
113 {
114 const auto constMConditionMap = mConditionMap;
115 for ( QgsSmartGroupCondition *condition : constMConditionMap )
116 {
117 condition->hideRemoveButton( false );
118 }
119 }
121 mLayout->addWidget( cond, mCondCount, 0, 1, 1 );
122
124 if ( mConditionMap.isEmpty() )
125 {
126 cond->hideRemoveButton( true );
127 }
128 mConditionMap.insert( mCondCount, cond );
129 ++mCondCount;
130}
131
133{
134 // hide the remove button of the last condition when 2nd last is removed
135 if ( mConditionMap.count() == 2 )
136 {
137 const auto constMConditionMap = mConditionMap;
138 for ( QgsSmartGroupCondition *condition : constMConditionMap )
139 {
140 condition->hideRemoveButton( true );
141 }
142 }
143
144 QgsSmartGroupCondition *cond = mConditionMap.take( id );
145 delete cond;
146}
147
149{
150 QgsSmartConditionMap conditions;
151
152 const auto constMConditionMap = mConditionMap;
153 for ( QgsSmartGroupCondition *condition : constMConditionMap )
154 {
155 conditions.insert( condition->constraint(), condition->parameter() );
156 }
157
158 return conditions;
159}
160
162{
163 return mAndOrCombo->currentData().toString();
164}
165
167{
168 QStringList constraints;
169 constraints << u"tag"_s << u"name"_s << u"!tag"_s << u"!name"_s;
170
171 // clear any defaults
172 qDeleteAll( mConditionMap );
173 mConditionMap.clear();
174
175 //set the constraints
176 const auto constConstraints = constraints;
177 for ( const QString &constr : constConstraints )
178 {
179 const QStringList params = map.values( constr );
180 const auto constParams = params;
181 for ( const QString &param : constParams )
182 {
184 mLayout->addWidget( cond, mCondCount, 0, 1, 1 );
185
186 cond->setConstraint( constr );
187 cond->setParameter( param );
188
190
191 mConditionMap.insert( mCondCount, cond );
192 ++mCondCount;
193 }
194 }
195}
196
198{
199 mAndOrCombo->setCurrentIndex( mAndOrCombo->findData( QVariant( op ) ) );
200}
201
203{
204 mNameLineEdit->setText( name );
205}
206
207void QgsSmartGroupEditorDialog::buttonBox_accepted()
208{
209 if ( mNameLineEdit->text().isEmpty() )
210 {
211 QMessageBox::critical( this, tr( "Edit Smart Group" ), tr( "The smart group name field is empty. Kindly provide a name." ) );
212 return;
213 }
214 accept();
215}
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:224
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:89
QMultiMap< QString, QString > QgsSmartConditionMap
A multimap to hold the smart group conditions as constraint and parameter pairs.
Definition qgsstyle.h:80