summaryrefslogtreecommitdiffstats
path: root/smtreemodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'smtreemodel.cpp')
-rw-r--r--smtreemodel.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/smtreemodel.cpp b/smtreemodel.cpp
index 98e7e45..802eebc 100644
--- a/smtreemodel.cpp
+++ b/smtreemodel.cpp
@@ -185,7 +185,7 @@ SmTreeItem *SmTreeModel::parentItem(const QModelIndex &child) const{
return static_cast<SmTreeItem*>(child.parent().internalPointer());
}
-void SmTreeModel::reparent(const QModelIndex &idx, const QModelIndex &newParent){
+void SmTreeModel::reparent(const QModelIndex &idx, const QModelIndex &newParent, bool sorted){
if(!idx.isValid()){
return;
}
@@ -194,8 +194,9 @@ void SmTreeModel::reparent(const QModelIndex &idx, const QModelIndex &newParent)
for(int i = 0; i < item->columnCount(); ++i){
data << item->data(i);
}
+ QPersistentModelIndex pNewParent = newParent;
removeRows(idx.row(), 1, idx.parent());
- addRow(data, newParent);
+ addRow(data, pNewParent, sorted);
}
bool SmTreeModel::insertRows(int row, int count, const QModelIndex &parent){
@@ -231,15 +232,24 @@ bool SmTreeModel::removeRows(int row, int count, const QModelIndex &parent){
return retval;
}
-bool SmTreeModel::addRow(const QList<QVariant> &data, const QModelIndex &parent){
+bool SmTreeModel::addRow(const QList<QVariant> &data, const QModelIndex &parent, bool sorted){
if(data.count() != mRootItem->columnCount()){
return false;
}
SmTreeItem *parentItem = itemAt(parent);
+ int where = 0;
+ if(sorted){
+ for(int i = 0; i < parentItem->childCount(); ++i){
+ if(parentItem->child(i)->data(0).toString() > data.at(0).toString()){
+ where = i;
+ break;
+ }
+ }
+ }
- if(insertRows(parentItem->childCount(), 1, parent)){
- SmTreeItem *child = parentItem->child(parentItem->childCount() - 1);
+ if(insertRows(where, 1, parent)){
+ SmTreeItem *child = parentItem->child(where);
for(int i = 0; i < data.count(); ++i){
child->setData(i, data.at(i));
}