diff options
Diffstat (limited to 'mappingtreemodel.cpp')
-rw-r--r-- | mappingtreemodel.cpp | 13 |
1 files changed, 7 insertions, 6 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); } |