Skip to content
Permalink
Browse files

layer comboboxes display proper layers as per topologyrule

  • Loading branch information
vinayan authored and jef-n committed Mar 26, 2013
1 parent 54303e3 commit 0e35f75438308bb6733307a765bcd9a34fc020cd
@@ -49,6 +49,7 @@ checkDock::checkDock( QgisInterface* qIface, QWidget* parent )
: QDockWidget( parent ), Ui::checkDock()
{
mTest = new topolTest( qIface );

setupUi( this );

// hide the fix-related stuff, needs more work
@@ -56,13 +56,16 @@ rulesDialog::rulesDialog( QList<QString> layerList, QMap<QString, TopologyRule>
// add layer ID to the layerId list
mLayerIds << layerList[i];

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

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

connect (mLayer1Box, SIGNAL( currentIndexChanged(const QString&) ),this, SLOT( updateRuleItems(const QString&) ) );

connect( mAddTestButton, SIGNAL( clicked() ), this, SLOT( addTest() ) );
connect( mAddTestButton, SIGNAL( clicked() ), mTestTable, SLOT( resizeColumnsToContents() ) );
// attempt to add new test when Ok clicked
@@ -169,11 +172,46 @@ void rulesDialog::projectRead()

void rulesDialog::showControls( const QString& testName )
{
mLayer2Box->setVisible( mTestConfMap[testName].useSecondLayer );
mLayer2Box->clear();
mLayer2Box->addItem("No layer");
TopologyRule topologyRule = mTestConfMap[testName];
QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();

if( topologyRule.useSecondLayer)
{
mLayer2Box->setVisible(true);
for(int i = 0; i < mLayerIds.count(); ++i)
{
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[mLayerIds.at(i)];

if ( v1->name() == mLayer1Box->currentText())
{
continue;
}

if( topologyRule.layer2AcceptsType( v1->geometryType()) )
{
mLayer2Box->addItem( v1->name());
}
}
}
else
{
mLayer2Box->setVisible(false);
}


if(topologyRule.useTolerance)
{
mToleranceBox->setVisible( true );
mToleranceLabel->setVisible( true );
}
else
{
mToleranceBox->setVisible( false );
mToleranceLabel->setVisible( false );
}

bool useTolerance = mTestConfMap[testName].useTolerance;
mToleranceBox->setVisible( useTolerance );
mToleranceLabel->setVisible( useTolerance );
}

void rulesDialog::addLayer( QgsMapLayer* layer )
@@ -272,3 +310,28 @@ void rulesDialog::deleteTest()
if ( 0 <= row && row < mTestTable->rowCount() )
mTestTable->removeRow( row );
}

void rulesDialog::updateRuleItems(const QString &layerName)
{
mTestBox->clear();

if( layerName == "No layer")
{
return;
}

QString layerId = mLayer1Box->itemData(mLayer1Box->currentIndex()).toString();

QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
QgsVectorLayer* vlayer= (QgsVectorLayer*)layerRegistry->mapLayers()[layerId];

for (QMap<QString, TopologyRule>::iterator it = mTestConfMap.begin(); it != mTestConfMap.end(); ++it)
{
TopologyRule rule = it.value();
if(rule.layer1AcceptsType(vlayer->geometryType()))
{
mTestBox->addItem(it.key());
}

}
}
@@ -95,6 +95,14 @@ class rulesDialog : public QDialog, public Ui::rulesDialog
* @param layerId layer ID
*/
void removeLayer( QString layerId );


/*
* Updates Rule combobox to mach first layer
* @param layerId layer ID
*/
void updateRuleItems( const QString& layerName);

};

