Skip to content

Commit 0e35f75

Browse files
vinayanjef-n
authored andcommitted
layer comboboxes display proper layers as per topologyrule
1 parent 54303e3 commit 0e35f75

File tree

6 files changed

+160
-37
lines changed

6 files changed

+160
-37
lines changed

src/plugins/topology/checkDock.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ checkDock::checkDock( QgisInterface* qIface, QWidget* parent )
4949
: QDockWidget( parent ), Ui::checkDock()
5050
{
5151
mTest = new topolTest( qIface );
52+
5253
setupUi( this );
5354

5455
// hide the fix-related stuff, needs more work

src/plugins/topology/rulesDialog.cpp

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,16 @@ rulesDialog::rulesDialog( QList<QString> layerList, QMap<QString, TopologyRule>
5656
// add layer ID to the layerId list
5757
mLayerIds << layerList[i];
5858

59-
//QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]];
59+
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]];
60+
qDebug() << "layerid = " + layerList[i];
6061

6162
// add layer name to the layer combo boxes
62-
mLayer1Box->addItem((( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]] )->name() );
63-
mLayer2Box->addItem((( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]] )->name() );
63+
mLayer1Box->addItem( v1->name(), v1->id() );
64+
//mLayer2Box->addItem((( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]] )->name() );
6465
}
6566

67+
connect (mLayer1Box, SIGNAL( currentIndexChanged(const QString&) ),this, SLOT( updateRuleItems(const QString&) ) );
68+
6669
connect( mAddTestButton, SIGNAL( clicked() ), this, SLOT( addTest() ) );
6770
connect( mAddTestButton, SIGNAL( clicked() ), mTestTable, SLOT( resizeColumnsToContents() ) );
6871
// attempt to add new test when Ok clicked
@@ -169,11 +172,46 @@ void rulesDialog::projectRead()
169172

170173
void rulesDialog::showControls( const QString& testName )
171174
{
172-
mLayer2Box->setVisible( mTestConfMap[testName].useSecondLayer );
175+
mLayer2Box->clear();
176+
mLayer2Box->addItem("No layer");
177+
TopologyRule topologyRule = mTestConfMap[testName];
178+
QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
179+
180+
if( topologyRule.useSecondLayer)
181+
{
182+
mLayer2Box->setVisible(true);
183+
for(int i = 0; i < mLayerIds.count(); ++i)
184+
{
185+
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[mLayerIds.at(i)];
186+
187+
if ( v1->name() == mLayer1Box->currentText())
188+
{
189+
continue;
190+
}
191+
192+
if( topologyRule.layer2AcceptsType( v1->geometryType()) )
193+
{
194+
mLayer2Box->addItem( v1->name());
195+
}
196+
}
197+
}
198+
else
199+
{
200+
mLayer2Box->setVisible(false);
201+
}
202+
203+
204+
if(topologyRule.useTolerance)
205+
{
206+
mToleranceBox->setVisible( true );
207+
mToleranceLabel->setVisible( true );
208+
}
209+
else
210+
{
211+
mToleranceBox->setVisible( false );
212+
mToleranceLabel->setVisible( false );
213+
}
173214

174-
bool useTolerance = mTestConfMap[testName].useTolerance;
175-
mToleranceBox->setVisible( useTolerance );
176-
mToleranceLabel->setVisible( useTolerance );
177215
}
178216

179217
void rulesDialog::addLayer( QgsMapLayer* layer )
@@ -272,3 +310,28 @@ void rulesDialog::deleteTest()
272310
if ( 0 <= row && row < mTestTable->rowCount() )
273311
mTestTable->removeRow( row );
274312
}
313+
314+
void rulesDialog::updateRuleItems(const QString &layerName)
315+
{
316+
mTestBox->clear();
317+
318+
if( layerName == "No layer")
319+
{
320+
return;
321+
}
322+
323+
QString layerId = mLayer1Box->itemData(mLayer1Box->currentIndex()).toString();
324+
325+
QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
326+
QgsVectorLayer* vlayer= (QgsVectorLayer*)layerRegistry->mapLayers()[layerId];
327+
328+
for (QMap<QString, TopologyRule>::iterator it = mTestConfMap.begin(); it != mTestConfMap.end(); ++it)
329+
{
330+
TopologyRule rule = it.value();
331+
if(rule.layer1AcceptsType(vlayer->geometryType()))
332+
{
333+
mTestBox->addItem(it.key());
334+
}
335+
336+
}
337+
}

