diff --git a/plugins/gui/include/gui/context_manager_widget/context_manager_widget.h b/plugins/gui/include/gui/context_manager_widget/context_manager_widget.h index ab6748c9387..7f398b63342 100644 --- a/plugins/gui/include/gui/context_manager_widget/context_manager_widget.h +++ b/plugins/gui/include/gui/context_manager_widget/context_manager_widget.h @@ -176,7 +176,7 @@ namespace hal GraphTabWidget* mTabView; QTableView* mContextTableView; - ContextTableModel* mContextTableModel; + ContextTreeModel* mContextTableModel; ContextTableProxyModel* mContextTableProxyModel; Searchbar* mSearchbar; diff --git a/plugins/gui/include/gui/context_manager_widget/models/context_table_model.h b/plugins/gui/include/gui/context_manager_widget/models/context_table_model.h index 6882b1089d0..d52d3a0c1af 100644 --- a/plugins/gui/include/gui/context_manager_widget/models/context_table_model.h +++ b/plugins/gui/include/gui/context_manager_widget/models/context_table_model.h @@ -33,11 +33,24 @@ namespace hal { + + class ContextDirectory + { + private: + u32 mId; + QString mName; + + public: + ContextDirectory(u32 id, QString name):mId(id), mName(name){} + + }; + class ContextTreeItem : public BaseTreeItem { private: GraphContext* mContext; + ContextDirectory* mDirectory; public: ContextTreeItem(GraphContext* context); @@ -47,6 +60,7 @@ namespace hal void appendData(QVariant data) override; int getColumnCount() const override; int row() const; + bool isDirectory() const; }; /** @@ -58,7 +72,7 @@ namespace hal * the ContextManagerWidget to store and display the data. For specific information on how to * implement a table model, refer to qt's QAbstractTableModel class and its examples. */ - class ContextTableModel : public BaseTreeModel + class ContextTreeModel : public BaseTreeModel { Q_OBJECT @@ -68,12 +82,12 @@ namespace hal * * @param parent - The widget's parent. */ - ContextTableModel(QObject* parent = nullptr); + ContextTreeModel(QObject* parent = nullptr); /** @name Overwritten model functions */ ///@{ - int rowCount(const QModelIndex& parent = QModelIndex()) const override; + //int rowCount(const QModelIndex& parent = QModelIndex()) const override; QVariant data(const QModelIndex& inddex, int role = Qt::DisplayRole) const override; ///@} @@ -83,7 +97,7 @@ namespace hal * @param context - The context to add. * @param parent - The Parent of the context. */ - void addContext(GraphContext* context, BaseTreeItem* parent); + void addContext(GraphContext* context, BaseTreeItem* parent = nullptr); /** * Removes a given GraphContext from the model. @@ -114,7 +128,7 @@ namespace hal * @param item - The ContextTreeitem to search for in the item model * @returns the model index of the specified ContextTreeitem */ - QModelIndex getIndex(const BaseTreeItem * const item) const; + //QModelIndex getIndex(const BaseTreeItem * const item) const; /** * Resets the model (removes all GraphContext%s). @@ -131,6 +145,7 @@ namespace hal void handleDataChanged(); private: + ContextTreeItem *mCurrentDirectory; std::map mContextMap; }; } // namespace hal diff --git a/plugins/gui/include/gui/graph_widget/graph_context_manager.h b/plugins/gui/include/gui/graph_widget/graph_context_manager.h index 494e14bddfc..e479ecaf975 100644 --- a/plugins/gui/include/gui/graph_widget/graph_context_manager.h +++ b/plugins/gui/include/gui/graph_widget/graph_context_manager.h @@ -42,7 +42,7 @@ namespace hal class GraphShader; class GraphContext; - class ContextTableModel; + class ContextTreeModel; class SettingsItemCheckbox; /** @@ -342,7 +342,7 @@ namespace hal * * @returns the context table model */ - ContextTableModel* getContextTableModel() const; + ContextTreeModel* getContextTableModel() const; /** * Deletes all contexts. @@ -390,7 +390,7 @@ namespace hal private: // QVector mGraphContexts; - ContextTableModel* mContextTableModel; + ContextTreeModel* mContextTableModel; u32 mMaxContextId; void dump(const QString& title, u32 mid, u32 xid) const; SettingsItemCheckbox* mSettingDebugGrid; diff --git a/plugins/gui/src/context_manager_widget/context_manager_widget.cpp b/plugins/gui/src/context_manager_widget/context_manager_widget.cpp index bc319c56cc1..23b99faaf14 100644 --- a/plugins/gui/src/context_manager_widget/context_manager_widget.cpp +++ b/plugins/gui/src/context_manager_widget/context_manager_widget.cpp @@ -107,8 +107,8 @@ namespace hal connect(mContextTableView, &QTableView::customContextMenuRequested, this, &ContextManagerWidget::handleContextMenuRequest); connect(mContextTableView, &QTableView::doubleClicked, this, &ContextManagerWidget::handleOpenContextClicked); connect(mContextTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ContextManagerWidget::handleSelectionChanged); - connect(mContextTableModel, &ContextTableModel::rowsRemoved, this, &ContextManagerWidget::handleDataChanged); - connect(mContextTableModel, &ContextTableModel::rowsInserted, this, &ContextManagerWidget::handleDataChanged); + connect(mContextTableModel, &ContextTreeModel::rowsRemoved, this, &ContextManagerWidget::handleDataChanged); + connect(mContextTableModel, &ContextTreeModel::rowsInserted, this, &ContextManagerWidget::handleDataChanged); connect(mSearchbar, &Searchbar::triggerNewSearch, this, &ContextManagerWidget::updateSearchIcon); connect(mSearchbar, &Searchbar::triggerNewSearch, mContextTableProxyModel, &ContextTableProxyModel::startSearch); diff --git a/plugins/gui/src/context_manager_widget/models/context_table_model.cpp b/plugins/gui/src/context_manager_widget/models/context_table_model.cpp index f0d4dcb6648..dd7fa4e674a 100644 --- a/plugins/gui/src/context_manager_widget/models/context_table_model.cpp +++ b/plugins/gui/src/context_manager_widget/models/context_table_model.cpp @@ -55,20 +55,25 @@ namespace hal return parent->getRowForChild(this); } - ContextTableModel::ContextTableModel(QObject* parent) : BaseTreeModel(parent) + bool ContextTreeItem::isDirectory() const + { + return mDirectory != nullptr; + } + + ContextTreeModel::ContextTreeModel(QObject* parent) : BaseTreeModel(parent), mCurrentDirectory(nullptr) { setHeaderLabels(QStringList() << "View Name" << "Timestamp"); } - int ContextTableModel::rowCount(const QModelIndex& parent) const + /*int ContextTreeModel::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent) return mContextMap.size(); - } + }*/ - QVariant ContextTableModel::data(const QModelIndex& index, int role) const + QVariant ContextTreeModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); @@ -91,7 +96,7 @@ namespace hal return QVariant(); } - void ContextTableModel::clear() + void ContextTreeModel::clear() { beginResetModel(); @@ -101,13 +106,19 @@ namespace hal endResetModel(); } - void ContextTableModel::addContext(GraphContext* context, BaseTreeItem* parent) + void ContextTreeModel::addContext(GraphContext* context, BaseTreeItem* parent) { ContextTreeItem* item = new ContextTreeItem(context); - item->setParent(parent); + if (parent) + item->setParent(parent); + else if(mCurrentDirectory) + item->setParent(mCurrentDirectory); + else + item->setParent(mRootItem); + - QModelIndex index = getIndex(parent); + QModelIndex index = getIndexFromItem(parent); int row = parent->getChildCount(); beginInsertRows(index, row, row); @@ -118,18 +129,18 @@ namespace hal //connect(context,&GraphContext::dataChanged,this,&ContextTableModel::handleDataChanged); connect(context, &GraphContext::dataChanged, this, [item, this]() { - Q_EMIT dataChanged(getIndex(item), getIndex(item)); + Q_EMIT dataChanged(getIndexFromItem(item), getIndexFromItem(item)); }); } - void ContextTableModel::removeContext(GraphContext *context) + void ContextTreeModel::removeContext(GraphContext *context) { ContextTreeItem* item = mContextMap.find(context)->second; ContextTreeItem* parent = static_cast(item->getParent()); assert(item); assert(parent); - QModelIndex index = getIndex(parent); + QModelIndex index = getIndexFromItem(parent); int row = item->row(); @@ -165,7 +176,7 @@ namespace hal return (mContextList)[index.row()]; }*/ - QModelIndex ContextTableModel::getIndex(const BaseTreeItem* const item) const + /* QModelIndex ContextTableModel::getIndex(const BaseTreeItem* const item) const { assert(item); @@ -184,9 +195,9 @@ namespace hal model_index = index(*i, 0, model_index); return model_index; - } + }*/ - const QVector &ContextTableModel::list() const + const QVector &ContextTreeModel::list() const { QVector key; for (auto it = mContextMap.begin(); it != mContextMap.end(); ++it) { diff --git a/plugins/gui/src/graph_widget/graph_context_manager.cpp b/plugins/gui/src/graph_widget/graph_context_manager.cpp index df6afdeb2b4..52e599f74f7 100644 --- a/plugins/gui/src/graph_widget/graph_context_manager.cpp +++ b/plugins/gui/src/graph_widget/graph_context_manager.cpp @@ -30,7 +30,7 @@ namespace hal "Appearance:Graph View", "If set net grouping colors are also applied to input and output pins of gates"); - GraphContextManager::GraphContextManager() : mContextTableModel(new ContextTableModel()), mMaxContextId(0) + GraphContextManager::GraphContextManager() : mContextTableModel(new ContextTreeModel()), mMaxContextId(0) { mSettingDebugGrid = new SettingsItemCheckbox("GUI Debug Grid", "debug/grid", @@ -528,7 +528,7 @@ namespace hal return new ModuleShader(context); } - ContextTableModel* GraphContextManager::getContextTableModel() const + ContextTreeModel* GraphContextManager::getContextTableModel() const { return mContextTableModel; } @@ -599,9 +599,7 @@ namespace hal continue; } - mContextTableModel->beginInsertContext(context); mContextTableModel->addContext(context); - mContextTableModel->endInsertContext(); if (visibleFlag) Q_EMIT contextCreated(context); }