QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsdatadefinedsymboldialog.cpp
Go to the documentation of this file.
4 #include "qgsvectorlayer.h"
5 #include "qgslogger.h"
6 
7 #include <QCheckBox>
8 
9 
10 QgsDataDefinedSymbolDialog::QgsDataDefinedSymbolDialog( const QList< DataDefinedSymbolEntry >& entries, const QgsVectorLayer* vl, QWidget * parent, Qt::WindowFlags f )
11  : QDialog( parent, f )
12  , mVectorLayer( vl )
13 {
14  setupUi( this );
15 
16  QgsFields attributeFields;
17  if ( mVectorLayer )
18  {
19  attributeFields = mVectorLayer->pendingFields();
20  }
21 
22  int i = 0;
23  QList< DataDefinedSymbolEntry >::const_iterator entryIt = entries.constBegin();
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  ++i;
47  }
48 
49  for ( int c = 0; c != mTreeWidget->columnCount() - 1; c++ )
50  mTreeWidget->resizeColumnToContents( c );
51 
52  QSettings settings;
53  restoreGeometry( settings.value( "/Windows/QgsDataDefinedSymbolDialog/geometry" ).toByteArray() );
54 }
55 
57 {
58  QSettings settings;
59  settings.setValue( "/Windows/QgsDataDefinedSymbolDialog/geometry", saveGeometry() );
60 }
61 
62 QMap< QString, QString > QgsDataDefinedSymbolDialog::dataDefinedProperties() const
63 {
64  QMap< QString, QString > propertyMap;
65  int rowCount = mTreeWidget->topLevelItemCount();
66  for ( int i = 0; i < rowCount; ++i )
67  {
68  QTreeWidgetItem* item = mTreeWidget->topLevelItem( i );
69  //property
70  QString propertyKey = item->data( 0, Qt::UserRole ).toString();
71  //checked?
72  bool checked = false;
73  QCheckBox* cb = qobject_cast<QCheckBox*>( mTreeWidget->itemWidget( item, 0 ) );
74  if ( cb )
75  {
76  checked = cb->isChecked();
77  }
78  QString expressionString;
79  if ( checked )
80  {
81  QgsFieldExpressionWidget* few = qobject_cast<QgsFieldExpressionWidget*>( mTreeWidget->itemWidget( item, 1 ) );
82  expressionString = few->currentField();
83  }
84  propertyMap.insert( propertyKey, expressionString );
85  }
86  return propertyMap;
87 }
88 
90 {
91  return tr( "double" );
92 }
93 
95 {
96  return tr( "'<red>,<green>,<blue>,<alpha>'" );
97 }
98 
100 {
101  return "'<x>,<y>'";
102 }
103 
105 {
106  return tr( "'<filename>'" );
107 }
108 
110 {
111  // Don't translate, localized keywords are not supported.
112  return "'left'|'center'|'right'";
113 }
114 
116 {
117  // Don't translate, localized keywords are not supported.
118  return "'top'|'center'|'bottom'";
119 }
120 
122 {
123  return tr( "'linear'|'radial'|'conical'" );
124 }
125 
127 {
128  return tr( "'feature'|'viewport'" );
129 }
130 
132 {
133  return tr( "'pad'|'repeat'|'reflect'" );
134 }
135 
137 {
138  return tr( "0 (false)|1 (true)" );
139 }
140 
141 
The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains ...
QgsDataDefinedSymbolDialog(const QList< DataDefinedSymbolEntry > &entries, const QgsVectorLayer *vl, QWidget *parent=0, Qt::WindowFlags f=0)
Container of fields for a vector layer.
Definition: qgsfield.h:163
void setLayer(QgsVectorLayer *layer)
set the layer used to display the fields and expression
QMap< QString, QString > dataDefinedProperties() const
QString currentField(bool *isExpression=0, bool *isValid=0) const
currentField returns the currently selected field or expression if allowed
void setField(const QString &fieldName)
sets the current field or expression in the widget
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
Represents a vector layer which manages a vector based data sets.
#define tr(sourceText)