src/plugins/topology/rulesDialog.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ class rulesDialog : public QDialog, public Ui::rulesDialog
9595
* @param layerId layer ID
9696
*/
9797
void removeLayer( QString layerId );
98+
99+
100+
/*
101+
* Updates Rule combobox to mach first layer
102+
* @param layerId layer ID
103+
*/
104+
void updateRuleItems( const QString& layerName);
105+
98106
};
99107

100108
#endif

src/plugins/topology/rulesDialog.ui

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@
5959
</item>
6060
<item>
6161
<layout class="QHBoxLayout" name="horizontalLayout">
62-
<item>
63-
<widget class="QComboBox" name="mTestBox">
64-
<property name="sizeAdjustPolicy">
65-
<enum>QComboBox::AdjustToContents</enum>
66-
</property>
67-
</widget>
68-
</item>
6962
<item>
7063
<widget class="QComboBox" name="mLayer1Box">
7164
<property name="sizeAdjustPolicy">
@@ -78,6 +71,13 @@
7871
</item>
7972
</widget>
8073
</item>
74+
<item>
75+
<widget class="QComboBox" name="mTestBox">
76+
<property name="sizeAdjustPolicy">
77+
<enum>QComboBox::AdjustToContents</enum>
78+
</property>
79+
</widget>
80+
</item>
8181
<item>
8282
<widget class="QComboBox" name="mLayer2Box">
8383
<property name="sizeAdjustPolicy">

src/plugins/topology/topolTest.cpp

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ topolTest::topolTest( QgisInterface* qgsIface )
4141
mTopologyRuleMap["must not have invalid geometries"].useSecondLayer = false;
4242
mTopologyRuleMap["must not have invalid geometries"].useTolerance = false;
4343
mTopologyRuleMap["must not have invalid geometries"].useSpatialIndex = false;
44+
mTopologyRuleMap["must not have invalid geometries"].layer1SupportedTypes << QGis::Point << QGis::Polygon << QGis::Line;
4445

4546
//mTopologyRuleMap["segments must have minimum length"].f = &topolTest::checkSegmentLength;
4647
//mTopologyRuleMap["segments must have minimum length"].useTolerance = true;
@@ -51,67 +52,85 @@ topolTest::topolTest( QgisInterface* qgsIface )
5152
mTopologyRuleMap["must not have dangles"].useSecondLayer = false;
5253
mTopologyRuleMap["must not have dangles"].useTolerance = false;
5354
mTopologyRuleMap["must not have dangles"].useSpatialIndex = false;
55+
mTopologyRuleMap["must not have dangles"].layer1SupportedTypes << QGis::Line;
5456

5557
mTopologyRuleMap["must not have duplicates"].f = &topolTest::checkDuplicates;
5658
mTopologyRuleMap["must not have duplicates"].useTolerance = false;
5759
mTopologyRuleMap["must not have duplicates"].useSecondLayer = false;
5860
mTopologyRuleMap["must not have duplicates"].useSpatialIndex = true;
61+
mTopologyRuleMap["must not have duplicates"].layer1SupportedTypes << QGis::Point << QGis::Polygon << QGis::Line;
5962

6063
mTopologyRuleMap["must not have pseudos"].f = &topolTest::checkPseudos;
6164
mTopologyRuleMap["must not have pseudos"].useTolerance = false;
6265
mTopologyRuleMap["must not have pseudos"].useSecondLayer = false;
6366
mTopologyRuleMap["must not have pseudos"].useSpatialIndex = false;
67+
mTopologyRuleMap["must not have pseudos"].layer1SupportedTypes << QGis::Line;
6468

6569
mTopologyRuleMap["must not overlap"].f = &topolTest::checkOverlaps;
6670
mTopologyRuleMap["must not overlap"].useTolerance = false;
6771
mTopologyRuleMap["must not overlap"].useSecondLayer = false;
6872
mTopologyRuleMap["must not overlap"].useSpatialIndex = true;
73+
mTopologyRuleMap["must not overlap"].layer1SupportedTypes << QGis::Polygon;
6974

