summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mappingtreemodel.cpp187
-rw-r--r--mappingtreemodel.h17
-rw-r--r--mappingtreewidget.cpp28
-rw-r--r--mappingtreewidget.h5
-rw-r--r--picfilesmodel.cpp29
-rw-r--r--picfilesmodel.h2
-rw-r--r--pictureswidget.cpp16
-rw-r--r--pictureviewer2.cpp2
-rw-r--r--smtreemodel.cpp42
-rw-r--r--smtreemodel.h12
10 files changed, 154 insertions, 186 deletions
diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp
index 62cec14..cb981d0 100644
--- a/mappingtreemodel.cpp
+++ b/mappingtreemodel.cpp
@@ -11,6 +11,7 @@
#include "mappingtreemodel.h"
#include "smtreeitem.h"
+#include "smglobals.h"
MappingTreeModel::MappingTreeModel(QStringList &headers, QObject *parent) : SmTreeModel(headers, parent), mForbidden("/"), mType(-1) {
//init database
@@ -72,34 +73,19 @@ QList<QVariant> MappingTreeModel::childList(const QVariant &value, int column) c
return QList<QVariant>() << value;
}
-QStringList MappingTreeModel::path(QModelIndex &idx) const{
- if(!idx.isValid()){
- return QStringList();
+QModelIndex MappingTreeModel::indexFromParentPath(const QList<int> &pPath, bool reverse) const{
+ QList<int> path = pPath;
+ if(reverse){
+ std::reverse(path.begin(), path.end());
}
- QStringList retval;
- SmTreeItem *item = static_cast<SmTreeItem*>(idx.internalPointer());
- do {
- QString d = item->data(MappingTreeModel::Name).toString();
- if(!d.isEmpty()){
- retval << d;
+ QModelIndex retval = QModelIndex();
+ while(!path.isEmpty()){
+ int curId = path.last();
+ path.removeLast();
+ retval = find(curId, MappingId, retval);
+ if(!retval.isValid()){
+ return QModelIndex();
}
- item = item->parent();
- }while(item);
- std::reverse(retval.begin(), retval.end());
- return retval;
-}
-
-QModelIndex MappingTreeModel::indexFromPath(const QString &path, int column) const{
- if(path == "/"){
- return rootIndex();
- }
- QStringList items = path.split("/");
- if(items.isEmpty() || column >= NumFields){
- return QModelIndex();
- }
- QModelIndex retval;
- for(int i = 0; i < items.count(); ++i){
- retval = find(items.at(i), column, retval);
}
return retval;
}
@@ -135,24 +121,6 @@ bool MappingTreeModel::setData(const QModelIndex &idx, const QVariant &value, in
return true;
}
-bool MappingTreeModel::move(const QModelIndex &source, const QModelIndex &dest){
- QVariant sourceId = source.data(MappingIdRole);
- QVariant destId = dest.data(MappingIdRole);
- QSqlQuery updateParentQ(mDb);
- updateParentQ.prepare("UPDATE mapping_parents SET iparent_id = :id where imapping_parents_id = :sid");
- updateParentQ.bindValue(":id", destId);
- updateParentQ.bindValue(":sid", sourceId);
- if(updateParentQ.exec()){
- // well, well, I tried to make this work with removeRows and insertRows,
- // but qt has a mind of its own there. So take the easy way out. Also,
- // it's way faster!
- populate();
- return true;
- }
- mLastError = updateParentQ.lastError();
- return false;
-}
-
bool MappingTreeModel::addMappingType(const QString &type){
QSqlQuery addMappingTypeQ(mDb);
addMappingTypeQ.prepare("INSERT INTO mappings_type (tmappings_type_name) VALUES(:value)");
@@ -242,16 +210,18 @@ MappingData MappingTreeModel::mappingDataFromIndex(QModelIndex &idx) const{
return retval;
}
retval.mappingId = idx.data(MappingTreeModel::MappingIdRole).toInt();
- retval.parentId = idx.data(MappingTreeModel::MappingParentIdRole).toInt();
retval.descId = idx.data(MappingTreeModel::DescIdRole).toInt();
retval.name = idx.data(MappingTreeModel::NameRole).toString();
- retval.path << path(idx);
- return retval;
-}
-
-QStringList MappingTreeModel::paths() const{
- QStringList retval = QStringList() << "/";
- retval << getPathsRecursive(root());
+ retval.parents << idx.data(MappingTreeModel::MappingIdRole).toInt();
+ retval.path << idx.data(MappingTreeModel::NameRole).toString();
+ QModelIndex pIdx = idx.parent();
+ while(pIdx.isValid()){
+ retval.parents << pIdx.data(MappingTreeModel::MappingIdRole).toInt();
+ retval.path << pIdx.data(MappingTreeModel::NameRole).toString();
+ pIdx = pIdx.parent();
+ }
+ std::reverse(retval.parents.begin(), retval.parents.end());
+ std::reverse(retval.path.begin(), retval.path.end());
return retval;
}
@@ -362,21 +332,6 @@ bool MappingTreeModel::updateChild(SmTreeItem *item, const QVariant &value){
return false;
}
-QStringList MappingTreeModel::getPathsRecursive(SmTreeItem *parent) const{
- QStringList retval;
- if(!basePath(parent).isEmpty()){
- retval << basePath(parent);
- }
- for(int i = 0; i < parent->childCount(); ++i){
- if(parent->child(i)->childCount()){
- retval << getPathsRecursive(parent->child(i));
- }else{
- retval << QString("%1/%2").arg(basePath(parent)).arg(parent->child(i)->data(Name).toString());
- }
- }
- return retval;
-}
-
QList<QVariant> MappingTreeModel::getChildListRecursive(SmTreeItem *item, int column) const{
QList<QVariant> retval;
if(!item){
@@ -423,6 +378,26 @@ Qt::ItemFlags MappingTreeResultModel::flags(const QModelIndex &index) const {
return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
}
+QVariant MappingTreeResultModel::data(const QModelIndex &index, int role) const{
+ if(!index.isValid()){
+ return QVariant();
+ }
+ SmTreeItem *item = itemAt(index);
+ if(role == NameRole){
+ return item->data(Name);
+ }
+ if(role == MappingIdRole){
+ return item->data(MappingId);
+ }
+ if(role == DescIdRole){
+ return item->data(DescId);
+ }
+ if(role == ParentIdRole){
+ return item->data(ParentId);
+ }
+ return SmTreeModel::data(index, role);
+}
+
bool MappingTreeResultModel::setData(const QModelIndex &index, const QVariant &value, int role){
SmTreeItem *item = itemAt(index);
if(role == NameRole){
@@ -445,50 +420,46 @@ bool MappingTreeResultModel::setData(const QModelIndex &index, const QVariant &v
}
void MappingTreeResultModel::addItem(const MappingData &data){
- SmTreeItem *curItem = root();
- QList<QStringList> paths = data.path;
- foreach(QStringList p, paths){
- for(int i = 0; i < p.count(); ++i){
- int childPos = hasChild(curItem, p.at(i));
- if(childPos != -1){
- //child already exists
- curItem = curItem->child(childPos);
- continue;
+ QList<int> pPath = data.parents;
+ QList<int> curPath;
+ std::reverse(pPath.begin(), pPath.end());
+ MappingTreeModel *mapModel = qobject_cast<MappingTreeModel*>(SmGlobals::instance()->model("MappingTree"));
+ QModelIndex curIdx = QModelIndex();
+ int curId = -1;
+ while(!pPath.isEmpty()){
+ curId = pPath.last();
+ curPath << curId;
+ pPath.removeLast();
+ QModelIndex lastIdx = curIdx;
+ curIdx = find(curId, MappingId, curIdx);
+ if(!curIdx.isValid()){
+ QModelIndex sourceIdx = mapModel->indexFromParentPath(curPath, true);
+ if(!sourceIdx.isValid()){
+ return; //should never happen!
+ }
+ SmTreeItem *pItem;
+ if(!lastIdx.isValid()){
+ pItem = root();
}else{
- //insert child
- int mappingId = -1;
- int parentId = -1;
- int descId = -1;
- if(i == p.count() - 1){
- mappingId = data.mappingId;
- parentId = data.parentId;
- descId = data.descId;
- }
- QModelIndex curIdx = insertChild(p.at(i), mappingId, parentId, descId, curItem);
- curItem = itemAt(curIdx);
+ pItem = static_cast<SmTreeItem*>(lastIdx.internalPointer());
}
- }
- }
-}
-
-QModelIndex MappingTreeResultModel::insertChild(const QVariant &data, int mappingId, int parentId, int descId, SmTreeItem *parent){
- QModelIndex parentIdx;
- int row = parent->childCount();
- if(parent != root()){
- for(int i = 0; i < parent->childCount(); ++i){
- if(parent->child(i)->data(0).toString() > data.toString()){
- row = i;
+ int row = pItem->childCount();
+ const QString curName = sourceIdx.data(MappingTreeModel::NameRole).toString();
+ for(int i = 0; i < pItem->childCount(); ++i){
+ if(pItem->child(i)->data(Name).toString() > curName){
+ row = i;
+ }
}
+ insertRows(row, 1, lastIdx);
+ QModelIndex newIdx = index(row, 0, lastIdx);
+ setData(newIdx, curName, NameRole);
+ setData(newIdx, sourceIdx.data(MappingTreeModel::MappingIdRole), MappingIdRole);
+ setData(newIdx, sourceIdx.data(MappingTreeModel::DescIdRole), DescIdRole);
+ setData(newIdx, sourceIdx.data(MappingTreeModel::MappingParentIdRole), ParentIdRole);
+ setData(newIdx, sourceIdx.data(MappingTreeModel::DescIdRole), DescIdRole);
+ curIdx = newIdx;
}
- parentIdx = createIndex(0, 0, parent);
}
- insertRows(row, 1, parentIdx);
- QModelIndex newIdx = index(row, 0, parentIdx);
- setData(newIdx, data, NameRole);
- setData(newIdx, mappingId, MappingIdRole);
- setData(newIdx, descId, DescIdRole);
- setData(newIdx, parentId, ParentIdRole);
- return newIdx;
}
QList<QVariant> MappingTreeResultModel::columnValues(int column) const {
@@ -524,8 +495,8 @@ QList<QVariant> MappingTreeResultModel::columnValuesRecursive(SmTreeItem *parent
return retval;
}
-MappingData::MappingData() : mappingId(-1), parentId(-1), descId(-1) {}
+MappingData::MappingData() : mappingId(-1), descId(-1) {}
bool MappingData::isValid(){
- return !(mappingId == -1 && parentId == -1 && descId == -1);
+ return !(mappingId == -1 && descId == -1);
}
diff --git a/mappingtreemodel.h b/mappingtreemodel.h
index efc4e2d..a730aaa 100644
--- a/mappingtreemodel.h
+++ b/mappingtreemodel.h
@@ -33,18 +33,14 @@ class MappingTreeModel : public SmTreeModel {
//data
QVariant data(const QModelIndex &index, int role) const;
QList<QVariant> childList(const QVariant &value, int column = 0) const;
- QStringList path(QModelIndex &idx) const;
- QModelIndex indexFromPath(const QString &path, int column = 0) const;
+ QModelIndex indexFromParentPath(const QList<int> &pPath, bool reverse) const;
bool setData(const QModelIndex &idx, const QVariant &value, int role);
- bool move(const QModelIndex &source, const QModelIndex &dest);
bool addMappingType(const QString &type);
bool deleteMappingType(int typeId);
bool addChild(const QVariant &name, const QModelIndex &parent);
bool renameChild(const QModelIndex &idx, const QString newName);
bool deleteChild(const QModelIndex &idx);
MappingData mappingDataFromIndex(QModelIndex &idx) const;
- QStringList paths() const;
- const QString &forbidden() const { return mForbidden; }
const QSqlError &lastError() const { return mLastError; }
public slots:
@@ -65,7 +61,6 @@ class MappingTreeModel : public SmTreeModel {
void getMappingTypes();
void getChildrenRecursive(SmTreeItem *item);
bool updateChild(SmTreeItem *item, const QVariant &value);
- QStringList getPathsRecursive(SmTreeItem *parent) const;
QList<QVariant> getChildListRecursive(SmTreeItem *item, int column) const;
QString basePath(SmTreeItem *item) const;
int lowerBound(SmTreeItem *item, const QVariant &value, int column = 0) const;
@@ -88,8 +83,8 @@ class MappingTreeResultModel : public SmTreeModel {
//data + flags
Qt::ItemFlags flags(const QModelIndex &index) const;
- bool setData(const QModelIndex &index, const QVariant &value, int role);
- QModelIndex insertChild(const QVariant &data, int mappingId, int parentId, int descId, SmTreeItem *parent);
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
QList<QVariant> columnValues(int column) const;
void clearData();
@@ -105,12 +100,10 @@ struct MappingData {
MappingData();
bool isValid();
int mappingId;
- int parentId;
int descId;
QString name;
- QList<QStringList> path;
+ QList<int> parents;
+ QStringList path;
};
-Q_DECLARE_METATYPE(QList<QStringList>)
-
#endif // MAPPINGTREEMODEL_H
diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp
index dcf96e1..c2da053 100644
--- a/mappingtreewidget.cpp
+++ b/mappingtreewidget.cpp
@@ -101,9 +101,6 @@ MappingTreeWidget::MappingTreeWidget(QWidget *parent) : QWidget(parent){
mEditChildA = new QAction(tr("Edit..."), this);
connect(mEditChildA, SIGNAL(triggered()), this, SLOT(editChild()));
mTree->addAction(mEditChildA);
- mMoveChildA = new QAction(tr("Move..."), this);
- connect(mMoveChildA, SIGNAL(triggered()), this, SLOT(moveChild()));
- mTree->addAction(mMoveChildA);
//widget layout and tab order
QVBoxLayout *mainLayout = new QVBoxLayout;
@@ -133,11 +130,6 @@ 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 parent = mModel->rootIndex();
if(!dlg.createRoot()){
QModelIndex sel = selected();
@@ -213,8 +205,8 @@ void MappingTreeWidget::deleteType(){
}
}
-void MappingTreeWidget::selectPath(const QString &path){
- QModelIndex pathIdx = mModel->indexFromPath(path);
+void MappingTreeWidget::selectPath(const QList<int> &data){
+ QModelIndex pathIdx = mModel->indexFromParentPath(data, true);
if(!pathIdx.isValid()){
return;
}
@@ -259,22 +251,6 @@ void MappingTreeWidget::selectionChanged(){
emit mappingChanged(real.data(MappingTreeModel::MappingIdRole).toInt());
}
-void MappingTreeWidget::moveChild(){
- QString path = QInputDialog::getItem(this, tr("Move item"), tr("Move to:"), mModel->paths(), -1, false);
- if(!path.isEmpty()){
- QModelIndex sel = selected();
- QModelIndex realSource = mProxy->mapToSource(sel);
- QModelIndex dest = mModel->indexFromPath(path);
- if(dest == realSource){
- QMessageBox::critical(this, tr("Error"), tr("Destination cannot be the source!"));
- return;
- }
- if(realSource.isValid() && dest.isValid()){
- mModel->move(realSource, dest);
- }
- }
-}
-
void MappingTreeWidget::filter(){
QString filter = mFilter->text();
mProxy->setFilter(filter);
diff --git a/mappingtreewidget.h b/mappingtreewidget.h
index 9fe5739..63145fa 100644
--- a/mappingtreewidget.h
+++ b/mappingtreewidget.h
@@ -36,7 +36,7 @@ class MappingTreeWidget : public QWidget {
void addType();
void deleteChild();
void deleteType();
- void selectPath(const QString &path);
+ void selectPath(const QList<int> &data);
protected:
virtual void hideEvent(QHideEvent *event);
@@ -45,7 +45,7 @@ class MappingTreeWidget : public QWidget {
void typeChanged(QString type);
void editChild();
void selectionChanged();
- void moveChild();
+ //void moveChild();
void filter();
void clearFilter();
@@ -67,7 +67,6 @@ class MappingTreeWidget : public QWidget {
QAction *mAddChildA;
QAction *mDeleteChildA;
QAction *mEditChildA;
- QAction *mMoveChildA;
};
class MappingTreeView : public SmTreeView {
diff --git a/picfilesmodel.cpp b/picfilesmodel.cpp
index ea51beb..edb7a23 100644
--- a/picfilesmodel.cpp
+++ b/picfilesmodel.cpp
@@ -171,13 +171,32 @@ QList<MappingData> PicFilesModel::mappingDataFromFiles(const QList<int> fileIds)
return QList<MappingData>();
}
QList<MappingData> retval;
+ QSqlQuery mpq(mDb);
+ mpq.prepare("SELECT imapping_parents_id, iparent_id, tdescription_name, mapping_parents.idescription_id FROM mapping_parents, mapping_description WHERE imapping_parents_id = :id AND mapping_parents.idescription_id = mapping_description.idescription_id");
foreach(int pId, parentIds){
- QModelIndex curIdx = mMappingTreeModel->findRecursive(pId, MappingTreeModel::MappingId, mMappingTreeModel->rootIndex());
MappingData curData;
- curData.mappingId = curIdx.data(MappingTreeModel::MappingIdRole).toInt();
- curData.parentId = curIdx.data(MappingTreeModel::MappingParentIdRole).toInt();
- curData.name = curIdx.data(MappingTreeModel::NameRole).toString();
- curData.path << mMappingTreeModel->path(curIdx);
+ int curParent = -1;
+ mpq.bindValue(":id", pId);
+ mpq.exec();
+ while(mpq.next()){
+ curData.name = mpq.value(2).toString();
+ curData.mappingId = pId;
+ curData.descId = mpq.value(3).toInt();
+ curData.parents << pId;
+ curData.path << curData.name;
+ curParent = mpq.value(1).toInt();
+ }
+ while(curParent != -1){
+ mpq.bindValue(":id", curParent);
+ mpq.exec();
+ while(mpq.next()){
+ curData.parents << curParent;
+ curData.path << mpq.value(2).toString();
+ curParent = mpq.value(1).toInt();
+ }
+ }
+ std::reverse(curData.parents.begin(), curData.parents.end());
+ std::reverse(curData.path.begin(), curData.path.end());
retval << curData;
}
return retval;
diff --git a/picfilesmodel.h b/picfilesmodel.h
index a538f75..a5a9859 100644
--- a/picfilesmodel.h
+++ b/picfilesmodel.h
@@ -11,6 +11,8 @@
#include "smtreemodel.h"
#include "mappingtreemodel.h"
+class QSqlQuery;
+
class PicFilesModel : public SmTreeModel {
Q_OBJECT
public:
diff --git a/pictureswidget.cpp b/pictureswidget.cpp
index d043e1c..c23af06 100644
--- a/pictureswidget.cpp
+++ b/pictureswidget.cpp
@@ -68,15 +68,23 @@ void PicturesWidget::writeSettings(){
QSettings s;
MappingData selected = mMappingTree->selectedItem();
if(selected.isValid()){
- s.setValue("ui/selectedmapping", selected.path.first());
+ QStringList v;
+ for(int i = 0; i< selected.parents.count(); ++i){
+ v << QString::number(selected.parents.at(i));
+ }
+ s.setValue("ui/selectedmapping", v.join(","));
}
mPictureView->writeHeaderConfig();
}
void PicturesWidget::readSettings(){
QSettings s;
- QStringList selPath = s.value("ui/selectedmapping").toStringList();
- mMappingTree->selectPath(selPath.join("/"));
+ QStringList ps = s.value("ui/selectedmapping").toString().split(",");
+ QList<int> path;
+ for(int i = 0; i < ps.count(); ++i){
+ path << ps.at(i).toInt();
+ }
+ mMappingTree->selectPath(path);
mPictureView->readHeaderConfig();
}
@@ -109,7 +117,7 @@ void PicturesWidget::constructWindowTitle(){
QString windowTitle = mWindowTitleBase;
MappingData selected = mMappingTree->selectedItem();
if(!selected.path.isEmpty()){
- windowTitle = QString("%1 - [%2]").arg(mWindowTitleBase).arg(selected.path.first().join("/"));
+ windowTitle = QString("%1 - [%2]").arg(mWindowTitleBase).arg(selected.path.join("/"));
mPictureView->setHoverWinVisible(false);
}
emit needWindowTitleChange(windowTitle);
diff --git a/pictureviewer2.cpp b/pictureviewer2.cpp
index 2c36dc9..4532030 100644
--- a/pictureviewer2.cpp
+++ b/pictureviewer2.cpp
@@ -496,7 +496,7 @@ void PictureViewer2::constructMappingItem(const PicData &file){
QMap<QString, QStringList> sortedPaths;
int maxRows = 0;
foreach(MappingData d, mapData){
- QStringList pItems = d.path.first();
+ QStringList pItems = d.path;
if(pItems.size() > maxRows){
maxRows = pItems.size();
}
diff --git a/smtreemodel.cpp b/smtreemodel.cpp
index b52859c..1386179 100644
--- a/smtreemodel.cpp
+++ b/smtreemodel.cpp
@@ -126,17 +126,17 @@ bool SmTreeModel::setData(const QModelIndex &index, const QVariant &value, int r
return true;
}
-QModelIndex SmTreeModel::find(const QVariant &value, int column, const QModelIndex &parent) const{
+QModelIndex SmTreeModel::find(const QVariant &value, int column, const QModelIndex &pIdx) const{
SmTreeItem *parentItem = 0;
- if(!parent.isValid()){
+ if(!pIdx.isValid()){
parentItem = root();
}else{
- parentItem = static_cast<SmTreeItem*>(parent.internalPointer());
+ parentItem = static_cast<SmTreeItem*>(pIdx.internalPointer());
}
for(int i = 0; i < parentItem->childCount(); ++i){
SmTreeItem *child = parentItem->child(i);
if(child->data(column) == value){
- return index(i, column, parent);
+ return index(i, column, pIdx);
}
}
return QModelIndex();
@@ -166,12 +166,12 @@ QModelIndex SmTreeModel::findRecursive(const QVariant &value, int column, const
return QModelIndex();
}
-bool SmTreeModel::matchRecursive(const QModelIndex &parent, const QRegExp &regex, int column) const {
- if(!parent.isValid()){
+bool SmTreeModel::matchRecursive(const QModelIndex &pIdx, const QRegExp &regex, int column) const {
+ if(!pIdx.isValid()){
return false;
}
// first try the parent itself
- QString value = parent.data().toString();
+ QString value = pIdx.data().toString();
if(value.isEmpty()){
return false;
}
@@ -180,7 +180,7 @@ bool SmTreeModel::matchRecursive(const QModelIndex &parent, const QRegExp &regex
}
// no match, check for children
- SmTreeItem *item = static_cast<SmTreeItem*>(parent.internalPointer());
+ SmTreeItem *item = static_cast<SmTreeItem*>(pIdx.internalPointer());
if(!item->childCount()){
//leaf, chech parents
return checkParents(item, regex, column);
@@ -246,15 +246,15 @@ void SmTreeModel::reparent(const QModelIndex &idx, const QModelIndex &newParent,
addRow(data, pNewParent, sorted);
}
-bool SmTreeModel::insertRows(int row, int count, const QModelIndex &parent){
- SmTreeItem *parentItem = itemAt(parent);
+bool SmTreeModel::insertRows(int row, int count, const QModelIndex &pIdx){
+ SmTreeItem *parentItem = itemAt(pIdx);
bool retval;
if(row > parentItem->childCount()){
return false;
}
- beginInsertRows(parent, row, row + count - 1);
+ beginInsertRows(pIdx, row, row + count - 1);
for(int i = row; i < row + count; ++i){
SmTreeItem *newItem = new SmTreeItem(mRootItem->columnCount(), parentItem);
retval = parentItem->insertChild(i, newItem);
@@ -263,15 +263,15 @@ bool SmTreeModel::insertRows(int row, int count, const QModelIndex &parent){
return retval;
}
-bool SmTreeModel::removeRows(int row, int count, const QModelIndex &parent){
- SmTreeItem *parentItem = itemAt(parent);
+bool SmTreeModel::removeRows(int row, int count, const QModelIndex &pIdx){
+ SmTreeItem *parentItem = itemAt(pIdx);
bool retval;
if(row > parentItem->childCount()){
return false;
}
- beginRemoveRows(parent, row, row + count - 1);
+ beginRemoveRows(pIdx, row, row + count - 1);
for(int i = row + count; i > row; --i){
retval = parentItem->removeChild(i - 1);
}
@@ -279,12 +279,12 @@ bool SmTreeModel::removeRows(int row, int count, const QModelIndex &parent){
return retval;
}
-bool SmTreeModel::addRow(const QList<QVariant> &data, const QModelIndex &parent, bool sorted){
+bool SmTreeModel::addRow(const QList<QVariant> &data, const QModelIndex &pIdx, bool sorted){
if(data.count() != mRootItem->columnCount()){
return false;
}
- SmTreeItem *parentItem = itemAt(parent);
+ SmTreeItem *parentItem = itemAt(pIdx);
int where = 0;
if(sorted){
for(int i = 0; i < parentItem->childCount(); ++i){
@@ -295,21 +295,21 @@ bool SmTreeModel::addRow(const QList<QVariant> &data, const QModelIndex &parent,
}
}
- if(insertRows(where, 1, parent)){
+ if(insertRows(where, 1, pIdx)){
SmTreeItem *child = parentItem->child(where);
for(int i = 0; i < data.count(); ++i){
child->setData(i, data.at(i));
}
- QModelIndex start = index(parentItem->childCount() - 1, 0, parent);
- QModelIndex end = index(parentItem->childCount() - 1, parentItem->columnCount() - 1, parent);
+ QModelIndex start = index(parentItem->childCount() - 1, 0, pIdx);
+ QModelIndex end = index(parentItem->childCount() - 1, parentItem->columnCount() - 1, pIdx);
emit dataChanged(start, end);
return true;
}
return false;
}
-bool SmTreeModel::appendRow(const QList<QVariant> &data, const QModelIndex &parent){
- SmTreeItem *pItem = itemAt(parent);
+bool SmTreeModel::appendRow(const QList<QVariant> &data, const QModelIndex &pIdx){
+ SmTreeItem *pItem = itemAt(pIdx);
SmTreeItem *newItem = new SmTreeItem(data, pItem);
beginResetModel();
pItem->appendChild(newItem);
diff --git a/smtreemodel.h b/smtreemodel.h
index d72d53c..5f7ad7e 100644
--- a/smtreemodel.h
+++ b/smtreemodel.h
@@ -36,9 +36,9 @@ class SmTreeModel : public QAbstractItemModel {
virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role);
virtual QVariant data(const QModelIndex &index, int role) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
- virtual QModelIndex find(const QVariant &value, int column = 0, const QModelIndex &parent = QModelIndex()) const;
+ virtual QModelIndex find(const QVariant &value, int column = 0, const QModelIndex &pIdx = QModelIndex()) const;
virtual QModelIndex findRecursive(const QVariant &value, int column, const QModelIndex &start) const;
- virtual bool matchRecursive(const QModelIndex &parent, const QRegExp &regex, int column = 0) const;
+ virtual bool matchRecursive(const QModelIndex &pIdx, const QRegExp &regex, int column = 0) const;
virtual bool checkParents(const SmTreeItem *item, const QRegExp &regex, int column) const;
// root + parent item
@@ -49,10 +49,10 @@ class SmTreeModel : public QAbstractItemModel {
void reparent(const QModelIndex &idx, const QModelIndex &newParent, bool sorted = false);
// row manipulation
- virtual bool insertRows(int row, int count, const QModelIndex &parent);
- virtual bool removeRows(int row, int count, const QModelIndex &parent);
- bool addRow(const QList<QVariant> &data, const QModelIndex &parent, bool sorted = false);
- bool appendRow(const QList<QVariant> &data, const QModelIndex &parent);
+ virtual bool insertRows(int row, int count, const QModelIndex &pIdx);
+ virtual bool removeRows(int row, int count, const QModelIndex &pIdx);
+ bool addRow(const QList<QVariant> &data, const QModelIndex &pIdx, bool sorted = false);
+ bool appendRow(const QList<QVariant> &data, const QModelIndex &pIdx);
//misc
void setDecorationIcon(const QIcon &icon) { mDecorationIcon = icon; }