23
23
#include < QLabel>
24
24
#include < QLineEdit>
25
25
26
- QgsAttributeSelectionDialog::QgsAttributeSelectionDialog (const QgsVectorLayer* vLayer, const QSet<int >& enabledAttributes, const QMap<int , QString>& aliasMap, \
27
- QWidget * parent, Qt::WindowFlags f): QDialog(parent, f), mVectorLayer(vLayer)
26
+ QgsAttributeSelectionDialog::QgsAttributeSelectionDialog ( const QgsVectorLayer* vLayer, const QSet<int >& enabledAttributes, const QMap<int , QString>& aliasMap,
27
+ QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mVectorLayer( vLayer )
28
28
{
29
- if ( vLayer )
30
- {
31
- mGridLayout = new QGridLayout (this );
32
- QLabel* attributeLabel = new QLabel (QString (" <b>" ) + tr (" Attribute" ) + QString (" </b>" ), this );
33
- attributeLabel->setTextFormat (Qt::RichText);
34
- mGridLayout ->addWidget (attributeLabel, 0 , 0 );
35
- QLabel* aliasLabel = new QLabel (QString (" <b>" ) + tr (" Alias" ) + QString (" </b>" ), this );
36
- aliasLabel->setTextFormat (Qt::RichText);
37
- mGridLayout ->addWidget (aliasLabel, 0 , 1 );
38
-
39
- QgsFieldMap fieldMap = vLayer->pendingFields ();
40
- QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin ();
41
- int layoutRowCounter = 1 ;
42
- for (; fieldIt != fieldMap.constEnd (); ++fieldIt)
43
- {
44
- QCheckBox* attributeCheckBox = new QCheckBox (fieldIt.value ().name (), this );
45
- if ( enabledAttributes.size () < 1 || enabledAttributes.contains (fieldIt.key ()) )
46
- {
47
- attributeCheckBox->setCheckState (Qt::Checked);
48
- }
49
- else
50
- {
51
- attributeCheckBox->setCheckState (Qt::Unchecked);
52
- }
53
- mGridLayout ->addWidget (attributeCheckBox, layoutRowCounter, 0 );
29
+ if ( vLayer )
30
+ {
31
+ mGridLayout = new QGridLayout ( this );
32
+ QLabel* attributeLabel = new QLabel ( QString ( " <b>" ) + tr ( " Attribute" ) + QString ( " </b>" ), this );
33
+ attributeLabel->setTextFormat ( Qt::RichText );
34
+ mGridLayout ->addWidget ( attributeLabel, 0 , 0 );
35
+ QLabel* aliasLabel = new QLabel ( QString ( " <b>" ) + tr ( " Alias" ) + QString ( " </b>" ), this );
36
+ aliasLabel->setTextFormat ( Qt::RichText );
37
+ mGridLayout ->addWidget ( aliasLabel, 0 , 1 );
54
38
55
- QLineEdit* attributeLineEdit = new QLineEdit (this );
56
- QMap<int , QString>::const_iterator aliasIt = aliasMap.find ( fieldIt.key () );
57
- if (aliasIt != aliasMap.constEnd ())
58
- {
59
- attributeLineEdit->setText (aliasIt.value ());
60
- }
61
- mGridLayout ->addWidget (attributeLineEdit, layoutRowCounter, 1 );
62
- ++layoutRowCounter;
63
- }
39
+ QgsFieldMap fieldMap = vLayer->pendingFields ();
40
+ QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin ();
41
+ int layoutRowCounter = 1 ;
42
+ for ( ; fieldIt != fieldMap.constEnd (); ++fieldIt )
43
+ {
44
+ QCheckBox* attributeCheckBox = new QCheckBox ( fieldIt.value ().name (), this );
45
+ if ( enabledAttributes.size () < 1 || enabledAttributes.contains ( fieldIt.key () ) )
46
+ {
47
+ attributeCheckBox->setCheckState ( Qt::Checked );
48
+ }
49
+ else
50
+ {
51
+ attributeCheckBox->setCheckState ( Qt::Unchecked );
52
+ }
53
+ mGridLayout ->addWidget ( attributeCheckBox, layoutRowCounter, 0 );
64
54
65
- QDialogButtonBox* buttonBox = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
66
- QObject::connect (buttonBox, SIGNAL (accepted ()), this , SLOT (accept ()));
67
- QObject::connect (buttonBox, SIGNAL (rejected ()), this , SLOT (reject ()));
68
- mGridLayout ->addWidget ( buttonBox, layoutRowCounter, 0 , 3 , 1 );
55
+ QLineEdit* attributeLineEdit = new QLineEdit ( this );
56
+ QMap<int , QString>::const_iterator aliasIt = aliasMap.find ( fieldIt.key () );
57
+ if ( aliasIt != aliasMap.constEnd () )
58
+ {
59
+ attributeLineEdit->setText ( aliasIt.value () );
60
+ }
61
+ mGridLayout ->addWidget ( attributeLineEdit, layoutRowCounter, 1 );
62
+ ++layoutRowCounter;
69
63
}
64
+
65
+ QDialogButtonBox* buttonBox = new QDialogButtonBox ( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
66
+ QObject::connect ( buttonBox, SIGNAL ( accepted () ), this , SLOT ( accept () ) );
67
+ QObject::connect ( buttonBox, SIGNAL ( rejected () ), this , SLOT ( reject () ) );
68
+ mGridLayout ->addWidget ( buttonBox, layoutRowCounter, 0 , 3 , 1 );
69
+ }
70
70
}
71
71
72
72
QgsAttributeSelectionDialog::~QgsAttributeSelectionDialog ()
@@ -76,69 +76,56 @@ QgsAttributeSelectionDialog::~QgsAttributeSelectionDialog()
76
76
77
77
QSet<int > QgsAttributeSelectionDialog::enabledAttributes () const
78
78
{
79
- QSet<int > result;
80
- if ( !mGridLayout || !mVectorLayer )
81
- {
82
- return result;
83
- }
79
+ QSet<int > result;
80
+ if ( !mGridLayout || !mVectorLayer )
81
+ {
82
+ return result;
83
+ }
84
84
85
- for ( int i = 1 ; i < mGridLayout ->rowCount (); ++i)
85
+ for ( int i = 1 ; i < mGridLayout ->rowCount (); ++i )
86
+ {
87
+ QLayoutItem *checkBoxItem = mGridLayout ->itemAtPosition ( i, 0 );
88
+ if ( checkBoxItem )
86
89
{
87
- bool boxChecked = false ;
88
- QLayoutItem* checkBoxItem = mGridLayout ->itemAtPosition (i, 0 );
89
- if (checkBoxItem)
90
- {
91
- QWidget* checkBoxWidget = checkBoxItem->widget ();
92
- if (checkBoxWidget)
93
- {
94
- QCheckBox* checkBox = dynamic_cast <QCheckBox*>(checkBoxWidget);
95
- if (checkBox)
96
- {
97
- if (checkBox->checkState () == Qt::Checked)
98
- {
99
- result.insert (mVectorLayer ->fieldNameIndex (checkBox->text ()));
100
- }
101
- }
102
- }
103
- }
90
+ QCheckBox *checkBox = qobject_cast< QCheckBox * >( checkBoxItem->widget () );
91
+ if ( checkBox && checkBox->checkState () == Qt::Checked )
92
+ {
93
+ result.insert ( mVectorLayer ->fieldNameIndex ( checkBox->text () ) );
94
+ }
104
95
}
96
+ }
105
97
106
- return result;
98
+ return result;
107
99
}
108
100
109
101
QMap<int , QString> QgsAttributeSelectionDialog::aliasMap () const
110
102
{
111
- QMap<int , QString> result;
112
- if ( !mGridLayout || !mVectorLayer )
113
- {
114
- return result;
115
- }
103
+ QMap<int , QString> result;
104
+ if ( !mGridLayout || !mVectorLayer )
105
+ {
106
+ return result;
107
+ }
116
108
117
- for ( int i = 1 ; i < mGridLayout ->rowCount (); ++i)
109
+ for ( int i = 1 ; i < mGridLayout ->rowCount (); ++i )
110
+ {
111
+ QLayoutItem* lineEditItem = mGridLayout ->itemAtPosition ( i, 1 );
112
+ QLayoutItem* checkBoxItem = mGridLayout ->itemAtPosition ( i, 0 );
113
+ if ( lineEditItem && checkBoxItem )
118
114
{
119
- QLayoutItem* lineEditItem = mGridLayout ->itemAtPosition (i, 1 );
120
- QLayoutItem* checkBoxItem = mGridLayout ->itemAtPosition (i, 0 );
121
- if (lineEditItem && checkBoxItem)
115
+ QLineEdit *lineEdit = qobject_cast<QLineEdit*>( lineEditItem->widget () );
116
+ QCheckBox *checkBox = qobject_cast<QCheckBox*>( checkBoxItem->widget () );
117
+ if ( lineEdit )
118
+ {
119
+ QString aliasText = lineEdit->text ();
120
+ if ( !aliasText.isEmpty () && checkBox )
122
121
{
123
- QWidget* lineEditWidget = lineEditItem->widget ();
124
- QWidget* checkBoxWidget = checkBoxItem->widget ();
125
- if (lineEditWidget)
126
- {
127
- QLineEdit* lineEdit = dynamic_cast <QLineEdit*>(lineEditWidget);
128
- QCheckBox* checkBox = dynamic_cast <QCheckBox*>(checkBoxWidget);
129
- if (lineEdit)
130
- {
131
- QString aliasText = lineEdit->text ();
132
- if (!aliasText.isEmpty ())
133
- {
134
- // insert into map
135
- int fieldIndex = mVectorLayer ->fieldNameIndex ( checkBox->text () );
136
- result.insert (fieldIndex, aliasText);
137
- }
138
- }
139
- }
122
+ // insert into map
123
+ int fieldIndex = mVectorLayer ->fieldNameIndex ( checkBox->text () );
124
+ result.insert ( fieldIndex, aliasText );
140
125
}
126
+ }
141
127
}
142
- return result;
128
+ }
129
+ return result;
143
130
}
144
131
0 commit comments