7075
mTopologyRuleMap["must not have gaps"].f = &topolTest::checkGaps;
7176
mTopologyRuleMap["must not have gaps"].useTolerance = false;
7277
mTopologyRuleMap["must not have gaps"].useSecondLayer = false;
7378
mTopologyRuleMap["must not have gaps"].useSpatialIndex = false;
79+
mTopologyRuleMap["must not have gaps"].layer1SupportedTypes << QGis::Polygon;
7480

7581
mTopologyRuleMap["Must not have multi-part geometries"].f = &topolTest::checkMultipart;
7682
mTopologyRuleMap["Must not have multi-part geometries"].useSecondLayer = false;
7783
mTopologyRuleMap["Must not have multi-part geometries"].useTolerance = false;
7884
mTopologyRuleMap["Must not have multi-part geometries"].useSpatialIndex = false;
85+
mTopologyRuleMap["Must not have multi-part geometries"].layer1SupportedTypes << QGis::Point << QGis::Polygon << QGis::Line;
7986

8087
// two layer tests
8188
mTopologyRuleMap["must not overlap with"].f = &topolTest::checkOverlapWithLayer;
8289
mTopologyRuleMap["must not overlap with"].useSecondLayer = true;
8390
mTopologyRuleMap["must not overlap with"].useTolerance = false;
8491
mTopologyRuleMap["must not overlap with"].useSpatialIndex = true;
92+
mTopologyRuleMap["must not overlap with"].layer1SupportedTypes << QGis::Polygon;
93+
mTopologyRuleMap["must not overlap with"].layer2SupportedTypes << QGis::Polygon;
8594

86-
mTopologyRuleMap["points must be covered by segments"].f = &topolTest::checkPointCoveredBySegment;
87-
mTopologyRuleMap["points must be covered by segments"].useSecondLayer = true;
88-
mTopologyRuleMap["points must be covered by segments"].useTolerance = false;
89-
mTopologyRuleMap["points must be covered by segments"].useSpatialIndex = true;
95+
mTopologyRuleMap["must be covered by"].f = &topolTest::checkPointCoveredBySegment;
96+
mTopologyRuleMap["must be covered by"].useSecondLayer = true;
97+
mTopologyRuleMap["must be covered by"].useTolerance = false;
98+
mTopologyRuleMap["must be covered by"].useSpatialIndex = true;
99+
mTopologyRuleMap["must be covered by"].layer1SupportedTypes << QGis::Point;
100+
mTopologyRuleMap["must be covered by"].layer2SupportedTypes << QGis::Line << QGis::Polygon;
90101

91102
//mTopologyRuleMap["features must not be closer than tolerance"].f = &topolTest::checkCloseFeature;
92103
//mTopologyRuleMap["features must not be closer than tolerance"].useSecondLayer = true;
93104
//mTopologyRuleMap["features must not be closer than tolerance"].useTolerance = false;
94105
//mTopologyRuleMap["features must not be closer than tolerance"].useSpatialIndex = false;
95106

