@@ -42,15 +42,15 @@ void QgsDbTableModel::addTableEntry(QString type, QString schemaName, QString ta
42
42
43
43
// there is already an item for this schema
44
44
if (schemaItems.size () > 0 )
45
- {
46
- schemaItem = schemaItems.at (0 );
47
- }
45
+ {
46
+ schemaItem = schemaItems.at (0 );
47
+ }
48
48
else // create a new toplevel item for this schema
49
- {
50
- schemaItem = new QStandardItem (schemaName);
51
- schemaItem->setFlags (Qt::ItemIsEnabled);
52
- invisibleRootItem ()->setChild (invisibleRootItem ()->rowCount (), schemaItem);
53
- }
49
+ {
50
+ schemaItem = new QStandardItem (schemaName);
51
+ schemaItem->setFlags (Qt::ItemIsEnabled);
52
+ invisibleRootItem ()->setChild (invisibleRootItem ()->rowCount (), schemaItem);
53
+ }
54
54
55
55
// path to icon for specified type
56
56
QString myThemePath = QgsApplication::themePath ();
@@ -86,27 +86,27 @@ void QgsDbTableModel::addTableEntry(QString type, QString schemaName, QString ta
86
86
void QgsDbTableModel::setSql (const QModelIndex& index, const QString& sql)
87
87
{
88
88
if (!index.isValid () || !index.parent ().isValid ())
89
- {
90
- return ;
91
- }
89
+ {
90
+ return ;
91
+ }
92
92
93
93
// find out schema name and table name
94
94
QModelIndex schemaSibling = index.sibling (index.row (), 0 );
95
95
QModelIndex tableSibling = index.sibling (index.row (), 1 );
96
-
96
+
97
97
if (!schemaSibling.isValid () || !tableSibling.isValid ())
98
- {
99
- return ;
100
- }
98
+ {
99
+ return ;
100
+ }
101
101
102
102
QString schemaName = itemFromIndex (schemaSibling)->text ();
103
103
QString tableName = itemFromIndex (tableSibling)->text ();
104
104
105
105
QList<QStandardItem*> schemaItems = findItems (schemaName, Qt::MatchExactly, 0 );
106
106
if (schemaItems.size () < 1 )
107
- {
108
- return ;
109
- }
107
+ {
108
+ return ;
109
+ }
110
110
111
111
QStandardItem* schemaItem = schemaItems.at (0 );
112
112
int numChildren = schemaItem->rowCount ();
@@ -115,28 +115,28 @@ void QgsDbTableModel::setSql(const QModelIndex& index, const QString& sql)
115
115
QModelIndex currentTableIndex;
116
116
117
117
for (int i = 0 ; i < numChildren; ++i)
118
+ {
119
+ currentChildIndex = indexFromItem (schemaItem->child (i, 0 ));
120
+ if (!currentChildIndex.isValid ())
118
121
{
119
- currentChildIndex = indexFromItem (schemaItem->child (i, 0 ));
120
- if (!currentChildIndex.isValid ())
121
- {
122
- continue ;
123
- }
124
- currentTableIndex = currentChildIndex.sibling (i, 1 );
125
- if (!currentTableIndex.isValid ())
126
- {
127
- continue ;
128
- }
129
-
130
- if (itemFromIndex (currentTableIndex)->text () == tableName)
131
- {
132
- QModelIndex sqlIndex = currentChildIndex.sibling (i, 4 );
133
- if (sqlIndex.isValid ())
134
- {
135
- itemFromIndex (sqlIndex)->setText (sql);
136
- break ;
137
- }
138
- }
122
+ continue ;
139
123
}
124
+ currentTableIndex = currentChildIndex.sibling (i, 1 );
125
+ if (!currentTableIndex.isValid ())
126
+ {
127
+ continue ;
128
+ }
129
+
130
+ if (itemFromIndex (currentTableIndex)->text () == tableName)
131
+ {
132
+ QModelIndex sqlIndex = currentChildIndex.sibling (i, 4 );
133
+ if (sqlIndex.isValid ())
134
+ {
135
+ itemFromIndex (sqlIndex)->setText (sql);
136
+ break ;
137
+ }
138
+ }
139
+ }
140
140
}
141
141
142
142
void QgsDbTableModel::setGeometryTypesForTable (const QString& schema, const QString& table, const QString& attribute, const QString& type)
@@ -149,9 +149,9 @@ void QgsDbTableModel::setGeometryTypesForTable(const QString& schema, const QStr
149
149
QList<QStandardItem*> schemaItems = findItems (schema, Qt::MatchExactly, 0 );
150
150
151
151
if (schemaItems.size () < 1 )
152
- {
153
- return ;
154
- }
152
+ {
153
+ return ;
154
+ }
155
155
schemaItem = schemaItems.at (0 );
156
156
int numChildren = schemaItem->rowCount ();
157
157
@@ -161,124 +161,124 @@ void QgsDbTableModel::setGeometryTypesForTable(const QString& schema, const QStr
161
161
QModelIndex currentGeomColumnIndex;
162
162
163
163
for (int i = 0 ; i < numChildren; ++i)
164
+ {
165
+ currentChildIndex = indexFromItem (schemaItem->child (i, 0 ));
166
+ if (!currentChildIndex.isValid ())
167
+ {
168
+ continue ;
169
+ }
170
+ currentTableIndex = currentChildIndex.sibling (i, 1 );
171
+ currentTypeIndex = currentChildIndex.sibling (i, 2 );
172
+ currentGeomColumnIndex = currentChildIndex.sibling (i, 3 );
173
+ QString geomColText = itemFromIndex (currentGeomColumnIndex)->text ();
174
+
175
+ if (!currentTypeIndex.isValid () || !currentTableIndex.isValid () || !currentGeomColumnIndex.isValid ())
164
176
{
165
- currentChildIndex = indexFromItem (schemaItem->child (i, 0 ));
166
- if (!currentChildIndex.isValid ())
167
- {
168
- continue ;
169
- }
170
- currentTableIndex = currentChildIndex.sibling (i, 1 );
171
- currentTypeIndex = currentChildIndex.sibling (i, 2 );
172
- currentGeomColumnIndex = currentChildIndex.sibling (i, 3 );
173
- QString geomColText = itemFromIndex (currentGeomColumnIndex)->text ();
174
-
175
- if (!currentTypeIndex.isValid () || !currentTableIndex.isValid () || !currentGeomColumnIndex.isValid ())
176
- {
177
- continue ;
178
- }
179
-
180
- if (itemFromIndex (currentTableIndex)->text () == table)
181
- {
182
- if (typeIsEmpty)
183
- {
184
- removeRow (i, indexFromItem (schemaItem));
185
- return ;
186
- }
187
- for (int j = 0 ; j < typeList.size (); ++j)
188
- {
189
- if (j == 0 )
190
- {
191
- QGis::WKBTYPE wkbType = qgisTypeFromDbType (typeList.at (0 ));
192
- QString iconPath = iconFilePathForType (wkbType);
193
- itemFromIndex (currentTypeIndex)->setText (typeList.at (0 )); // todo: add other rows
194
- itemFromIndex (currentTypeIndex)->setIcon (QIcon (iconPath));
195
- if (!geomColText.contains (" AS" ))
196
- {
197
- itemFromIndex (currentGeomColumnIndex)->setText (geomColText + " AS " + typeList.at (0 ));
198
- }
199
- }
200
- else
201
- {
202
- // todo: add correct type
203
- addTableEntry (typeList.at (j), schema, table, geomColText + " AS " + typeList.at (j), " " );
204
- }
205
- }
206
- }
177
+ continue ;
207
178
}
179
+
180
+ if (itemFromIndex (currentTableIndex)->text () == table)
181
+ {
182
+ if (typeIsEmpty)
183
+ {
184
+ removeRow (i, indexFromItem (schemaItem));
185
+ return ;
186
+ }
187
+ for (int j = 0 ; j < typeList.size (); ++j)
188
+ {
189
+ if ( j==0 )
190
+ {
191
+ QGis::WKBTYPE wkbType = qgisTypeFromDbType (typeList.at (0 ));
192
+ QString iconPath = iconFilePathForType (wkbType);
193
+ itemFromIndex (currentTypeIndex)->setText (typeList.at (0 )); // todo: add other rows
194
+ itemFromIndex (currentTypeIndex)->setIcon (QIcon (iconPath));
195
+ if (!geomColText.contains (" AS " ))
196
+ {
197
+ itemFromIndex (currentGeomColumnIndex)->setText (geomColText + " AS " + typeList.at (0 ));
198
+ }
199
+ }
200
+ else
201
+ {
202
+ // todo: add correct type
203
+ addTableEntry (typeList.at (j), schema, table, geomColText + " AS " + typeList.at (j), " " );
204
+ }
205
+ }
206
+ }
207
+ }
208
208
}
209
209
210
210
QString QgsDbTableModel::iconFilePathForType (QGis::WKBTYPE type) const
211
211
{
212
212
QString myThemePath = QgsApplication::themePath ();
213
213
if (type == QGis::WKBPoint || type == QGis::WKBPoint25D || type == QGis::WKBMultiPoint || type == QGis::WKBMultiPoint25D)
214
- {
215
- return myThemePath+" /mIconPointLayer.png" ;
216
- }
214
+ {
215
+ return myThemePath+" /mIconPointLayer.png" ;
216
+ }
217
217
else if (type == QGis::WKBLineString || type == QGis::WKBLineString25D || type == QGis::WKBMultiLineString || type == QGis::WKBMultiLineString25D)
218
- {
219
- return myThemePath+" /mIconLineLayer.png" ;
220
- }
218
+ {
219
+ return myThemePath+" /mIconLineLayer.png" ;
220
+ }
221
221
else if (type == QGis::WKBPolygon || type == QGis::WKBPolygon25D || type == QGis::WKBMultiPolygon || type == QGis::WKBMultiPolygon25D)
222
- {
223
- return myThemePath+" /mIconPolygonLayer.png" ;
224
- }
222
+ {
223
+ return myThemePath+" /mIconPolygonLayer.png" ;
224
+ }
225
225
else return " " ;
226
226
}
227
227
228
228
QString QgsDbTableModel::displayStringForType (QGis::WKBTYPE type) const
229
229
{
230
230
if (type == QGis::WKBPoint || type == QGis::WKBPoint25D)
231
- {
232
- return tr (" Point" );
233
- }
231
+ {
232
+ return tr (" Point" );
233
+ }
234
234
else if (type == QGis::WKBMultiPoint || type == QGis::WKBMultiPoint25D)
235
- {
236
- return tr (" Multipoint" );
237
- }
235
+ {
236
+ return tr (" Multipoint" );
237
+ }
238
238
else if (type == QGis::WKBLineString || type == QGis::WKBLineString25D)
239
- {
240
- return tr (" Line" );
241
- }
239
+ {
240
+ return tr (" Line" );
241
+ }
242
242
else if (type == QGis::WKBMultiLineString || type == QGis::WKBMultiLineString25D)
243
- {
244
- return tr (" Multiline" );
245
- }
243
+ {
244
+ return tr (" Multiline" );
245
+ }
246
246
else if (type == QGis::WKBPolygon || type == QGis::WKBPolygon25D)
247
- {
248
- return tr (" Polygon" );
249
- }
247
+ {
248
+ return tr (" Polygon" );
249
+ }
250
250
else if (type == QGis::WKBMultiPolygon || type == QGis::WKBMultiPolygon25D)
251
- {
252
- return tr (" Multipolygon" );
253
- }
251
+ {
252
+ return tr (" Multipolygon" );
253
+ }
254
254
return " Unknown" ;
255
255
}
256
256
257
257
QGis::WKBTYPE QgsDbTableModel::qgisTypeFromDbType (const QString& dbType) const
258
258
{
259
- if (dbType == " POINT" )
260
- {
261
- return QGis::WKBPoint;
262
- }
259
+ if (dbType == " POINT" )
260
+ {
261
+ return QGis::WKBPoint;
262
+ }
263
263
else if (dbType == " MULTIPOINT" )
264
- {
265
- return QGis::WKBMultiPoint;
266
- }
264
+ {
265
+ return QGis::WKBMultiPoint;
266
+ }
267
267
else if (dbType == " LINESTRING" )
268
- {
269
- return QGis::WKBLineString;
270
- }
268
+ {
269
+ return QGis::WKBLineString;
270
+ }
271
271
else if (dbType == " MULTILINESTRING" )
272
- {
273
- return QGis::WKBMultiLineString;
274
- }
272
+ {
273
+ return QGis::WKBMultiLineString;
274
+ }
275
275
else if (dbType == " POLYGON" )
276
- {
277
- return QGis::WKBPolygon;
278
- }
276
+ {
277
+ return QGis::WKBPolygon;
278
+ }
279
279
else if (dbType == " MULTIPOLYGON" )
280
- {
281
- return QGis::WKBMultiPolygon;
282
- }
280
+ {
281
+ return QGis::WKBMultiPolygon;
282
+ }
283
283
return QGis::WKBUnknown;
284
284
}
0 commit comments