#endif
@@ -59,13 +59,6 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="mTestBox">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mLayer1Box">
<property name="sizeAdjustPolicy">
@@ -78,6 +71,13 @@
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="mTestBox">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mLayer2Box">
<property name="sizeAdjustPolicy">
@@ -41,6 +41,7 @@ topolTest::topolTest( QgisInterface* qgsIface )
mTopologyRuleMap["must not have invalid geometries"].useSecondLayer = false;
mTopologyRuleMap["must not have invalid geometries"].useTolerance = false;
mTopologyRuleMap["must not have invalid geometries"].useSpatialIndex = false;
mTopologyRuleMap["must not have invalid geometries"].layer1SupportedTypes << QGis::Point << QGis::Polygon << QGis::Line;

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

mTopologyRuleMap["must not have duplicates"].f = &topolTest::checkDuplicates;
mTopologyRuleMap["must not have duplicates"].useTolerance = false;
mTopologyRuleMap["must not have duplicates"].useSecondLayer = false;
mTopologyRuleMap["must not have duplicates"].useSpatialIndex = true;
mTopologyRuleMap["must not have duplicates"].layer1SupportedTypes << QGis::Point << QGis::Polygon << QGis::Line;

mTopologyRuleMap["must not have pseudos"].f = &topolTest::checkPseudos;
mTopologyRuleMap["must not have pseudos"].useTolerance = false;
mTopologyRuleMap["must not have pseudos"].useSecondLayer = false;
mTopologyRuleMap["must not have pseudos"].useSpatialIndex = false;
mTopologyRuleMap["must not have pseudos"].layer1SupportedTypes << QGis::Line;

mTopologyRuleMap["must not overlap"].f = &topolTest::checkOverlaps;
mTopologyRuleMap["must not overlap"].useTolerance = false;
mTopologyRuleMap["must not overlap"].useSecondLayer = false;
mTopologyRuleMap["must not overlap"].useSpatialIndex = true;
mTopologyRuleMap["must not overlap"].layer1SupportedTypes << QGis::Polygon;

mTopologyRuleMap["must not have gaps"].f = &topolTest::checkGaps;
mTopologyRuleMap["must not have gaps"].useTolerance = false;
mTopologyRuleMap["must not have gaps"].useSecondLayer = false;
mTopologyRuleMap["must not have gaps"].useSpatialIndex = false;
mTopologyRuleMap["must not have gaps"].layer1SupportedTypes << QGis::Polygon;

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

// two layer tests
mTopologyRuleMap["must not overlap with"].f = &topolTest::checkOverlapWithLayer;
mTopologyRuleMap["must not overlap with"].useSecondLayer = true;
mTopologyRuleMap["must not overlap with"].useTolerance = false;
mTopologyRuleMap["must not overlap with"].useSpatialIndex = true;
mTopologyRuleMap["must not overlap with"].layer1SupportedTypes << QGis::Polygon;
mTopologyRuleMap["must not overlap with"].layer2SupportedTypes << QGis::Polygon;

mTopologyRuleMap["points must be covered by segments"].f = &topolTest::checkPointCoveredBySegment;
mTopologyRuleMap["points must be covered by segments"].useSecondLayer = true;
mTopologyRuleMap["points must be covered by segments"].useTolerance = false;
mTopologyRuleMap["points must be covered by segments"].useSpatialIndex = true;
mTopologyRuleMap["must be covered by"].f = &topolTest::checkPointCoveredBySegment;
mTopologyRuleMap["must be covered by"].useSecondLayer = true;
mTopologyRuleMap["must be covered by"].useTolerance = false;
mTopologyRuleMap["must be covered by"].useSpatialIndex = true;
mTopologyRuleMap["must be covered by"].layer1SupportedTypes << QGis::Point;
mTopologyRuleMap["must be covered by"].layer2SupportedTypes << QGis::Line << QGis::Polygon;

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

mTopologyRuleMap["Ponts must be covered by endpoints of line"].f = &topolTest::checkPointCoveredByLineEnds;
mTopologyRuleMap["Ponts must be covered by endpoints of line"].useSecondLayer = true;
mTopologyRuleMap["Ponts must be covered by endpoints of line"].useTolerance = false;
mTopologyRuleMap["Ponts must be covered by endpoints of line"].useSpatialIndex = true;

