28
28
#include " qgsrelationmanager.h"
29
29
#include " qgsvectordataprovider.h"
30
30
#include " qgsvectorlayer.h"
31
+ #include " qgsfieldexpressionwidget.h"
31
32
32
33
#include < QTreeWidgetItem>
33
34
#include < QWidget>
@@ -72,7 +73,7 @@ QgsFieldsProperties::QgsFieldsProperties( QgsVectorLayer *layer, QWidget* parent
72
73
// tab and group display
73
74
mAddItemButton ->setEnabled ( false );
74
75
75
- mDesignerTree = new DesignerTree ( mAttributesTreeFrame );
76
+ mDesignerTree = new DesignerTree ( mLayer , mAttributesTreeFrame );
76
77
mDesignerListLayout ->addWidget ( mDesignerTree );
77
78
mDesignerTree ->setHeaderLabels ( QStringList () << tr ( " Label" ) );
78
79
@@ -154,7 +155,7 @@ void QgsFieldsProperties::onAttributeSelectionChanged()
154
155
updateButtons ();
155
156
}
156
157
157
- QTreeWidgetItem * QgsFieldsProperties::loadAttributeEditorTreeItem ( QgsAttributeEditorElement* const widgetDef, QTreeWidgetItem* parent )
158
+ QTreeWidgetItem* QgsFieldsProperties::loadAttributeEditorTreeItem ( QgsAttributeEditorElement* const widgetDef, QTreeWidgetItem* parent )
158
159
{
159
160
QTreeWidgetItem* newWidget = nullptr ;
160
161
switch ( widgetDef->type () )
@@ -187,6 +188,7 @@ QTreeWidgetItem *QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE
187
188
188
189
itemData.setColumnCount ( container->columnCount () );
189
190
itemData.setShowAsGroupBox ( container->isGroupBox () );
191
+ itemData.setVisibilityExpression ( container->visibilityExpression () );
190
192
newWidget = mDesignerTree ->addItem ( parent, itemData );
191
193
192
194
Q_FOREACH ( QgsAttributeEditorElement* wdg, container->children () )
@@ -865,6 +867,7 @@ QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTr
865
867
QgsAttributeEditorContainer* container = new QgsAttributeEditorContainer ( item->text ( 0 ), parent );
866
868
container->setColumnCount ( itemData.columnCount () );
867
869
container->setIsGroupBox ( forceGroup ? true : itemData.showAsGroupBox () );
870
+ container->setVisibilityExpression ( itemData.visibilityExpression () );
868
871
869
872
for ( int t = 0 ; t < item->childCount (); t++ )
870
873
{
@@ -1092,8 +1095,9 @@ QTreeWidgetItem* DesignerTree::addContainer( QTreeWidgetItem* parent, const QStr
1092
1095
return newItem;
1093
1096
}
1094
1097
1095
- DesignerTree::DesignerTree ( QWidget* parent )
1098
+ DesignerTree::DesignerTree ( QgsVectorLayer* layer, QWidget* parent )
1096
1099
: QTreeWidget( parent )
1100
+ , mLayer( layer )
1097
1101
{
1098
1102
connect ( this , SIGNAL ( itemDoubleClicked ( QTreeWidgetItem*, int ) ), this , SLOT ( onItemDoubleClicked ( QTreeWidgetItem*, int ) ) );
1099
1103
}
@@ -1271,11 +1275,22 @@ void DesignerTree::onItemDoubleClicked( QTreeWidgetItem* item, int column )
1271
1275
QCheckBox* showAsGroupBox = nullptr ;
1272
1276
QLineEdit* title = new QLineEdit ( itemData.name () );
1273
1277
QSpinBox* columnCount = new QSpinBox ();
1278
+ QGroupBox* visibilityExpressionGroupBox = new QGroupBox ( tr ( " Control visibility by expression " ) );
1279
+ visibilityExpressionGroupBox->setCheckable ( true );
1280
+ visibilityExpressionGroupBox->setChecked ( itemData.visibilityExpression ().enabled () );
1281
+ visibilityExpressionGroupBox->setLayout ( new QGridLayout );
1282
+ QgsFieldExpressionWidget* visibilityExpressionWidget = new QgsFieldExpressionWidget;
1283
+ visibilityExpressionWidget->setLayer ( mLayer );
1284
+ visibilityExpressionWidget->setExpressionDialogTitle ( tr ( " Visibility expression" ) );
1285
+ visibilityExpressionWidget->setExpression ( itemData.visibilityExpression ()->expression () );
1286
+ visibilityExpressionGroupBox->layout ()->addWidget ( visibilityExpressionWidget );
1287
+
1274
1288
columnCount->setRange ( 1 , 5 );
1275
1289
columnCount->setValue ( itemData.columnCount () );
1276
1290
1277
1291
layout->addRow ( tr ( " Title" ), title );
1278
1292
layout->addRow ( tr ( " Column count" ), columnCount );
1293
+ layout->addWidget ( visibilityExpressionGroupBox );
1279
1294
1280
1295
if ( !item->parent () )
1281
1296
{
@@ -1299,6 +1314,11 @@ void DesignerTree::onItemDoubleClicked( QTreeWidgetItem* item, int column )
1299
1314
itemData.setName ( title->text () );
1300
1315
itemData.setShowLabel ( showLabelCheckbox->isChecked () );
1301
1316
1317
+ QgsOptionalExpression visibilityExpression;
1318
+ visibilityExpression.setData ( QgsExpression ( visibilityExpressionWidget->expression () ) );
1319
+ visibilityExpression.setEnabled ( visibilityExpressionGroupBox->isChecked () );
1320
+ itemData.setVisibilityExpression ( visibilityExpression );
1321
+
1302
1322
item->setData ( 0 , QgsFieldsProperties::DesignerTreeRole, itemData.asQVariant () );
1303
1323
item->setText ( 0 , title->text () );
1304
1324
}
@@ -1369,3 +1389,13 @@ void QgsFieldsProperties::DesignerTreeItemData::setShowLabel( bool showLabel )
1369
1389
{
1370
1390
mShowLabel = showLabel;
1371
1391
}
1392
+
1393
+ QgsOptionalExpression QgsFieldsProperties::DesignerTreeItemData::visibilityExpression () const
1394
+ {
1395
+ return mVisibilityExpression ;
1396
+ }
1397
+
1398
+ void QgsFieldsProperties::DesignerTreeItemData::setVisibilityExpression ( const QgsOptionalExpression& visibilityExpression )
1399
+ {
1400
+ mVisibilityExpression = visibilityExpression;
1401
+ }
0 commit comments