From 8c6051a16b12f265d7a30b4b24da10b3ba63edae Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 2 Jul 2010 16:28:02 +0200 Subject: Started NewMovieWizard for adding movies Finished GUI for first page of NewMovieWizard. To make things easier I added two new member functions to SmTreeModel: -QModelIndex find() to find items by value of a column -void reparent() to remove an item from one parent and add it to another --- smtreemodel.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'smtreemodel.cpp') diff --git a/smtreemodel.cpp b/smtreemodel.cpp index 2a230cc..2026902 100644 --- a/smtreemodel.cpp +++ b/smtreemodel.cpp @@ -107,6 +107,22 @@ 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{ + SmTreeItem *parentItem = 0; + if(!parent.isValid()){ + parentItem = root(); + }else{ + parentItem = static_cast(parent.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 QModelIndex(); +} + bool SmTreeModel::setRoot(SmTreeItem *rootItem){ if(mRootItem){ beginResetModel(); @@ -126,6 +142,25 @@ SmTreeItem *SmTreeModel::parentItem(const QModelIndex &child) const{ return static_cast(child.parent().internalPointer()); } +void SmTreeModel::reparent(const QModelIndex &idx, const QModelIndex &newParent){ + if(!idx.isValid()){ + return; + } + SmTreeItem *parentItem = 0; + SmTreeItem *item = static_cast(idx.internalPointer()); + if(newParent == QModelIndex()){ + parentItem = root(); + }else{ + parentItem = static_cast(newParent.internalPointer()); + } + removeRows(idx.row(), 1, idx.parent()); + QList data; + for(int i = 0; i < item->columnCount(); ++i){ + data << item->data(i); + } + addRow(data, newParent); +} + bool SmTreeModel::insertRows(int row, int count, const QModelIndex &parent){ SmTreeItem *parentItem = itemAt(parent); bool retval; -- cgit v1.2.3-70-g09d2