QGIS API Documentation  2.12.0-Lyon
qgsdatadefinedsymboldialog.cpp
Go to the documentation of this file.
4 #include "qgsvectorlayer.h"
5 #include "qgslogger.h"
6 
7 #include <QCheckBox>
8 #include <QSettings>
9 
10 
12  : QDialog( parent, f )
13  , mVectorLayer( vl )
14 {
15  setupUi( this );
16 
17  QgsFields attributeFields;
18  if ( mVectorLayer )
19  {
20  attributeFields = mVectorLayer->fields();
21  }
22 
24  for ( ; entryIt != entries.constEnd(); ++entryIt )
25  {
26  QTreeWidgetItem* item = new QTreeWidgetItem( mTreeWidget );
27 
28  //check box
29  QCheckBox* cb = new QCheckBox( entryIt->title, this );
30  cb->setChecked( !entryIt->initialValue.isEmpty() );
31  item->setData( 0, Qt::UserRole, entryIt->property );
32  mTreeWidget->setItemWidget( item, 0, cb );
33 
34  // expression
36  few->setMaximumWidth( 350 );
37  few->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
38  few->setLayer( const_cast<QgsVectorLayer*>( vl ) );
39  few->setField( entryIt->initialValue );
40  mTreeWidget->setItemWidget( item, 1, few );
41 
42  //help text
43  item->setText( 2, entryIt->helpText );
44 
45  mTreeWidget->addTopLevelItem( item );
46  }
47 
48  for ( int c = 0; c != mTreeWidget->columnCount() - 1; c++ )
49  mTreeWidget->resizeColumnToContents( c );
50 
51  QSettings settings;
52  restoreGeometry( settings.value( "/Windows/QgsDataDefinedSymbolDialog/geometry" ).toByteArray() );
53 }
54 
56 {
57  QSettings settings;
58  settings.setValue( "/Windows/QgsDataDefinedSymbolDialog/geometry", saveGeometry() );
59 }
60 
62 {
63  QMap< QString, QString > propertyMap;
64  int rowCount = mTreeWidget->topLevelItemCount();
65  for ( int i = 0; i < rowCount; ++i )
66  {
67  QTreeWidgetItem* item = mTreeWidget->topLevelItem( i );
68  //property
69  QString propertyKey = item->data( 0, Qt::UserRole ).toString();
70  //checked?
71  bool checked = false;
72  QCheckBox* cb = qobject_cast<QCheckBox*>( mTreeWidget->itemWidget( item, 0 ) );
73  if ( cb )
74  {
75  checked = cb->isChecked();
76  }
77  QString expressionString;
78  if ( checked )
79  {
80  QgsFieldExpressionWidget* few = qobject_cast<QgsFieldExpressionWidget*>( mTreeWidget->itemWidget( item, 1 ) );
81  expressionString = few->currentField();
82  }
83  propertyMap.insert( propertyKey, expressionString );
84  }
85  return propertyMap;
86 }
87 
89 {
90  return tr( "double" );
91 }
92 
94 {
95  return tr( "'<red>,<green>,<blue>,<alpha>'" );
96 }
97 
99 {
100  return "'<x>,<y>'";
101 }
102 
104 {
105  return tr( "'<filename>'" );
106 }
107 
109 {
110  // Don't translate, localized keywords are not supported.
111  return "'left'|'center'|'right'";
112 }
113 
115 {
116  // Don't translate, localized keywords are not supported.
117  return "'top'|'center'|'bottom'";
118 }
119 
121 {
122  return tr( "'linear'|'radial'|'conical'" );
123 }
124 
126 {
127  return tr( "'feature'|'viewport'" );
128 }
129 
131 {
132  return tr( "'pad'|'repeat'|'reflect'" );
133 }
134 
136 {
137  return tr( "0 (false)|1 (true)" );
138 }
139 
141 {
142  return "'no'|'solid'|'dash'|'dot'|'dash dot'|'dash dot dot'";
143 }
144 
146 {
147  return "'bevel'|'miter'|'round'";
148 }
149 
151 {
152  return "'square'|'flat'|'round'";
153 }
154 
156 {
157  return "'solid'|'horizontal'|'vertical'|'cross'|'b_diagonal'|'f_diagonal'|"
158  "'diagonal_x'|'dense1'|'dense2'|'dense3'|'dense4'|'dense5'|"
159  "'dense6'|'dense7'|'no'";
160 }
161 
162 
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()
QgsFields fields() const
Returns the list of fields of this layer.
static Q_DECL_DEPRECATED QString lineStyleHelpText()
Container of fields for a vector layer.
Definition: qgsfield.h:177
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
QString tr(const char *sourceText, const char *disambiguation, int n)
static Q_DECL_DEPRECATED QString fillStyleHelpText()
void setValue(const QString &key, const QVariant &value)
static Q_DECL_DEPRECATED QString doubleHelpText()
Q_DECL_DEPRECATED QMap< QString, QString > dataDefinedProperties() const
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)
QString currentField(bool *isExpression=0, bool *isValid=0) const
currentField returns the currently selected field or expression if allowed
QByteArray saveGeometry() 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)
Q_DECL_DEPRECATED QgsDataDefinedSymbolDialog(const QList< DataDefinedSymbolEntry > &entries, const QgsVectorLayer *vl, QWidget *parent=0, const Qt::WindowFlags &f=0)
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