Skip to content

Commit 20d79c5

Browse files

File tree

1 file changed

+129
-129
lines changed

1 file changed

+129
-129
lines changed
 

‎src/app/qgsdbtablemodel.cpp

Lines changed: 129 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ void QgsDbTableModel::addTableEntry(QString type, QString schemaName, QString ta
4242

4343
//there is already an item for this schema
4444
if(schemaItems.size() > 0)
45-
{
46-
schemaItem = schemaItems.at(0);
47-
}
45+
{
46+
schemaItem = schemaItems.at(0);
47+
}
4848
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+
}
5454

5555
//path to icon for specified type
5656
QString myThemePath = QgsApplication::themePath();
@@ -86,27 +86,27 @@ void QgsDbTableModel::addTableEntry(QString type, QString schemaName, QString ta
8686
void QgsDbTableModel::setSql(const QModelIndex& index, const QString& sql)
8787
{
8888
if(!index.isValid() || !index.parent().isValid())
89-
{
90-
return;
91-
}
89+
{
90+
return;
91+
}
9292

9393
//find out schema name and table name
9494
QModelIndex schemaSibling = index.sibling(index.row(), 0);
9595
QModelIndex tableSibling = index.sibling(index.row(), 1);
96-
96+
9797
if(!schemaSibling.isValid() || !tableSibling.isValid())
98-
{
99-
return;
100-
}
98+
{
99+
return;
100+
}
101101

102102
QString schemaName = itemFromIndex(schemaSibling)->text();
103103
QString tableName = itemFromIndex(tableSibling)->text();
104104

105105
QList<QStandardItem*> schemaItems = findItems(schemaName, Qt::MatchExactly, 0);
106106
if(schemaItems.size() < 1)
107-
{
108-
return;
109-
}
107+
{
108+
return;
109+
}
110110

111111
QStandardItem* schemaItem = schemaItems.at(0);
112112
int numChildren = schemaItem->rowCount();
@@ -115,28 +115,28 @@ void QgsDbTableModel::setSql(const QModelIndex& index, const QString& sql)
115115
QModelIndex currentTableIndex;
116116

117117
for(int i = 0; i < numChildren; ++i)
118+
{
119+
currentChildIndex = indexFromItem(schemaItem->child(i, 0));
120+
if(!currentChildIndex.isValid())
118121
{
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;
139123
}
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+
}
140140
}
141141

142142
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
149149
QList<QStandardItem*> schemaItems = findItems(schema, Qt::MatchExactly, 0);
150150

151151
if(schemaItems.size() < 1)
152-
{
153-
return;
154-
}
152+
{
153+
return;
154+
}
155155
schemaItem = schemaItems.at(0);
156156
int numChildren = schemaItem->rowCount();
157157

@@ -161,124 +161,124 @@ void QgsDbTableModel::setGeometryTypesForTable(const QString& schema, const QStr
161161
QModelIndex currentGeomColumnIndex;
162162

163163
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())
164176
{
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;
207178
}
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+
}
208208
}
209209

210210
QString QgsDbTableModel::iconFilePathForType(QGis::WKBTYPE type) const
211211
{
212212
QString myThemePath = QgsApplication::themePath();
213213
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+
}
217217
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+
}
221221
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+
}
225225
else return "";
226226
}
227227

228228
QString QgsDbTableModel::displayStringForType(QGis::WKBTYPE type) const
229229
{
230230
if(type == QGis::WKBPoint || type == QGis::WKBPoint25D)
231-
{
232-
return tr("Point");
233-
}
231+
{
232+
return tr("Point");
233+
}
234234
else if(type == QGis::WKBMultiPoint || type == QGis::WKBMultiPoint25D)
235-
{
236-
return tr("Multipoint");
237-
}
235+
{
236+
return tr("Multipoint");
237+
}
238238
else if(type == QGis::WKBLineString || type == QGis::WKBLineString25D)
239-
{
240-
return tr("Line");
241-
}
239+
{
240+
return tr("Line");
241+
}
242242
else if(type == QGis::WKBMultiLineString || type == QGis::WKBMultiLineString25D)
243-
{
244-
return tr("Multiline");
245-
}
243+
{
244+
return tr("Multiline");
245+
}
246246
else if(type == QGis::WKBPolygon || type == QGis::WKBPolygon25D)
247-
{
248-
return tr("Polygon");
249-
}
247+
{
248+
return tr("Polygon");
249+
}
250250
else if(type == QGis::WKBMultiPolygon || type == QGis::WKBMultiPolygon25D)
251-
{
252-
return tr("Multipolygon");
253-
}
251+
{
252+
return tr("Multipolygon");
253+
}
254254
return "Unknown";
255255
}
256256

257257
QGis::WKBTYPE QgsDbTableModel::qgisTypeFromDbType(const QString& dbType) const
258258
{
259-
if(dbType == "POINT")
260-
{
261-
return QGis::WKBPoint;
262-
}
259+
if(dbType == "POINT")
260+
{
261+
return QGis::WKBPoint;
262+
}
263263
else if(dbType == "MULTIPOINT")
264-
{
265-
return QGis::WKBMultiPoint;
266-
}
264+
{
265+
return QGis::WKBMultiPoint;
266+
}
267267
else if(dbType == "LINESTRING")
268-
{
269-
return QGis::WKBLineString;
270-
}
268+
{
269+
return QGis::WKBLineString;
270+
}
271271
else if(dbType == "MULTILINESTRING")
272-
{
273-
return QGis::WKBMultiLineString;
274-
}
272+
{
273+
return QGis::WKBMultiLineString;
274+
}
275275
else if(dbType == "POLYGON")
276-
{
277-
return QGis::WKBPolygon;
278-
}
276+
{
277+
return QGis::WKBPolygon;
278+
}
279279
else if(dbType == "MULTIPOLYGON")
280-
{
281-
return QGis::WKBMultiPolygon;
282-
}
280+
{
281+
return QGis::WKBMultiPolygon;
282+
}
283283
return QGis::WKBUnknown;
284284
}

0 commit comments

Comments
 (0)
Please sign in to comment.