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