diff options
author | Arno <am@disconnect.de> | 2012-03-02 21:34:26 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2012-03-02 21:34:26 +0100 |
commit | 08861cc269ba6126ec7fa3bfad4f946fb60d3d98 (patch) | |
tree | 30a37656b1f5dd93560ab59e000e1f235efde85f | |
parent | c81a54da19d0d81cb57e3f104ce4d7502faeb869 (diff) | |
download | SheMov-08861cc269ba6126ec7fa3bfad4f946fb60d3d98.tar.gz SheMov-08861cc269ba6126ec7fa3bfad4f946fb60d3d98.tar.bz2 SheMov-08861cc269ba6126ec7fa3bfad4f946fb60d3d98.zip |
Fix MappingTreeModel::addChild()
Catch illegal separator in value before making a database entry and
insertRows()
-rw-r--r-- | mappingtreemodel.cpp | 13 | ||||
-rw-r--r-- | mappingtreemodel.h | 3 | ||||
-rw-r--r-- | mappingtreewidget.cpp | 5 |
3 files changed, 14 insertions, 7 deletions
diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp index 8651a4a..ec60da4 100644 --- a/mappingtreemodel.cpp +++ b/mappingtreemodel.cpp @@ -13,7 +13,7 @@ #include "mappingtreemodel.h" #include "smtreeitem.h" -MappingTreeModel::MappingTreeModel(QStringList &headers, QObject *parent) : SmTreeModel(headers, parent), mType(-1) { +MappingTreeModel::MappingTreeModel(QStringList &headers, QObject *parent) : SmTreeModel(headers, parent), mForbidden("/"), mType(-1) { //init database mDb = QSqlDatabase::database("treedb"); mTypesQ = new QSqlQuery(mDb); @@ -129,7 +129,7 @@ bool MappingTreeModel::setData(const QModelIndex &index, const QVariant &value, SmTreeItem *item = itemAt(index); if(role == Qt::EditRole){ if(index.column() == Name){ - if(value.toString().contains("/")){ + if(value.toString().contains(mForbidden)){ return false; } } @@ -151,7 +151,7 @@ bool MappingTreeModel::setData(const QModelIndex &index, const QVariant &value, mDb.rollback(); } if(role == NameRole){ - if(value.toString().contains("/")){ + if(value.toString().contains(mForbidden)){ return false; } item->setData(Name, value); @@ -215,6 +215,9 @@ bool MappingTreeModel::addChild(const QVariant &name, const QModelIndex &parent) if(!parent.isValid()){ return false; } + if(name.toString().contains(mForbidden)){ + return false; + } SmTreeItem *pItem = itemAt(parent); mAddChildQ->bindValue(":name", name); mAddChildQ->bindValue(":type", mType); @@ -226,9 +229,7 @@ bool MappingTreeModel::addChild(const QVariant &name, const QModelIndex &parent) int where = lowerBound(pItem, mSelectChildQ->value(1), Name); if(insertRows(where, 1, parent)){ QModelIndex newIdx = index(where, 0, parent); - if(!setData(newIdx, mSelectChildQ->value(1), NameRole)){ - return false; - } + setData(newIdx, mSelectChildQ->value(1), NameRole); setData(newIdx, mSelectChildQ->value(0), IdRole); setData(newIdx, mSelectChildQ->value(2), AddedRole); } diff --git a/mappingtreemodel.h b/mappingtreemodel.h index c8ee8ee..1c35db9 100644 --- a/mappingtreemodel.h +++ b/mappingtreemodel.h @@ -45,6 +45,7 @@ class MappingTreeModel : public SmTreeModel { MappingData mappingDataFromId(int mappingId) const; void setSelectedMappings(const QList<int> &mappingData); QStringList paths() const; + const QString &forbidden() const { return mForbidden; } public slots: void populate(); @@ -81,8 +82,8 @@ class MappingTreeModel : public SmTreeModel { QList<mappingType> mMappingTypes; QList<MappingData> mValidMappings; QList<int> mSelectedMappings; + const QString mForbidden; int mType; - }; class MappingTreeResultModel : public SmTreeModel { diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index 01582e5..67ccd87 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -121,6 +121,11 @@ void MappingTreeWidget::addChild(){ if(value.isEmpty()){ return; } + if(value.contains(mModel->forbidden())){ + QString msg = QString(tr("Value contains illegal string \"%1\"")).arg(mModel->forbidden()); + QMessageBox::critical(this, tr("Error"), msg); + return; + } QModelIndex real = mProxy->mapToSource(sel); mModel->addChild(value, real); } |