96-
mTopologyRuleMap["Ponts must be covered by endpoints of line"].f = &topolTest::checkPointCoveredByLineEnds;
97-
mTopologyRuleMap["Ponts must be covered by endpoints of line"].useSecondLayer = true;
98-
mTopologyRuleMap["Ponts must be covered by endpoints of line"].useTolerance = false;
99-
mTopologyRuleMap["Ponts must be covered by endpoints of line"].useSpatialIndex = true;
100-
101-
mTopologyRuleMap["Line ends must be covered by Points"].f = &topolTest::checkyLineEndsCoveredByPoints;
102-
mTopologyRuleMap["Line ends must be covered by Points"].useSecondLayer = true;
103-
mTopologyRuleMap["Line ends must be covered by Points"].useTolerance = false;
104-
mTopologyRuleMap["Line ends must be covered by Points"].useSpatialIndex = true;
105-
106-
mTopologyRuleMap["Points must be inside polygon"].f = &topolTest::checkPointInPolygon;
107-
mTopologyRuleMap["Points must be inside polygon"].useSecondLayer = true;
108-
mTopologyRuleMap["Points must be inside polygon"].useTolerance = false;
109-
mTopologyRuleMap["Points must be inside polygon"].useSpatialIndex = true;
110-
111-
mTopologyRuleMap["Polygon must contain point"].f = &topolTest::checkPolygonContainsPoint;
112-
mTopologyRuleMap["Polygon must contain point"].useSecondLayer = true;
113-
mTopologyRuleMap["Polygon must contain point"].useTolerance = false;
114-
mTopologyRuleMap["Polygon must contain point"].useSpatialIndex = true;
107+
mTopologyRuleMap["must be covered by endpoints of"].f = &topolTest::checkPointCoveredByLineEnds;
108+
mTopologyRuleMap["must be covered by endpoints of"].useSecondLayer = true;
109+
mTopologyRuleMap["must be covered by endpoints of"].useTolerance = false;
110+
mTopologyRuleMap["must be covered by endpoints of"].useSpatialIndex = true;
111+
mTopologyRuleMap["must be covered by endpoints of"].layer1SupportedTypes << QGis::Point;
112+
mTopologyRuleMap["must be covered by endpoints of"].layer2SupportedTypes << QGis::Line;
113+
114+
mTopologyRuleMap["end points must be covered by"].f = &topolTest::checkyLineEndsCoveredByPoints;
115+
mTopologyRuleMap["end points must be covered by"].useSecondLayer = true;
116+
mTopologyRuleMap["end points must be covered by"].useTolerance = false;
117+
mTopologyRuleMap["end points must be covered by"].useSpatialIndex = true;
118+
mTopologyRuleMap["end points must be covered by"].layer1SupportedTypes << QGis::Line;
119+
mTopologyRuleMap["end points must be covered by"].layer2SupportedTypes << QGis::Point;
120+
121+
mTopologyRuleMap["must be inside"].f = &topolTest::checkPointInPolygon;
122+
mTopologyRuleMap["must be inside"].useSecondLayer = true;
123+
mTopologyRuleMap["must be inside"].useTolerance = false;
124+
mTopologyRuleMap["must be inside"].useSpatialIndex = true;
125+
mTopologyRuleMap["must be inside"].layer1SupportedTypes << QGis::Point;
126+
mTopologyRuleMap["must be inside"].layer2SupportedTypes << QGis::Polygon;
127+
128+
mTopologyRuleMap["must contain"].f = &topolTest::checkPolygonContainsPoint;
129+
mTopologyRuleMap["must contain"].useSecondLayer = true;
130+
mTopologyRuleMap["must contain"].useTolerance = false;
131+
mTopologyRuleMap["must contain"].useSpatialIndex = true;
132+
mTopologyRuleMap["must contain"].layer1SupportedTypes << QGis::Polygon;
133+
mTopologyRuleMap["must contain"].layer2SupportedTypes << QGis::Point;
115134

116135

117136

src/plugins/topology/topolTest.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,37 @@ class TopologyRule
4040
bool useSecondLayer;
4141
bool useTolerance;
4242
bool useSpatialIndex;
43+
QList<QGis::GeometryType> layer1SupportedTypes;
44+
QList<QGis::GeometryType> layer2SupportedTypes;
45+
46+
bool layer1AcceptsType(QGis::GeometryType type )
47+
{
48+
if (layer1SupportedTypes.contains(type))
49+
{
50+
51+
return true;
52+
}
53+
else
54+
{
55+
return false;
56+
}
57+
58+
}
59+
60+
bool layer2AcceptsType(QGis::GeometryType type )
61+
{
62+
if (layer2SupportedTypes.contains(type))
63+
{
64+
65+
return true;
66+
}
67+
else
68+
{
69+
return false;
70+
}
71+
72+
}
73+
4374
testFunction f;
4475

4576
/**
@@ -50,6 +81,7 @@ class TopologyRule
5081
{
5182
useSecondLayer = true;
5283
useTolerance = false;
84+
5385
f = 0;
5486
}
5587
};

0 commit comments

Comments
 (0)