mTopologyRuleMap["Line ends must be covered by Points"].f = &topolTest::checkyLineEndsCoveredByPoints;
mTopologyRuleMap["Line ends must be covered by Points"].useSecondLayer = true;
mTopologyRuleMap["Line ends must be covered by Points"].useTolerance = false;
mTopologyRuleMap["Line ends must be covered by Points"].useSpatialIndex = true;

mTopologyRuleMap["Points must be inside polygon"].f = &topolTest::checkPointInPolygon;
mTopologyRuleMap["Points must be inside polygon"].useSecondLayer = true;
mTopologyRuleMap["Points must be inside polygon"].useTolerance = false;
mTopologyRuleMap["Points must be inside polygon"].useSpatialIndex = true;

mTopologyRuleMap["Polygon must contain point"].f = &topolTest::checkPolygonContainsPoint;
mTopologyRuleMap["Polygon must contain point"].useSecondLayer = true;
mTopologyRuleMap["Polygon must contain point"].useTolerance = false;
mTopologyRuleMap["Polygon must contain point"].useSpatialIndex = true;
mTopologyRuleMap["must be covered by endpoints of"].f = &topolTest::checkPointCoveredByLineEnds;
mTopologyRuleMap["must be covered by endpoints of"].useSecondLayer = true;
mTopologyRuleMap["must be covered by endpoints of"].useTolerance = false;
mTopologyRuleMap["must be covered by endpoints of"].useSpatialIndex = true;
mTopologyRuleMap["must be covered by endpoints of"].layer1SupportedTypes << QGis::Point;
mTopologyRuleMap["must be covered by endpoints of"].layer2SupportedTypes << QGis::Line;

mTopologyRuleMap["end points must be covered by"].f = &topolTest::checkyLineEndsCoveredByPoints;
mTopologyRuleMap["end points must be covered by"].useSecondLayer = true;
mTopologyRuleMap["end points must be covered by"].useTolerance = false;
mTopologyRuleMap["end points must be covered by"].useSpatialIndex = true;
mTopologyRuleMap["end points must be covered by"].layer1SupportedTypes << QGis::Line;
mTopologyRuleMap["end points must be covered by"].layer2SupportedTypes << QGis::Point;

mTopologyRuleMap["must be inside"].f = &topolTest::checkPointInPolygon;
mTopologyRuleMap["must be inside"].useSecondLayer = true;
mTopologyRuleMap["must be inside"].useTolerance = false;
mTopologyRuleMap["must be inside"].useSpatialIndex = true;
mTopologyRuleMap["must be inside"].layer1SupportedTypes << QGis::Point;
mTopologyRuleMap["must be inside"].layer2SupportedTypes << QGis::Polygon;

mTopologyRuleMap["must contain"].f = &topolTest::checkPolygonContainsPoint;
mTopologyRuleMap["must contain"].useSecondLayer = true;
mTopologyRuleMap["must contain"].useTolerance = false;
mTopologyRuleMap["must contain"].useSpatialIndex = true;
mTopologyRuleMap["must contain"].layer1SupportedTypes << QGis::Polygon;
mTopologyRuleMap["must contain"].layer2SupportedTypes << QGis::Point;



@@ -40,6 +40,37 @@ class TopologyRule
bool useSecondLayer;
bool useTolerance;
bool useSpatialIndex;
QList<QGis::GeometryType> layer1SupportedTypes;
QList<QGis::GeometryType> layer2SupportedTypes;

bool layer1AcceptsType(QGis::GeometryType type )
{
if (layer1SupportedTypes.contains(type))
{

return true;
}
else
{
return false;
}

}

bool layer2AcceptsType(QGis::GeometryType type )
{
if (layer2SupportedTypes.contains(type))
{

return true;
}
else
{
return false;
}

}

testFunction f;

/**
@@ -50,6 +81,7 @@ class TopologyRule
{
useSecondLayer = true;
useTolerance = false;

f = 0;
}
};

0 comments on commit 0e35f75

Please sign in to comment.
You can’t perform that action at this time.