Permalink
Browse files

using qtableview instead of listwidget for listing topology errors

  • Loading branch information...
1 parent baf6980 commit 2aa8f97f5021fd3b1b2a8bf3a2151337e1d5624d weetya committed Jul 16, 2009
Showing with 206 additions and 18 deletions.
  1. +2 −0 CMakeLists.txt
  2. +31 −17 checkDock.cpp
  3. +2 −0 checkDock.h
  4. +1 −1 checkDock.ui
  5. +121 −0 dockModel.cpp
  6. +49 −0 dockModel.h
View
@@ -8,6 +8,7 @@ SET (topol_SRCS
checkDock.cpp
topolError.cpp
topolTest.cpp
+ dockModel.cpp
)
SET (topol_UIS
@@ -20,6 +21,7 @@ SET (topol_MOC_HDRS
rulesDialog.h
checkDock.h
topolTest.h
+ dockModel.h
)
SET (topol_RCCS topol.qrc)
View
@@ -38,6 +38,7 @@
#include "topolTest.h"
#include "rulesDialog.h"
+#include "dockModel.h"
class QgisInterface;
@@ -46,6 +47,11 @@ checkDock::checkDock(const QString &tableName, QgisInterface* qIface, QWidget* p
: QDockWidget(parent), Ui::checkDock()
{
setupUi(this);
+ mErrorListModel = new DockModel(mErrorList, parent);
+ mErrorTableView->setModel(mErrorListModel);
+ mErrorTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ //mErrorTableView->setHorizontalHeader();
+ mErrorTableView->verticalHeader()->setDefaultSectionSize( 20 );
mLayerRegistry = QgsMapLayerRegistry::instance();
mConfigureDialog = new rulesDialog("Rules", mLayerRegistry->mapLayers().keys(), mTest.testMap(), qIface, parent);
@@ -75,7 +81,7 @@ checkDock::checkDock(const QString &tableName, QgisInterface* qIface, QWidget* p
connect(mValidateExtentButton, SIGNAL(clicked()), this, SLOT(validateExtent()));
connect(mFixButton, SIGNAL(clicked()), this, SLOT(fix()));
- connect(mErrorListView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(errorListClicked(const QModelIndex &)));
+ connect(mErrorTableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(errorListClicked(const QModelIndex &)));
connect(mLayerRegistry, SIGNAL(layerWasAdded(QgsMapLayer*)), mConfigureDialog, SLOT(addLayer(QgsMapLayer*)));
connect(mLayerRegistry, SIGNAL(layerWillBeRemoved(QString)), mConfigureDialog, SLOT(removeLayer(QString)));
@@ -97,6 +103,7 @@ checkDock::~checkDock()
delete mRBConflict, mRBFeature1, mRBFeature2;
delete mConfigureDialog;
+ delete mErrorListModel;
// delete errors in list
deleteErrors();
@@ -122,7 +129,8 @@ void checkDock::deleteErrors()
delete *it;
mErrorList.clear();
- mErrorListView->clear();
+ mErrorListModel->resetModel();
+ //mErrorTableView->clear();
}
void checkDock::parseErrorListByLayer(QString layerId)
@@ -143,13 +151,15 @@ void checkDock::parseErrorListByLayer(QString layerId)
++it;
}
+ mErrorListModel->resetModel();
mComment->setText(QString("No errors were found"));
- mErrorListView->clear();
+ //mErrorTableView->clear();
- ErrorList::ConstIterator lit = mErrorList.begin();
+ /*ErrorList::ConstIterator lit = mErrorList.begin();
ErrorList::ConstIterator errorsEnd = mErrorList.end();
for (; lit != errorsEnd; ++lit)
- mErrorListView->addItem((*lit)->name() + QString(" %1").arg((*lit)->featurePairs().first().feature.id()));
+ mErrorTableView->addItem((*lit)->name() + QString(" %1").arg((*lit)->featurePairs().first().feature.id()));
+ */
}
void checkDock::parseErrorListByFeature(int featureId)
@@ -170,12 +180,14 @@ void checkDock::parseErrorListByFeature(int featureId)
}
mComment->setText(QString("No errors were found"));
- mErrorListView->clear();
+ mErrorListModel->resetModel();
+ /*mErrorTableView->clear();
ErrorList::ConstIterator lit = mErrorList.begin();
ErrorList::ConstIterator errorsEnd = mErrorList.end();
for (; lit != errorsEnd; ++lit)
- mErrorListView->addItem((*lit)->name() + QString(" %1").arg((*lit)->featurePairs().first().feature.id()));
+ mErrorTableView->addItem((*lit)->name() + QString(" %1").arg((*lit)->featurePairs().first().feature.id()));
+ */
}
void checkDock::configure()
@@ -239,10 +251,9 @@ void checkDock::errorListClicked(const QModelIndex& index)
mRBConflict->setToGeometry(mErrorList[row]->conflict(), fl.layer);
}
-//TODO: delete items in errorListView
void checkDock::fix()
{
- int row = mErrorListView->currentRow();
+ int row = mErrorTableView->currentIndex().row();
QString fixName = mFixBox->currentText();
if (row == -1)
@@ -255,9 +266,10 @@ void checkDock::fix()
if (mErrorList[row]->fix(fixName))
{
mErrorList.removeAt(row);
- delete mErrorListView->takeItem(row);
+ mErrorListModel->resetModel();
+ //delete mErrorTableView->takeItem(row);
//parseErrorListByFeature();
- mComment->setText(QString("%1 errors were found").arg(mErrorListView->count()));
+ mComment->setText(QString("%1 errors were found").arg(mErrorList.count()));
mQgisApp->mapCanvas()->refresh();
}
else
@@ -298,28 +310,30 @@ void checkDock::runTests(ValidateType type)
ErrorList errors = mTest.runTest(testName, layer1, layer2, type, toleranceStr.toDouble());
disconnect(&progress, SIGNAL(canceled()), &mTest, SLOT(setTestCancelled()));
disconnect(&mTest, SIGNAL(progress(int)), &progress, SLOT(setValue(int)));
-
+/*
ErrorList::ConstIterator it = errors.begin();
ErrorList::ConstIterator errorsEnd = errors.end();
for (; it != errorsEnd; ++it)
{
if (mTest.testMap()[testName].useSecondLayer)
- mErrorListView->addItem((*it)->name() + QString(" %1 %2").arg((*it)->featurePairs().first().feature.id()).arg((*it)->featurePairs()[1].feature.id()));
+ mErrorTableView->addItem((*it)->name() + QString(" %1 %2").arg((*it)->featurePairs().first().feature.id()).arg((*it)->featurePairs()[1].feature.id()));
else
- mErrorListView->addItem((*it)->name() + QString(" %1").arg((*it)->featurePairs().first().feature.id()));
+ mErrorTableView->addItem((*it)->name() + QString(" %1").arg((*it)->featurePairs().first().feature.id()));
}
-
+*/
mErrorList << errors;
}
+ mErrorListModel->resetModel();
}
void checkDock::validate(ValidateType type)
{
mErrorList.clear();
- mErrorListView->clear();
+ //mErrorListModel->resetModel();
+ //mErrorTableView->clear();
runTests(type);
- mComment->setText(QString("%1 errors were found").arg(mErrorListView->count()));
+ mComment->setText(QString("%1 errors were found").arg(mErrorList.count()));
mRBFeature1->reset();
mRBFeature2->reset();
View
@@ -28,6 +28,7 @@
#include "rulesDialog.h"
#include "topolError.h"
#include "topolTest.h"
+#include "dockModel.h"
class QgsMapLayerRegistry;
class QgsRubberBand;
@@ -66,6 +67,7 @@ private slots:
QList<QString> mLayerNameList;
ErrorList mErrorList;
+ DockModel* mErrorListModel;
QgsGeometryMap mGeometryMap;
//pointer to topology tests table
View
@@ -43,7 +43,7 @@
</layout>
</item>
<item>
- <widget class="QListWidget" name="mErrorListView"/>
+ <widget class="QTableView" name="mErrorTableView"/>
</item>
<item>
<widget class="QLabel" name="mComment">
View
@@ -0,0 +1,121 @@
+/***************************************************************************
+ dockModel.cpp
+ TOPOLogy checker
+ -------------------
+ date : May 2009
+ copyright : Vita Cizek
+ email : weetya (at) gmail.com
+
+ ***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "dockModel.h"
+#include "topolError.h"
+
+DockModel::DockModel(ErrorList& theErrorList, QObject *parent = 0) : mErrorlist(theErrorList)
+{
+ mHeader << "Error" << "Feature ID #1" << "Feature ID #2";
+}
+
+int DockModel::rowCount(const QModelIndex &parent) const
+{
+ return mErrorlist.count();
+}
+
+int DockModel::columnCount(const QModelIndex &parent) const
+{
+ return 3;
+}
+
+QVariant DockModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::DisplayRole)
+ {
+ if (orientation == Qt::Vertical) //row
+ {
+ return QVariant(section);
+ }
+ else
+ {
+ return mHeader[section];
+ }
+ }
+ else return QVariant();
+}
+
+QVariant DockModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid() || (role != Qt::TextAlignmentRole && role != Qt::DisplayRole && role != Qt::EditRole) )
+ return QVariant();
+
+ int row = index.row();
+ int column = index.column();
+ //if (!column)
+ //QVariant::Type fldType = mLayer->dataProvider()->fields()[column].type();
+ //QVariant::Type fldType = mLayer->dataProvider()->fields()[index.column()].type();
+ //bool fldNumeric = (fldType == QVariant::Int || fldType == QVariant::Double);
+
+ if (role == Qt::TextAlignmentRole)
+ {
+ if (column)
+ return QVariant(Qt::AlignRight);
+ else
+ return QVariant(Qt::AlignLeft);
+ }
+
+ QVariant val;
+ switch (column)
+ {
+ case 0:
+ val = mErrorlist[row]->name();
+ break;
+ case 1:
+ val = mErrorlist[row]->featurePairs().first().feature.id();
+ break;
+ case 2:
+ val = mErrorlist[row]->featurePairs()[1].feature.id();
+ break;
+ default:
+ val = QVariant();
+ }
+
+ if (val.isNull())
+ {
+ return QVariant();
+ }
+
+ // convert to QString from some other representation
+ // this prevents displaying greater numbers in exponential format
+ return val.toString();
+}
+
+bool DockModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ return false;
+}
+
+Qt::ItemFlags DockModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return Qt::ItemIsEnabled;
+
+ Qt::ItemFlags flags = QAbstractItemModel::flags(index);
+ return flags;
+}
+
+void DockModel::resetModel()
+{
+ reset();
+}
+
+void DockModel::reload(const QModelIndex &index1, const QModelIndex &index2)
+
+{
+ emit dataChanged(index1, index2);
+}
View
@@ -0,0 +1,49 @@
+/***************************************************************************
+ dockModel.h
+ TOPOLogy checker
+ -------------------
+ date : May 2009
+ copyright : Vita Cizek
+ email : weetya (at) gmail.com
+
+ ***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef DOCKMODEL_H
+#define DOCKMODEL_H
+
+#include <QAbstractTableModel>
+#include <QModelIndex>
+#include <QObject>
+
+#include "topolError.h"
+
+class DockModel: public QAbstractTableModel
+{
+Q_OBJECT
+
+public:
+ DockModel(ErrorList& theErrorList, QObject *parent);
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+
+ int rowCount(const QModelIndex &parent) const;
+ int columnCount(const QModelIndex &parent) const;
+
+ void reload(const QModelIndex &index1, const QModelIndex &index2);
+ void resetModel();
+
+private:
+ ErrorList& mErrorlist;
+ QList<QString> mHeader;
+};
+
+#endif

0 comments on commit 2aa8f97

Please sign in to comment.