QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsdatadefinedsymboldialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatadefinedsymboldialog.cpp
3  ---------------------
4  begin : March 2013
5  copyright : (C) 2013 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
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  ***************************************************************************/
18 #include "qgsvectorlayer.h"
19 #include "qgslogger.h"
20 
21 #include <QCheckBox>
22 #include <QSettings>
23 
24 
26  : QDialog( parent, f )
27  , mVectorLayer( vl )
28 {
29  setupUi( this );
30 
31  QgsFields attributeFields;
32  if ( mVectorLayer )
33  {
34  attributeFields = mVectorLayer->fields();
35  }
36 
38  for ( ; entryIt != entries.constEnd(); ++entryIt )
39  {
40  QTreeWidgetItem* item = new QTreeWidgetItem( mTreeWidget );
41 
42  //check box
43  QCheckBox* cb = new QCheckBox( entryIt->title, this );
44  cb->setChecked( !entryIt->initialValue.isEmpty() );
45  item->setData( 0, Qt::UserRole, entryIt->property );
46  mTreeWidget->setItemWidget( item, 0, cb );
47 
48  // expression
50  few->setMaximumWidth( 350 );
51  few->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
52  few->setLayer( const_cast<QgsVectorLayer*>( vl ) );
53  few->setField( entryIt->initialValue );
54  mTreeWidget->setItemWidget( item, 1, few );
55 
56  //help text
57  item->setText( 2, entryIt->helpText );
58 
59  mTreeWidget->addTopLevelItem( item );
60  }
61 
62  for ( int c = 0; c != mTreeWidget->columnCount() - 1; c++ )
63  mTreeWidget->resizeColumnToContents( c );
64 
65  QSettings settings;
66  restoreGeometry( settings.value( "/Windows/QgsDataDefinedSymbolDialog/geometry" ).toByteArray() );
67 }
68 
70 {
71  QSettings settings;
72  settings.setValue( "/Windows/QgsDataDefinedSymbolDialog/geometry", saveGeometry() );
73 }
74 
76 {
77  QMap< QString, QString > propertyMap;
78  int rowCount = mTreeWidget->topLevelItemCount();
79  for ( int i = 0; i < rowCount; ++i )
80  {
81  QTreeWidgetItem* item = mTreeWidget->topLevelItem( i );
82  //property
83  QString propertyKey = item->data( 0, Qt::UserRole ).toString();
84  //checked?
85  bool checked = false;
86  QCheckBox* cb = qobject_cast<QCheckBox*>( mTreeWidget->itemWidget( item, 0 ) );
87  if ( cb )
88  {
89  checked = cb->isChecked();
90  }
91  QString expressionString;
92  if ( checked )
93  {
94  QgsFieldExpressionWidget* few = qobject_cast<QgsFieldExpressionWidget*>( mTreeWidget->itemWidget( item, 1 ) );
95  expressionString = few->currentField();
96  }
97  propertyMap.insert( propertyKey, expressionString );
98  }
99  return propertyMap;
100 }
101 
103 {
104  return tr( "double" );
105 }
106 
108 {
109  return tr( "'<red>,<green>,<blue>,<alpha>'" );
110 }
111 
113 {
114  return "'<x>,<y>'";
115 }
116 
118 {
119  return tr( "'<filename>'" );
120 }
121 
123 {
124  // Don't translate, localized keywords are not supported.
125  return "'left'|'center'|'right'";
126 }
127 
129 {
130  // Don't translate, localized keywords are not supported.
131  return "'top'|'center'|'bottom'";
132 }
133 
135 {
136  return tr( "'linear'|'radial'|'conical'" );
137 }
138 
140 {
141  return tr( "'feature'|'viewport'" );
142 }
143 
145 {
146  return tr( "'pad'|'repeat'|'reflect'" );
147 }
148 
150 {
151  return tr( "0 (false)|1 (true)" );
152 }
153 
155 {
156  return "'no'|'solid'|'dash'|'dot'|'dash dot'|'dash dot dot'";
157 }
158 
160 {
161  return "'bevel'|'miter'|'round'";
162 }
163 
165 {
166  return "'square'|'flat'|'round'";
167 }
168 
170 {
171  return "'solid'|'horizontal'|'vertical'|'cross'|'b_diagonal'|'f_diagonal'|"
172  "'diagonal_x'|'dense1'|'dense2'|'dense3'|'dense4'|'dense5'|"
173  "'dense6'|'dense7'|'no'";
174 }
175 
176 
The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains ...
QByteArray toByteArray() const
void setupUi(QWidget *widget)
static Q_DECL_DEPRECATED QString gradientSpreadHelpText()
static Q_DECL_DEPRECATED QString gradientCoordModeHelpText()
static Q_DECL_DEPRECATED QString fileNameHelpText()
static Q_DECL_DEPRECATED QString lineStyleHelpText()
Container of fields for a vector layer.
Definition: qgsfield.h:252
static Q_DECL_DEPRECATED QString offsetHelpText()
virtual void setData(int column, int role, const QVariant &value)
void setLayer(QgsVectorLayer *layer)
set the layer used to display the fields and expression
static Q_DECL_DEPRECATED QString horizontalAnchorHelpText()
virtual QVariant data(int column, int role) const
Q_DECL_DEPRECATED QgsDataDefinedSymbolDialog(const QList< DataDefinedSymbolEntry > &entries, const QgsVectorLayer *vl, QWidget *parent=nullptr, const Qt::WindowFlags &f=nullptr)
QString tr(const char *sourceText, const char *disambiguation, int n)
QgsFields fields() const
Returns the list of fields of this layer.
static Q_DECL_DEPRECATED QString fillStyleHelpText()
void setValue(const QString &key, const QVariant &value)
static Q_DECL_DEPRECATED QString doubleHelpText()
bool restoreGeometry(const QByteArray &geometry)
static Q_DECL_DEPRECATED QString joinStyleHelpText()
void setSizePolicy(QSizePolicy)
static Q_DECL_DEPRECATED QString gradientTypeHelpText()
void setChecked(bool)
static Q_DECL_DEPRECATED QString capStyleHelpText()
QVariant value(const QString &key, const QVariant &defaultValue) const
void setMaximumWidth(int maxw)
QByteArray saveGeometry() const
Q_DECL_DEPRECATED QMap< QString, QString > dataDefinedProperties() const
void setField(const QString &fieldName)
sets the current field or expression in the widget
void setText(int column, const QString &text)
typedef WindowFlags
iterator insert(const Key &key, const T &value)
const_iterator constEnd() const
const_iterator constBegin() const
static Q_DECL_DEPRECATED QString boolHelpText()
Represents a vector layer which manages a vector based data sets.
static Q_DECL_DEPRECATED QString colorHelpText()
static Q_DECL_DEPRECATED QString verticalAnchorHelpText()
QString toString() const
QString currentField(bool *isExpression=nullptr, bool *isValid=nullptr) const
currentField returns the currently selected field or expression if allowed