Skip to content

Commit

Permalink
WIP: Migrate views to basetreemodel; Add directories to views
Browse files Browse the repository at this point in the history
  • Loading branch information
ailujezi committed Dec 4, 2023
1 parent df4afd1 commit 58f4315
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ namespace hal
GraphTabWidget* mTabView;

QTableView* mContextTableView;
ContextTableModel* mContextTableModel;
ContextTreeModel* mContextTableModel;
ContextTableProxyModel* mContextTableProxyModel;

Searchbar* mSearchbar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -47,6 +60,7 @@ namespace hal
void appendData(QVariant data) override;
int getColumnCount() const override;
int row() const;
bool isDirectory() const;
};

/**
Expand All @@ -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

Expand All @@ -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;
///@}

Expand All @@ -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.
Expand Down Expand Up @@ -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).
Expand All @@ -131,6 +145,7 @@ namespace hal
void handleDataChanged();

private:
ContextTreeItem *mCurrentDirectory;
std::map<GraphContext *, ContextTreeItem *> mContextMap;
};
} // namespace hal
6 changes: 3 additions & 3 deletions plugins/gui/include/gui/graph_widget/graph_context_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace hal
class GraphShader;
class GraphContext;

class ContextTableModel;
class ContextTreeModel;
class SettingsItemCheckbox;

/**
Expand Down Expand Up @@ -342,7 +342,7 @@ namespace hal
*
* @returns the context table model
*/
ContextTableModel* getContextTableModel() const;
ContextTreeModel* getContextTableModel() const;

/**
* Deletes all contexts.
Expand Down Expand Up @@ -390,7 +390,7 @@ namespace hal
private:
// QVector<GraphContext*> mGraphContexts;

ContextTableModel* mContextTableModel;
ContextTreeModel* mContextTableModel;
u32 mMaxContextId;
void dump(const QString& title, u32 mid, u32 xid) const;
SettingsItemCheckbox* mSettingDebugGrid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -91,7 +96,7 @@ namespace hal
return QVariant();
}

void ContextTableModel::clear()
void ContextTreeModel::clear()
{
beginResetModel();

Expand All @@ -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);
Expand All @@ -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<ContextTreeItem*>(item->getParent());
assert(item);
assert(parent);

QModelIndex index = getIndex(parent);
QModelIndex index = getIndexFromItem(parent);

int row = item->row();

Expand Down Expand Up @@ -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);
Expand All @@ -184,9 +195,9 @@ namespace hal
model_index = index(*i, 0, model_index);
return model_index;
}
}*/

const QVector<GraphContext *> &ContextTableModel::list() const
const QVector<GraphContext *> &ContextTreeModel::list() const
{
QVector<GraphContext *> key;
for (auto it = mContextMap.begin(); it != mContextMap.end(); ++it) {
Expand Down
6 changes: 2 additions & 4 deletions plugins/gui/src/graph_widget/graph_context_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -528,7 +528,7 @@ namespace hal
return new ModuleShader(context);
}

ContextTableModel* GraphContextManager::getContextTableModel() const
ContextTreeModel* GraphContextManager::getContextTableModel() const
{
return mContextTableModel;
}
Expand Down Expand Up @@ -599,9 +599,7 @@ namespace hal
continue;
}

mContextTableModel->beginInsertContext(context);
mContextTableModel->addContext(context);
mContextTableModel->endInsertContext();
if (visibleFlag)
Q_EMIT contextCreated(context);
}
Expand Down

0 comments on commit 58f4315

Please sign in to comment.