From 2fae36c0be38a86da8bcc2e85166684e318f60bd Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 8 Nov 2023 15:30:13 +0100 Subject: [PATCH] Migrate ModuleModel to BaseTreeModel and ModuleItem to BaseTreeItem --- .../include/gui/module_model/module_item.h | 22 ------ .../include/gui/module_model/module_model.h | 36 --------- plugins/gui/src/module_model/module_item.cpp | 15 ---- plugins/gui/src/module_model/module_model.cpp | 76 +------------------ 4 files changed, 3 insertions(+), 146 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_item.h b/plugins/gui/include/gui/module_model/module_item.h index bba273bd014..379fa6726d3 100644 --- a/plugins/gui/include/gui/module_model/module_item.h +++ b/plugins/gui/include/gui/module_model/module_item.h @@ -63,28 +63,6 @@ namespace hal */ ModuleItem(const u32 id, const TreeItemType type = TreeItemType::Module); - /** - * Appends a child ModuleItem to this ModuleItem. - * - * @param row - The index of the childs of this ModuleItem the new child should be moved to - * @param child - The new child to be inserted - */ - void insertChild(int row, ModuleItem* child); - - /** - * Removes a child ModuleItem from this ModuleItem. - * - * @param child - The child to remove - */ - void removeChild(ModuleItem* child); - - /** - * Inserts a child ModuleItem at the end of the children list of this ModuleItem. - * - * @param child - The child to be appended - */ - void appendChild(ModuleItem* child); - /** * Given a set of ModuleItems (in a map [id]->[ModuleItem]) this function adds each ModuleItem of this set as * a new children if its underlying module is a submodule (child) of the underlying module of this ModuleItem. diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index 7c619b79dfe..2b0fb9dee9e 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -61,41 +61,6 @@ namespace hal explicit ModuleModel(QObject* parent = nullptr); // === Pure Virtual === - /** - * Returns the index of the item in the model specified by the given row, column and parent index. - * - * @param row - The row of the item - * @param column - The column of the item - * @param parent - the index of the parent of the item - * @returns the index at the specified position - */ - QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; - - /** - * Returns the parent of the model item with the given index. If the item has no parent (i.e. index is - * invalid or module is the top module), and invalid QModelIndex is returned. - * - * @param index - The index to find the parent for - * @returns the model index of the parent - */ - QModelIndex parent(const QModelIndex& index) const override; - - /** - * Returns the number of rows under the given parent (i.e. the number of children of the parent). - * - * @param parent - The model index of the parent - * @returns the number of rows under the given parent - */ - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - - /** - * Returns the number of columns for the children of the given parent. Since the module model only contains - * one column this function returns always 1. - * - * @param parent - The model index of the parent - * @returns the number of columns for the children of the given parent. Always 1. - */ - int columnCount(const QModelIndex& parent = QModelIndex()) const override; /** * Returns the data stored under the given role for the item referred to by the index. @@ -239,7 +204,6 @@ namespace hal bool isModifying(); private: - ModuleItem* mTopModuleItem; QMap mModuleMap; QMap mGateMap; diff --git a/plugins/gui/src/module_model/module_item.cpp b/plugins/gui/src/module_model/module_item.cpp index d97f6126f38..cbf82f07c87 100644 --- a/plugins/gui/src/module_model/module_item.cpp +++ b/plugins/gui/src/module_model/module_item.cpp @@ -28,21 +28,6 @@ ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : } } - void ModuleItem::insertChild(int row, ModuleItem* child) - { - mChildItems.insert(row, child); - } - - void ModuleItem::removeChild(ModuleItem* child) - { - mChildItems.removeOne(child); - } - - void ModuleItem::appendChild(ModuleItem* child) - { - mChildItems.append(child); - } - void ModuleItem::appendExistingChildIfAny(const QMap& moduleMap) { if(mType != TreeItemType::Module) // only module can have children diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index e37ec8e8058..df17670cdd2 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -9,73 +9,12 @@ namespace hal { - ModuleModel::ModuleModel(QObject* parent) : BaseTreeModel(parent), mTopModuleItem(nullptr) + ModuleModel::ModuleModel(QObject* parent) : BaseTreeModel(parent) { // use root item to store header information setHeaderLabels(QStringList() << "Name" << "ID" << "Type"); } - QModelIndex ModuleModel::index(int row, int column, const QModelIndex& parent) const - { - // BEHAVIOR FOR ILLEGAL INDICES IS UNDEFINED - // SEE QT DOCUMENTATION - if (!hasIndex(row, column, parent)) - return QModelIndex(); - - if (!parent.isValid()) - { - if (row == 0 && column >= 0 && column < 3 && mTopModuleItem) - return createIndex(0, column, mTopModuleItem); - else - return QModelIndex(); - } - - if (column < 0 || column >= 3 || parent.column() < 0 || parent.column() >= 3) - return QModelIndex(); - - ModuleItem* parent_item = getItem(parent); - - ModuleItem* child_item = static_cast(parent_item)->child(row); - assert(child_item); - - return createIndex(row, column, child_item); - } - - QModelIndex ModuleModel::parent(const QModelIndex& index) const - { - if (!index.isValid()) - return QModelIndex(); - - ModuleItem* item = getItem(index); - - if (item == mTopModuleItem) - return QModelIndex(); - - ModuleItem* parent_item = static_cast(item->getParent()); - return createIndex(parent_item->row(), 0, parent_item); - - } - - int ModuleModel::rowCount(const QModelIndex& parent) const - { - if (!parent.isValid()) // ?? - return 1; - - //if (parent.column() != 0) - // return 0; - - ModuleItem* parent_item = getItem(parent); - - return parent_item->childCount(); - } - - int ModuleModel::columnCount(const QModelIndex& parent) const - { - Q_UNUSED(parent) - - return 3; - } - QVariant ModuleModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) @@ -143,7 +82,7 @@ namespace hal QVector row_numbers; const ModuleItem* current_item = item; - while (current_item != mTopModuleItem) + while (current_item != mRootItem->getChild(0)) { row_numbers.append(current_item->row()); current_item = static_cast(current_item->constParent()); @@ -163,7 +102,6 @@ namespace hal mModuleMap.insert(1, item); beginInsertRows(index(0, 0, QModelIndex()), 0, 0); - mTopModuleItem = item; mRootItem->appendChild(item); endInsertRows(); @@ -187,15 +125,7 @@ namespace hal { beginResetModel(); - mTopModuleItem = nullptr; - - for (ModuleItem* m : mModuleMap) - delete m; - for (ModuleItem* g : mGateMap) - delete g; - for (ModuleItem* n : mNetMap) - delete n; - + BaseTreeModel::clear(); mModuleMap.clear(); mGateMap.clear(); mNetMap.clear();