QGIS API Documentation  2.8.2-Wien
 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 #include <QSettings>
9 
10 
11 QgsDataDefinedSymbolDialog::QgsDataDefinedSymbolDialog( const QList< DataDefinedSymbolEntry >& entries, const QgsVectorLayer* vl, QWidget * parent, Qt::WindowFlags f )
12  : QDialog( parent, f )
13  , mVectorLayer( vl )
14 {
15  setupUi( this );
16 
17  QgsFields attributeFields;
18  if ( mVectorLayer )
19  {
20  attributeFields = mVectorLayer->pendingFields();
21  }
22 
23  int i = 0;
24  QList< DataDefinedSymbolEntry >::const_iterator entryIt = entries.constBegin();
25  for ( ; entryIt != entries.constEnd(); ++entryIt )
26  {
27  QTreeWidgetItem* item = new QTreeWidgetItem( mTreeWidget );
28 
29  //check box
30  QCheckBox* cb = new QCheckBox( entryIt->title, this );
31  cb->setChecked( !entryIt->initialValue.isEmpty() );
32  item->setData( 0, Qt::UserRole, entryIt->property );
33  mTreeWidget->setItemWidget( item, 0, cb );
34 
35  // expression
37  few->setMaximumWidth( 350 );
38  few->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
39  few->setLayer( const_cast<QgsVectorLayer*>( vl ) );
40  few->setField( entryIt->initialValue );
41  mTreeWidget->setItemWidget( item, 1, few );
42 
43  //help text
44  item->setText( 2, entryIt->helpText );
45 
46  mTreeWidget->addTopLevelItem( item );
47  ++i;
48  }
49 
50  for ( int c = 0; c != mTreeWidget->columnCount() - 1; c++ )
51  mTreeWidget->resizeColumnToContents( c );
52 
53  QSettings settings;
54  restoreGeometry( settings.value( "/Windows/QgsDataDefinedSymbolDialog/geometry" ).toByteArray() );
55 }
56 
58 {
59  QSettings settings;
60  settings.setValue( "/Windows/QgsDataDefinedSymbolDialog/geometry", saveGeometry() );
61 }
62 
63 QMap< QString, QString > QgsDataDefinedSymbolDialog::dataDefinedProperties() const
64 {
65  QMap< QString, QString > propertyMap;
66  int rowCount = mTreeWidget->topLevelItemCount();
67  for ( int i = 0; i < rowCount; ++i )
68  {
69  QTreeWidgetItem* item = mTreeWidget->topLevelItem( i );
70  //property
71  QString propertyKey = item->data( 0, Qt::UserRole ).toString();
72  //checked?
73  bool checked = false;
74  QCheckBox* cb = qobject_cast<QCheckBox*>( mTreeWidget->itemWidget( item, 0 ) );
75  if ( cb )
76  {
77  checked = cb->isChecked();
78  }
79  QString expressionString;
80  if ( checked )
81  {
82  QgsFieldExpressionWidget* few = qobject_cast<QgsFieldExpressionWidget*>( mTreeWidget->itemWidget( item, 1 ) );
83  expressionString = few->currentField();
84  }
85  propertyMap.insert( propertyKey, expressionString );
86  }
87  return propertyMap;
88 }
89 
91 {
92  return tr( "double" );
93 }
94 
96 {
97  return tr( "'<red>,<green>,<blue>,<alpha>'" );
98 }
99 
101 {
102  return "'<x>,<y>'";
103 }
104 
106 {
107  return tr( "'<filename>'" );
108 }
109 
111 {
112  // Don't translate, localized keywords are not supported.
113  return "'left'|'center'|'right'";
114 }
115 
117 {
118  // Don't translate, localized keywords are not supported.
119  return "'top'|'center'|'bottom'";
120 }
121 
123 {
124  return tr( "'linear'|'radial'|'conical'" );
125 }
126 
128 {
129  return tr( "'feature'|'viewport'" );
130 }
131 
133 {
134  return tr( "'pad'|'repeat'|'reflect'" );
135 }
136 
138 {
139  return tr( "0 (false)|1 (true)" );
140 }
141 
143 {
144  return "'no'|'solid'|'dash'|'dot'|'dash dot'|'dash dot dot'";
145 }
146 
148 {
149  return "'bevel'|'miter'|'round'";
150 }
151 
153 {
154  return "'square'|'flat'|'round'";
155 }
156 
158 {
159  return "'solid'|'horizontal'|'vertical'|'cross'|'b_diagonal'|'f_diagonal'|"
160  "'diagonal_x'|'dense1'|'dense2'|'dense3'|'dense4'|'dense5'|"
161  "'dense6'|'dense7'|'no'";
162 }
163 
164