#
#
# add_file "src/model/InventoryModel.cpp"
# content [5e43bd88ca04b12866e6bf64425e47cb0525f914]
#
# add_file "src/model/InventoryModel.h"
# content [aa9b4be844447b426ca557ecee9a64aaf442474d]
#
# patch "guitone.pro"
# from [0069d2f2544fa00125a94bdfc1701c27772d766c]
# to [ed4f11a395873f7e56d5a2fce27975ee0229529b]
#
# patch "notes/TODO"
# from [ea5f303d2ed6fb40d78885ae8d567d1c3808532a]
# to [d41645c79208bdef1e8887bb76c7de7961ce9845]
#
# patch "src/model/Inventory.cpp"
# from [5cb43db568057c644f6e3b77e89e49b0e8ebf822]
# to [ca5ce9ae95f10a662c15da323183356d64dc0212]
#
# patch "src/model/Inventory.h"
# from [2e63d286970c94f673751cd43e67bf9791a32eca]
# to [932f48c5ed90807b37a26c894a139f93985454be]
#
# patch "src/view/WorkspaceWindow.cpp"
# from [61f4579fd647177555ca083c93caea741b4100e6]
# to [8f2511b6d776f68716962305e51dce09fe25bc18]
#
# patch "src/view/WorkspaceWindow.h"
# from [cdb9e70c4d3328d8d963a488efc13c307026843f]
# to [baa9b2a1c5ccc191ca799df1b255704138795427]
#
# patch "src/view/dialogs/WorkspaceDialogManager.cpp"
# from [8b8904590203dc8cd1c4e66239cd40b808529033]
# to [a07aa7f29c83306b0af77ec51f791e0966de43e6]
#
============================================================
--- src/model/InventoryModel.cpp 5e43bd88ca04b12866e6bf64425e47cb0525f914
+++ src/model/InventoryModel.cpp 5e43bd88ca04b12866e6bf64425e47cb0525f914
@@ -0,0 +1,317 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Thomas Keller *
+ * address@hidden *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see . *
+ ***************************************************************************/
+
+#include "InventoryModel.h"
+
+InventoryModel::InventoryModel(QObject * parent)
+ : QAbstractItemModel(parent), inventory()
+{
+ inventory = new Inventory(this);
+
+ connect(
+ inventory, SIGNAL(inventoryRead(const QString &)),
+ this, SLOT(maybeResetModel(const QString &))
+ );
+
+ connect(
+ inventory, SIGNAL(invalidWorkspaceFormat(const QString &)),
+ this, SIGNAL(invalidWorkspaceFormat(const QString &))
+ );
+
+ connect(
+ inventory, SIGNAL(beginInsertRows(ModelItem *, int, int)),
+ this, SLOT(triggerBeginInsertRows(ModelItem *, int, int))
+ );
+
+ connect(
+ inventory, SIGNAL(endInsertRows()),
+ this, SLOT(triggerEndInsertRows())
+ );
+
+ connect(
+ inventory, SIGNAL(beginRemoveRows(ModelItem *, int, int)),
+ this, SLOT(triggerBeginRemoveRows(ModelItem *, int, int))
+ );
+
+ connect(
+ inventory, SIGNAL(endRemoveRows()),
+ this, SLOT(triggerEndRemoveRows())
+ );
+}
+
+InventoryModel::~InventoryModel()
+{
+ delete inventory;
+}
+
+void InventoryModel::setWorkspacePath(const WorkspacePath & ws)
+{
+ workspacePath = ws;
+ inventory->setWorkspacePath(ws);
+}
+
+void InventoryModel::refresh()
+{
+ inventory->refresh(false);
+}
+
+bool InventoryModel::canFetchMore(const QModelIndex & parent) const
+{
+ // special handling for the root item
+ if (!parent.isValid())
+ return true;
+
+ ModelItem * item = static_cast
+ (parent.internalPointer());
+ I(item);
+
+ InventoryItem * invitem = dynamic_cast
+ (item);
+
+ // not an inventory item
+ if (!invitem)
+ {
+ D(QString("skipping %1 (not an inventory item)").arg(item->getLabel()));
+ return false;
+ }
+
+ if (invitem->isExpanded(Inventory::QueryLevel))
+ {
+ D(QString("skipping %1 (already expanded)").arg(item->getLabel()));
+ return false;
+ }
+
+ if (invitem->isAboutToBeExpanded())
+ {
+ D(QString("skipping %1 (about to be expanded)").arg(item->getLabel()));
+ return false;
+ }
+
+ return true;
+}
+
+void InventoryModel::fetchMore(const QModelIndex & parent)
+{
+ if (!parent.isValid())
+ return;
+
+ ModelItem * item = static_cast
+ (parent.internalPointer());
+ I(item);
+
+ InventoryItem * invitem = dynamic_cast
+ (item);
+
+ // not an inventory item
+ if (!invitem)
+ {
+ D(QString("skipping %1 (not an inventory item)").arg(item->getLabel()));
+ return;
+ }
+
+ // again, if this item is already expanded, don't expand it again
+ if (invitem->isExpanded(Inventory::QueryLevel) ||
+ invitem->isAboutToBeExpanded()) return;
+
+ invitem->setAboutToBeExpanded();
+
+ inventory->readInventory(invitem->getPath());
+}
+
+void InventoryModel::maybeResetModel(const QString & queriedPath)
+{
+ if (queriedPath.isEmpty())
+ {
+ // we need to call reset() before we emit dataChanged,
+ // otherwise the view doesn't know anything of the new
+ // index we're going to present her afterwards
+ reset();
+
+ // give the root item a proper label, which is in our case the path
+ // to the workspace root directory
+ QList children = inventory->rootItem->getChildren();
+
+ int workspaceRootRow = 0;
+
+ I(children.size() > workspaceRootRow);
+
+ QString displayPath = workspacePath;
+ QString homePath = QDir::homePath();
+ if (workspacePath.indexOf(homePath) == 0)
+ {
+ displayPath = QDir(homePath).relativeFilePath(workspacePath);
+ displayPath.prepend("~/");
+ }
+ children[workspaceRootRow]->setLabel(displayPath);
+
+ emit dataChanged(
+ index(workspaceRootRow, 0, QModelIndex()),
+ index(workspaceRootRow, 2, QModelIndex())
+ );
+ }
+}
+
+QModelIndex InventoryModel::indexFromItem(ModelItem * item, int col) const
+{
+ if (item->isRoot())
+ {
+ return QModelIndex();
+ }
+ return createIndex(item->row(), col, reinterpret_cast(item));
+}
+
+QModelIndex InventoryModel::index(int row, int column, const QModelIndex & parent) const
+{
+ ModelItem * parentItem;
+
+ if (!parent.isValid())
+ {
+ parentItem = inventory->rootItem;
+ }
+ else
+ {
+ parentItem = static_cast(parent.internalPointer());
+ I(parentItem);
+ }
+
+ ModelItem * childItem = parentItem->child(row);
+
+ if (childItem)
+ {
+ return createIndex(row, column, childItem);
+ }
+
+ return QModelIndex();
+}
+
+int InventoryModel::columnCount(const QModelIndex & parent) const
+{
+ Q_UNUSED(parent);
+ return 3;
+}
+
+QVariant InventoryModel::data(const QModelIndex & index, int role) const
+{
+ if (!index.isValid())
+ {
+ return QVariant();
+ }
+
+ ModelItem * item = static_cast(index.internalPointer());
+ I(item);
+ return item->data(index.column(), role);
+}
+
+Qt::ItemFlags InventoryModel::flags(const QModelIndex & index) const
+{
+ if (!index.isValid()) return 0;
+
+ QFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
+
+ ModelItem * item = static_cast(index.internalPointer());
+ I(item);
+
+ // no special flags for pseudo items
+ PseudoItem * psitem = dynamic_cast(item);
+ if (psitem)
+ {
+ return flags;
+ }
+
+ InventoryItem * invitem = dynamic_cast(item);
+ if (invitem)
+ {
+ /*
+ // Disabled until we have figured out how to implement renaming properly
+ if (item->isNewNode())
+ {
+ flags |= Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
+
+ if (item->isDirectory())
+ {
+ flags |= Qt::ItemIsDropEnabled;
+ }
+ }
+ */
+ }
+ return flags;
+}
+
+// the root item needs to store the header for each field
+QVariant InventoryModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
+ {
+ return inventory->rootItem->data(section, role);
+ }
+
+ return QVariant();
+}
+
+QModelIndex InventoryModel::parent(const QModelIndex & index) const
+{
+ if (!index.isValid())
+ {
+ return QModelIndex();
+ }
+
+ ModelItem * childItem = static_cast(index.internalPointer());
+ I(childItem);
+ ModelItem * parentItem = childItem->parent();
+
+ if (parentItem == inventory->rootItem)
+ {
+ return QModelIndex();
+ }
+
+ I(parentItem);
+ return createIndex(parentItem->row(), 0, parentItem);
+}
+
+int InventoryModel::rowCount(const QModelIndex & parent) const
+{
+ ModelItem * parentItem = inventory->rootItem;
+
+ if (parent.isValid())
+ {
+ parentItem = static_cast(parent.internalPointer());
+ }
+
+ I(parentItem);
+ return parentItem->childCount();
+}
+
+void InventoryModel::triggerBeginInsertRows(ModelItem * parent, int start, int end)
+{
+ beginInsertRows(indexFromItem(parent, 0), start, end);
+}
+void InventoryModel::triggerEndInsertRows()
+{
+ endInsertRows();
+}
+
+void InventoryModel::triggerBeginRemoveRows(ModelItem * parent, int start, int end)
+{
+ beginRemoveRows(indexFromItem(parent, 0), start, end);
+}
+
+void InventoryModel::triggerEndRemoveRows()
+{
+ endRemoveRows();
+}
+
============================================================
--- src/model/InventoryModel.h aa9b4be844447b426ca557ecee9a64aaf442474d
+++ src/model/InventoryModel.h aa9b4be844447b426ca557ecee9a64aaf442474d
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Thomas Keller *
+ * address@hidden *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see . *
+ ***************************************************************************/
+
+#ifndef INVENTORY_MODEL_H
+#define INVENTORY_MODEL_H
+
+#include "Inventory.h"
+
+#include
+
+class InventoryModel : public QAbstractItemModel
+{
+ Q_OBJECT
+public:
+ InventoryModel(QObject *);
+ ~InventoryModel();
+
+ QVariant data(const QModelIndex &, int) const;
+ Qt::ItemFlags flags(const QModelIndex &) const;
+ QVariant headerData(int, Qt::Orientation, int) const;
+ QModelIndex index(int, int, const QModelIndex &) const;
+ QModelIndex parent(const QModelIndex &) const;
+ int rowCount(const QModelIndex &) const;
+ int columnCount(const QModelIndex &) const;
+ bool canFetchMore( const QModelIndex &) const;
+ void fetchMore(const QModelIndex &);
+
+public slots:
+ //! forwards
+ void setWorkspacePath(const WorkspacePath &);
+ void refresh();
+
+private:
+ QModelIndex indexFromItem(ModelItem *, int) const;
+
+ Inventory * inventory;
+ WorkspacePath workspacePath;
+
+private slots:
+ void triggerBeginInsertRows(ModelItem *, int, int);
+ void triggerEndInsertRows();
+
+ void triggerBeginRemoveRows(ModelItem *, int, int);
+ void triggerEndRemoveRows();
+
+ void maybeResetModel(const QString &);
+
+signals:
+ //! forward
+ void invalidWorkspaceFormat(const QString &);
+};
+
+#endif
+
============================================================
--- guitone.pro 0069d2f2544fa00125a94bdfc1701c27772d766c
+++ guitone.pro ed4f11a395873f7e56d5a2fce27975ee0229529b
@@ -65,6 +65,7 @@ HEADERS = src/view/TreeView.h \
src/model/AutomateCommand.h \
src/model/Inventory.h \
src/model/InventoryItem.h \
+ src/model/InventoryModel.h \
src/model/InventoryProxyModel.h \
src/model/GetAttributes.h \
src/model/Select.h \
@@ -141,6 +142,7 @@ SOURCES += src/view/TreeView.cpp \
src/model/AutomateCommand.cpp \
src/model/Inventory.cpp \
src/model/InventoryItem.cpp \
+ src/model/InventoryModel.cpp \
src/model/InventoryProxyModel.cpp \
src/model/GetAttributes.cpp \
src/model/Select.cpp \
============================================================
--- notes/TODO ea5f303d2ed6fb40d78885ae8d567d1c3808532a
+++ notes/TODO d41645c79208bdef1e8887bb76c7de7961ce9845
@@ -1,9 +1,6 @@ Current TODO, for "long-term" stuff see
Current TODO, for "long-term" stuff see IDEAS.
* make previous / next group buttons work again in detailed diff dialog
-* expand the root workspace node in the inventory view again
* decide what to do with the inventory watcher and incremental updates
* code rendering for graph view in the changeset dialog (and think about
a nice way to include this view in the per-file history as well)
-* in the "unaccounted renames" dialog the code which builds up the
-tree is apparently called twice; fix that
============================================================
--- src/model/Inventory.cpp 5cb43db568057c644f6e3b77e89e49b0e8ebf822
+++ src/model/Inventory.cpp ca5ce9ae95f10a662c15da323183356d64dc0212
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2006 by Thomas Keller *
+ * Copyright (C) 2008 by Thomas Keller *
* address@hidden *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -27,15 +27,10 @@ Inventory::Inventory(QObject * parent)
const int Inventory::QueryLevel = 2;
Inventory::Inventory(QObject * parent)
- : QAbstractItemModel(parent), AutomateCommand(0), workspacePath()
+ : QObject(parent), AutomateCommand(0)
{
rootItem = new ModelItem("__root__");
rootItem->setParent(rootItem);
-
- connect(
- this, SIGNAL(modelReset()),
- this, SLOT(setWorkspacePath())
- );
}
Inventory::~Inventory()
@@ -46,7 +41,6 @@ void Inventory::setWorkspacePath(const W
void Inventory::setWorkspacePath(const WorkspacePath & ws)
{
workspacePath = ws;
- refresh();
}
void Inventory::refresh(bool fullQuery)
@@ -54,69 +48,6 @@ void Inventory::refresh(bool fullQuery)
readInventory(QString(), fullQuery);
}
-bool Inventory::canFetchMore(const QModelIndex & parent) const
-{
- // special handling for the root item
- if (!parent.isValid())
- return true;
-
- ModelItem * item = static_cast
- (parent.internalPointer());
- I(item);
-
- InventoryItem * invitem = dynamic_cast
- (item);
-
- // not an inventory item
- if (!invitem)
- {
- D(QString("skipping %1 (not an inventory item)").arg(item->getLabel()));
- return false;
- }
-
- if (invitem->isExpanded(QueryLevel))
- {
- D(QString("skipping %1 (already expanded)").arg(item->getLabel()));
- return false;
- }
-
- if (invitem->isAboutToBeExpanded())
- {
- D(QString("skipping %1 (about to be expanded)").arg(item->getLabel()));
- return false;
- }
-
- return true;
-}
-
-void Inventory::fetchMore(const QModelIndex & parent)
-{
- if (!parent.isValid())
- return;
-
- ModelItem * item = static_cast
- (parent.internalPointer());
- I(item);
-
- InventoryItem * invitem = dynamic_cast
- (item);
-
- // not an inventory item
- if (!invitem)
- {
- D(QString("skipping %1 (not an inventory item)").arg(item->getLabel()));
- return;
- }
-
- // again, if this item is already expanded, don't expand it again
- if (invitem->isExpanded(QueryLevel) ||
- invitem->isAboutToBeExpanded()) return;
-
- invitem->setAboutToBeExpanded();
-
- readInventory(invitem->getPath());
-}
-
void Inventory::readInventory(const QString & path, bool fullQuery)
{
I(!workspacePath.isEmpty());
@@ -143,7 +74,7 @@ void Inventory::readInventory(const QStr
/*!
@fixme
- The whole item adding procedurecould eventually make problems
+ The whole item adding procedure could eventually make problems
if inventory is executed with a path which was renamed. The
inventory output then contains another stanza of a path which
was not yet read in, so we have no plan where to tack this on.
@@ -252,171 +183,9 @@ void Inventory::processTaskResult(const
insertRowsRecursive(parentItem, parentChildRelations);
- if (queriedPath.isEmpty())
- {
- // we need to call reset() before we emit dataChanged,
- // otherwise the view doesn't know anything of the new
- // index we're going to present her afterwards
- reset();
- }
-
emit inventoryRead(queriedPath);
}
-QModelIndex Inventory::indexFromItem(ModelItem * item, int col) const
-{
- if (item->isRoot())
- {
- return QModelIndex();
- }
- return createIndex(item->row(), col, reinterpret_cast(item));
-}
-
-void Inventory::setWorkspacePath()
-{
- QList children = rootItem->getChildren();
-
- int workspaceRootRow = 0;
-
- I(children.size() > workspaceRootRow);
-
- QString displayPath = workspacePath;
- QString homePath = QDir::homePath();
- if (workspacePath.indexOf(homePath) == 0)
- {
- displayPath = QDir(homePath).relativeFilePath(workspacePath);
- displayPath.prepend("~/");
- }
- children[workspaceRootRow]->setLabel(displayPath);
-
- emit dataChanged(
- index(workspaceRootRow, 0, QModelIndex()),
- index(workspaceRootRow, 2, QModelIndex())
- );
-}
-
-QModelIndex Inventory::index(int row, int column, const QModelIndex & parent) const
-{
- ModelItem * parentItem;
-
- if (!parent.isValid())
- {
- parentItem = rootItem;
- }
- else
- {
- parentItem = static_cast(parent.internalPointer());
- I(parentItem);
- }
-
- ModelItem * childItem = parentItem->child(row);
-
- if (childItem)
- {
- return createIndex(row, column, childItem);
- }
-
- return QModelIndex();
-}
-
-int Inventory::columnCount(const QModelIndex & parent) const
-{
- Q_UNUSED(parent);
- return 3;
-}
-
-QVariant Inventory::data(const QModelIndex & index, int role) const
-{
- if (!index.isValid())
- {
- return QVariant();
- }
-
- ModelItem * item = static_cast(index.internalPointer());
- I(item);
- return item->data(index.column(), role);
-}
-
-Qt::ItemFlags Inventory::flags(const QModelIndex & index) const
-{
- if (!index.isValid()) return 0;
-
- QFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
-
- ModelItem * item = static_cast(index.internalPointer());
- I(item);
-
- // no special flags for pseudo items
- PseudoItem * psitem = dynamic_cast(item);
- if (psitem)
- {
- return flags;
- }
-
- InventoryItem * invitem = dynamic_cast(item);
- if (invitem)
- {
- /*
- // Disabled until we have figured out how to implement renaming properly
- if (item->isNewNode())
- {
- flags |= Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
-
- if (item->isDirectory())
- {
- flags |= Qt::ItemIsDropEnabled;
- }
- }
- */
- }
- return flags;
-}
-
-// the root item needs to store the header for each field
-QVariant Inventory::headerData(int section, Qt::Orientation orientation, int role) const
-{
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
- {
- return rootItem->data(section, role);
- }
-
- return QVariant();
-}
-
-QModelIndex Inventory::parent(const QModelIndex & index) const
-{
- if (!index.isValid())
- {
- return QModelIndex();
- }
-
- ModelItem * childItem = static_cast(index.internalPointer());
- I(childItem);
- ModelItem * parentItem = childItem->parent();
-
- if (parentItem == rootItem)
- {
- return QModelIndex();
- }
-
- I(parentItem);
- return createIndex(parentItem->row(), 0, parentItem);
-}
-
-int Inventory::rowCount(const QModelIndex & parent) const
-{
- ModelItem * parentItem = rootItem;
-
- if (parent.isValid())
- {
- parentItem = static_cast(parent.internalPointer());
- }
-
- I(parentItem);
- return parentItem->childCount();
-}
-
-//! TODO move this somewhere else without the inventory model dependency
QMap Inventory::findUnaccountedRenames() const
{
QList missingItems;
@@ -436,7 +205,6 @@ QMap Inventory
}
// TODO: progess bar here!
-
QString parentRev = MonotoneUtil::getBaseWorkspaceRevision(workspacePath);
FileEntryList parentList = MonotoneUtil::getRevisionManifest(
MonotoneUtil::getDatabaseFile(workspacePath),
@@ -528,9 +296,8 @@ void Inventory::insertRowsRecursive(Mode
void Inventory::insertRowsRecursive(ModelItem * parentItem, const QMap > & parentChildRelations)
{
+ I(parentItem);
I(parentChildRelations.contains(parentItem));
- QModelIndex parentIndex = indexFromItem(parentItem, 0);
- I(parentIndex.isValid() || parentItem->isRoot());
const QList & children = parentChildRelations.value(parentItem);
I(children.size() > 0);
@@ -547,17 +314,18 @@ void Inventory::insertRowsRecursive(Mode
{
InventoryItem * oldItem = itemMap.value(path);
ModelItem * oldParent = oldItem->parent();
- QModelIndex oldParentIndex = indexFromItem(oldParent, 0);
int row = oldItem->row();
- removeRowsRecursive(oldParentIndex, row, row);
+ removeRowsRecursive(oldParent, row, row);
}
}
//
// now do the actual row insertion while notifying Qt properly about that
//
- int parentRowCount = rowCount(parentIndex);
- beginInsertRows(parentIndex, parentRowCount, parentRowCount + children.size() - 1);
+ int parentRowCount = parentItem->childCount();
+
+ emit beginInsertRows(parentItem, parentRowCount, parentRowCount + children.size() - 1);
+
foreach (ModelItem * item, children)
{
InventoryItem * invitem = dynamic_cast(item);
@@ -569,8 +337,9 @@ void Inventory::insertRowsRecursive(Mode
}
parentItem->appendChild(item);
}
- endInsertRows();
+ emit endInsertRows();
+
//
// finally check if the just added items have children we need
// to insert recursively
@@ -582,37 +351,35 @@ void Inventory::insertRowsRecursive(Mode
}
}
-void Inventory::removeRowsRecursive(const QModelIndex & parent, int startRow, int endRow)
+void Inventory::removeRowsRecursive(ModelItem * parent, int startRow, int endRow)
{
+ I(parent);
I(startRow >= 0);
- I(parent.isValid() || parent.parent() == QModelIndex());
- I(endRow >= startRow && endRow < rowCount(parent));
+ I(endRow >= startRow && endRow < parent->childCount());
// we need to ensure that we recursively delete all childrens before we
// actually delete the requested items for parent, otherwise Qt will
// throw too many signals around
- QModelIndexList indexesToDelete;
+ QList itemsToDelete;
for (int i=startRow; i<=endRow; i++)
{
- QModelIndex child = index(i, 0, parent);
- I(child.isValid());
- int count = rowCount(child);
- if (count > 0)
+ ModelItem * child = parent->child(i);
+ I(child);
+ int childCount = child->childCount();
+ if (childCount > 0)
{
- removeRowsRecursive(child, 0, count - 1);
+ removeRowsRecursive(child, 0, childCount - 1);
}
- indexesToDelete.append(child);
+ itemsToDelete.append(child);
}
- beginRemoveRows(parent, startRow, endRow);
- foreach (QModelIndex index, indexesToDelete)
- {
- I(index.isValid());
- I(rowCount(index) == 0);
+ emit beginRemoveRows(parent, startRow, endRow);
- ModelItem * item = static_cast(index.internalPointer());
+ foreach (ModelItem * item, itemsToDelete)
+ {
I(item);
+ I(item->childCount() == 0);
InventoryItem * invitem = qobject_cast(item);
if (invitem)
@@ -623,6 +390,7 @@ void Inventory::removeRowsRecursive(cons
item->parent()->removeChild(item);
delete item;
}
- endRemoveRows();
+
+ emit endRemoveRows();
}
============================================================
--- src/model/Inventory.h 2e63d286970c94f673751cd43e67bf9791a32eca
+++ src/model/Inventory.h 932f48c5ed90807b37a26c894a139f93985454be
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2006 by Thomas Keller *
+ * Copyright (C) 2008 by Thomas Keller *
* address@hidden *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -22,27 +22,19 @@
#include "AutomateCommand.h"
#include "InventoryItem.h"
-#include
+class InventoryModel;
-class Inventory : public QAbstractItemModel, public AutomateCommand
+class Inventory : public QObject, public AutomateCommand
{
Q_OBJECT
+
+ friend class InventoryModel;
+
public:
Inventory(QObject *);
~Inventory();
QMap findUnaccountedRenames() const;
-
- QVariant data(const QModelIndex &, int) const;
- Qt::ItemFlags flags(const QModelIndex &) const;
- QVariant headerData(int, Qt::Orientation, int) const;
- QModelIndex index(int, int, const QModelIndex &) const;
- QModelIndex parent(const QModelIndex &) const;
- int rowCount(const QModelIndex &) const;
- int columnCount(const QModelIndex &) const;
- bool canFetchMore( const QModelIndex &) const;
- void fetchMore(const QModelIndex &);
-
static const int QueryLevel;
public slots:
@@ -51,20 +43,21 @@ private:
private:
void processTaskResult(const MonotoneTask &);
- QModelIndex indexFromItem(ModelItem *, int) const;
+ void readInventory(const QString &, bool fullQuery = false);
void insertRowsRecursive(ModelItem *, const QMap > &);
- void removeRowsRecursive(const QModelIndex &, int, int);
- void readInventory(const QString &, bool fullQuery = false);
+ void removeRowsRecursive(ModelItem *, int, int);
ModelItem * rootItem;
- QString branchName;
QMap itemMap;
WorkspacePath workspacePath;
-private slots:
- void setWorkspacePath();
+signals:
+ void beginInsertRows(ModelItem *, int, int);
+ void endInsertRows();
-signals:
+ void beginRemoveRows(ModelItem *, int, int);
+ void endRemoveRows();
+
void inventoryRead(const QString &);
void invalidWorkspaceFormat(const QString &);
};
============================================================
--- src/view/WorkspaceWindow.cpp 61f4579fd647177555ca083c93caea741b4100e6
+++ src/view/WorkspaceWindow.cpp 8f2511b6d776f68716962305e51dce09fe25bc18
@@ -70,11 +70,6 @@ void WorkspaceWindow::init()
if (!dialogManager)
{
dialogManager = new WorkspaceDialogManager(this);
-
- connect(
- this, SIGNAL(workspaceSelected(const WorkspacePath &)),
- dialogManager, SLOT(init(const WorkspacePath &))
- );
}
connect(
@@ -89,7 +84,7 @@ void WorkspaceWindow::init()
connect(
menuBar, SIGNAL(checkForUnaccountedRenames()),
- this, SLOT(checkForUnaccountedRenames())
+ dialogManager, SLOT(checkForUnaccountedRenames())
);
DatabaseWindow::init();
@@ -194,17 +189,8 @@ void WorkspaceWindow::setup()
listSplitter->restoreState();
// models
- invModel = new Inventory(this);
- connect(
- this, SIGNAL(workspaceSelected(const WorkspacePath &)),
- invModel, SLOT(setWorkspacePath(const WorkspacePath &))
- );
-
+ invModel = new InventoryModel(this);
attrModel = new GetAttributes(this);
- connect(
- this, SIGNAL(workspaceSelected(const WorkspacePath &)),
- attrModel, SLOT(setWorkspacePath(const WorkspacePath &))
- );
proxyModelFolderTree = new InventoryProxyModel(this, true);
proxyModelFileList = new InventoryProxyModel(this, false);
@@ -273,8 +259,10 @@ void WorkspaceWindow::load(const QString
Settings::addItemToList("RecentWorkspaceList", workspacePath, 5);
- emit workspaceSelected(workspacePath);
- emit databaseSelected(APP->manager()->getDatabaseFilePath(workspacePath));
+ reinterpret_cast(dialogManager)->init(workspacePath);
+ invModel->setWorkspacePath(workspacePath);
+ invModel->refresh();
+ attrModel->setWorkspacePath(workspacePath);
}
void WorkspaceWindow::openFile(const QString & filePath)
@@ -282,12 +270,6 @@ void WorkspaceWindow::openFile(const QSt
Platform::openFile(workspacePath + "/" + filePath);
}
-void WorkspaceWindow::checkForUnaccountedRenames()
-{
- reinterpret_cast(dialogManager)
- ->checkForUnaccountedRenames();
-}
-
void WorkspaceWindow::readAttributes(const QModelIndex & index)
{
QModelIndex sourceIndex = static_cast
============================================================
--- src/view/WorkspaceWindow.h cdb9e70c4d3328d8d963a488efc13c307026843f
+++ src/view/WorkspaceWindow.h baa9b2a1c5ccc191ca799df1b255704138795427
@@ -21,7 +21,7 @@
#include "DatabaseWindow.h"
-#include "Inventory.h"
+#include "InventoryModel.h"
#include "InventoryProxyModel.h"
#include "GetAttributes.h"
@@ -44,9 +44,6 @@ public:
//! throws GuitoneException
virtual void load(const QString &);
-signals:
- void workspaceSelected(const WorkspacePath &);
-
protected:
WorkspacePath workspacePath;
@@ -58,7 +55,7 @@ protected:
QStatusBar * statusBar;
IconHelp * iconHelp;
- Inventory * invModel;
+ InventoryModel * invModel;
GetAttributes * attrModel;
InventoryProxyModel * proxyModelFolderTree;
InventoryProxyModel * proxyModelFileList;
@@ -67,7 +64,6 @@ private slots:
void readAttributes(const QModelIndex &);
void invalidWorkspaceFormat(const QString &);
void openFile(const QString &);
- void checkForUnaccountedRenames();
};
#endif
============================================================
--- src/view/dialogs/WorkspaceDialogManager.cpp 8b8904590203dc8cd1c4e66239cd40b808529033
+++ src/view/dialogs/WorkspaceDialogManager.cpp a07aa7f29c83306b0af77ec51f791e0966de43e6
@@ -116,6 +116,7 @@ void WorkspaceDialogManager::showRevisio
revisionDiff->forWorkspace(workspacePath, file, base, target);
showDialog(revisionDiff);
}
+
void WorkspaceDialogManager::checkForUnaccountedRenames()
{
if (!unaccountedRenames)