From 005b3dd0a5d77aaf6ae0988c773a0ef395e28b62 Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 26 Jun 2023 20:42:34 +0200 Subject: [PATCH 01/36] WIP: Change TreeItem to BaseTreeItem --- .../{tree_item.h => base_tree_item.h} | 100 ++++++--- .../gui/basic_tree_model/base_tree_model.h | 14 +- .../gate_details_widget/gate_pin_tree.h | 6 +- .../gate_details_widget/pin_tree_model.h | 6 +- .../module_details_widget/module_ports_tree.h | 4 +- .../module_details_widget/module_tree_model.h | 12 +- .../netlist_elements_tree_model.h | 37 +++- .../module_details_widget/port_tree_model.h | 26 +-- .../net_details_widget/net_endpoint_table.h | 2 +- .../net_details_widget/net_module_table.h | 2 +- .../src/basic_tree_model/base_tree_item.cpp | 134 ++++++++++++ .../src/basic_tree_model/base_tree_model.cpp | 39 ++-- .../gui/src/basic_tree_model/tree_item.cpp | 147 ------------- .../gate_details_widget/gate_pin_tree.cpp | 8 +- .../gate_details_widget/pin_tree_model.cpp | 10 +- .../module_elements_tree.cpp | 2 +- .../module_ports_tree.cpp | 14 +- .../module_tree_model.cpp | 34 +-- .../netlist_elements_tree_model.cpp | 197 ++++++++++++------ .../module_details_widget/port_tree_model.cpp | 30 +-- .../tree_navigation/selection_tree_item.cpp | 2 +- .../tree_navigation/selection_tree_model.cpp | 2 +- .../tree_navigation/selection_tree_proxy.cpp | 2 +- .../waveform_viewer/src/wave_widget.cpp | 2 +- 24 files changed, 481 insertions(+), 351 deletions(-) rename plugins/gui/include/gui/basic_tree_model/{tree_item.h => base_tree_item.h} (69%) create mode 100644 plugins/gui/src/basic_tree_model/base_tree_item.cpp delete mode 100644 plugins/gui/src/basic_tree_model/tree_item.cpp diff --git a/plugins/gui/include/gui/basic_tree_model/tree_item.h b/plugins/gui/include/gui/basic_tree_model/base_tree_item.h similarity index 69% rename from plugins/gui/include/gui/basic_tree_model/tree_item.h rename to plugins/gui/include/gui/basic_tree_model/base_tree_item.h index 1fff2d116d9..7a7a657ab7d 100644 --- a/plugins/gui/include/gui/basic_tree_model/tree_item.h +++ b/plugins/gui/include/gui/basic_tree_model/base_tree_item.h @@ -39,7 +39,7 @@ namespace hal * purpose, it uses QVariants as its main type of storage for its columns. (Note: Perhaps add * additional data in form of a list or map (split it from "normal" displayed column data) */ - class TreeItem + class BaseTreeItem { // maybe add enum type for all possible scenarios? or use additional data with key to access type // and handle type handling in model...e.g.: item->getAddData("type")(structure, more generalization,...) @@ -50,25 +50,25 @@ namespace hal * * @param item - The item to copy. */ - TreeItem(const TreeItem &item); + BaseTreeItem(const BaseTreeItem &item); public: /** * The constructor. */ - TreeItem(); + BaseTreeItem(); /** * Second constructor to immediately assign column data. * * @param columnData - The item's data. */ - TreeItem(QList columnData); + BaseTreeItem(QList columnData); /** * The destructor. */ - ~TreeItem(); + virtual ~BaseTreeItem(); /** * Get the data of a specific column (most in the form of a string). @@ -76,14 +76,14 @@ namespace hal * @param column - The requested column. * @return The data if within the column count. Empty QVariant otherwise. */ - QVariant getData(int column); + virtual QVariant getData(int column) const = 0; /** * Sets the data for all columns. * * @param data - Each entry in the list represents one column. */ - void setData(QList data); + virtual void setData(QList data) = 0; /** * Sets the data for a specified column. The index must be within @@ -92,28 +92,28 @@ namespace hal * @param index - The column to set the new data. * @param data - The new column data. */ - void setDataAtIndex(int index, QVariant data); + virtual void setDataAtIndex(int index, QVariant& data); /** * Appends a new column to the item. * * @param data - The data of the new column. */ - void appendData(QVariant data); + virtual void appendData(QVariant data); /** * Get the item's parent. * * @return The parent. */ - TreeItem* getParent(); + virtual BaseTreeItem* getParent() const; /** * Sets the item's parent. * * @param parent - The parent. */ - void setParent(TreeItem* parent); + virtual void setParent(BaseTreeItem* parent); /** * Get the child of a specific row. @@ -121,21 +121,21 @@ namespace hal * @param row - The requested row. * @return The child if within bounds. Nullptr otherwise. */ - TreeItem* getChild(int row); + virtual BaseTreeItem* getChild(int row) const; /** * Get the list of all children. * * @return The list of children. */ - QList getChildren(); + virtual QList getChildren() const; /** * Appends a child. * * @param child - The child to append. */ - void appendChild(TreeItem* child); + virtual void appendChild(BaseTreeItem* child); /** * Inserts a child at the given index. If the index exceeds the amount @@ -144,7 +144,7 @@ namespace hal * @param index - The position at which to insert. * @param child - The child to insert. */ - void insertChild(int index, TreeItem* child); + virtual void insertChild(int index, BaseTreeItem* child); /** * Removes the child at the given row and returns it. @@ -152,7 +152,7 @@ namespace hal * @param row - The row from which to remove the child. * @return The removed child. Nullptr if row was out of bounds. */ - TreeItem* removeChildAtPos(int row); + virtual BaseTreeItem* removeChildAtPos(int row); /** * Removes the given item and returns True if removing was successful @@ -161,21 +161,21 @@ namespace hal * @param child - The child to remove. * @return True on success, False otherwise. */ - bool removeChild(TreeItem* child); + virtual bool removeChild(BaseTreeItem* child); /** * Get the number of children. * * @return The number of children. */ - int getChildCount(); + virtual int getChildCount() const; /** * Get the number of currently stored column data. * * @return The column count. */ - int getColumnCount(); + virtual int getColumnCount() const = 0; /** * Convenience method to get the row for a given item. @@ -184,7 +184,7 @@ namespace hal * @param child - The child for which the row is requested. * @return The row if the item is a child, -1 otherwise. */ - int getRowForChild(TreeItem* child); + virtual int getRowForChild(BaseTreeItem* child) const; /** * Convenience method to get the row of this item within @@ -192,7 +192,7 @@ namespace hal * * @return The row of this item if it has a parent, -1 otherwise. */ - int getOwnRow(); + virtual int getOwnRow(); /** * Stores additional data. Can be accessed by getAdditionalData. @@ -201,7 +201,7 @@ namespace hal * @param key - The key to store the data under. * @param data - The actual data to store. */ - void setAdditionalData(QString key, QVariant data); + virtual void setAdditionalData(QString key, QVariant data); /** * Retrieve the data stored under the given key. @@ -209,16 +209,64 @@ namespace hal * @param key - The key for the requested data. * @return The data if something was stored under the key, empty QVariant otherwise. */ - QVariant getAdditionalData(QString key); + virtual QVariant getAdditionalData(QString key) const; private: - TreeItem* mParent; - QList mChildren; - QList mData; + BaseTreeItem* mParent; + QList mChildren; // experimental, additional data (for anything) QMap mAdditionalData; //QList mAdditionalData; }; + + /** + * Since the BaseTreeItem class is pure virtual it cannot be instanciated for + * root tree item. + * + * RootTreeItem class also provides the header labels. + */ + class RootTreeItem : public BaseTreeItem + { + QStringList mHeaderLabels; + public: + RootTreeItem(const QStringList& labels) : mHeaderLabels(labels) {;} + + /** + * Get header label for section. + * @param column The section of the header. + * @return The label for the header. + */ + QVariant getData(int column) const override; + + /** + * Set header label to new value. If element in list does not exist it gets created. + * @param column The section of the header. + * @param data The string value. + */ + void setData(QList data) override; + + /** + * Sets the data for a specified column. The index must be within + * already existing boundaries (for example, add dummy data beforehand). + * + * @param index - The column to set the new data. + * @param data - The new column data. + */ + void setDataAtIndex(int index, QVariant& data); + + /** + * Appends a new column to the item. + * + * @param data - The data of the new column. + */ + void appendData(QVariant data); + + /** + * Get number of sections for which header label exist. + * @return The number of sections. + */ + int getColumnCount() const override { return mHeaderLabels.size(); } + }; } diff --git a/plugins/gui/include/gui/basic_tree_model/base_tree_model.h b/plugins/gui/include/gui/basic_tree_model/base_tree_model.h index c836f1cc2dc..860aa7abaaf 100644 --- a/plugins/gui/include/gui/basic_tree_model/base_tree_model.h +++ b/plugins/gui/include/gui/basic_tree_model/base_tree_model.h @@ -26,7 +26,7 @@ #pragma once #include -#include "tree_item.h" +#include "base_tree_item.h" namespace hal { @@ -101,7 +101,7 @@ namespace hal * * @param firstLevelItems - All items that will be appended to this model's root item. */ - void setContent(QList firstLevelItems); + void setContent(QList firstLevelItems); /** * Resets the model (deletes the tree). @@ -113,7 +113,7 @@ namespace hal * classed to initialize * @param labels */ - void setHeaderLabels(QList labels); + void setHeaderLabels(const QStringList& label); // important converter methods /** @@ -122,7 +122,7 @@ namespace hal * @param item - The item from which to get the index. * @return The index. */ - QModelIndex getIndexFromItem(TreeItem* item) const; + QModelIndex getIndexFromItem(BaseTreeItem* item) const; /** * Helper method to convert between the index and its item. @@ -130,7 +130,7 @@ namespace hal * @param index - The index to convert. * @return The internal item. */ - TreeItem* getItemFromIndex(QModelIndex index) const; + BaseTreeItem* getItemFromIndex(QModelIndex index) const; /** * Convenient function to get the root item to which the tree is appended @@ -138,10 +138,10 @@ namespace hal * * @return The root item. */ - TreeItem* getRootItem() const; + BaseTreeItem* getRootItem() const; protected: - TreeItem* mRootItem; + BaseTreeItem* mRootItem; }; } diff --git a/plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pin_tree.h b/plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pin_tree.h index 2d22705060f..1d23ff76df1 100644 --- a/plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pin_tree.h +++ b/plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pin_tree.h @@ -33,7 +33,7 @@ namespace hal { class GatePinsTreeModel; class Gate; - class TreeItem; + class BaseTreeItem; class GraphNavigationWidget; /** @@ -98,8 +98,8 @@ namespace hal bool mClearSelection; //helper functions - void buildPythonMenuForPin(QMenu &menu, TreeItem* clickedPinItem); - void buildPythonMenuForPinGroup(QMenu &menu, TreeItem* clickedPinIGrouptem); + void buildPythonMenuForPin(QMenu &menu, BaseTreeItem* clickedPinItem); + void buildPythonMenuForPinGroup(QMenu &menu, BaseTreeItem* clickedPinIGrouptem); void addSourceOurDestinationToSelection(int netId, bool isInputPin); void handleNavigationCloseRequested(); void handleNavigationJumpRequested(const Node& origin, const u32 via_net, const QSet& to_gates, const QSet& to_modules); diff --git a/plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h b/plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h index 3002aed1b3f..a9bb61b9836 100644 --- a/plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h @@ -87,7 +87,7 @@ class GatePinsTreeModel : public BaseTreeModel * @param item - The treeitem from which to get the connected nets. * @return A list of net ids. */ - QList getNetIDsOfTreeItem(TreeItem* item); + QList getNetIDsOfTreeItem(BaseTreeItem* item); /** * Get the type (enum) of a given item. @@ -95,7 +95,7 @@ class GatePinsTreeModel : public BaseTreeModel * @param item - The item for which the type is requested. * @return The item's type. */ - itemType getTypeOfItem(TreeItem* item); + itemType getTypeOfItem(BaseTreeItem* item); /** * Get the number of displayed pins (the number of pins of all types). @@ -117,7 +117,7 @@ class GatePinsTreeModel : public BaseTreeModel private: int mGateId; - QMap mPinGroupingToTreeItem; + QMap mPinGroupingToTreeItem; }; diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_ports_tree.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_ports_tree.h index bf70d682e4c..75918f63aeb 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_ports_tree.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_ports_tree.h @@ -33,7 +33,7 @@ namespace hal { class Module; class ModulePinsTreeModel; - class TreeItem; + class BaseTreeItem; /** * @brief A widget to display the ports of a given module. @@ -104,7 +104,7 @@ namespace hal * (and if yes it returns the group id, otherwise -1), * second boolean = true if only pins (and no groups) were selected. */ - std::tuple, std::pair, bool> getSelectedPins(); + std::tuple, std::pair, bool> getSelectedPins(); }; } diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h index 9dd4d29f54f..68df1446122 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h @@ -33,7 +33,7 @@ namespace hal class Module; class Gate; class Net; - class TreeItem; + class BaseTreeItem; class ModuleTreeModel : public BaseTreeModel { @@ -68,7 +68,7 @@ namespace hal * @param item - The item for which the type is requested. * @return The item's type. */ - itemType getTypeOfItem(TreeItem* item) const; + itemType getTypeOfItem(BaseTreeItem* item) const; /** * Disconnects all events from the model. Can be called to increase performance when @@ -108,11 +108,11 @@ namespace hal bool mEventsConnected = false; int mModId; - QMap mModuleToTreeitems; - QMap mGateToTreeitems; + QMap mModuleToTreeitems; + QMap mGateToTreeitems; //necessary because setModule uses beginResetModel (should not be called by each recursive iteration) - void moduleRecursive(Module* mod, TreeItem* modItem); + void moduleRecursive(Module* mod, BaseTreeItem* modItem); //perhaps more performance instead of setting the whole displayed module anew void updateGatesOfModule(Module* mod); @@ -123,7 +123,7 @@ namespace hal * @param item - The requested item. * @return A module, net, or gate icon depending on the item's type. */ - QIcon getIconFromItem(TreeItem* item) const; + QIcon getIconFromItem(BaseTreeItem* item) const; void clearOwnStructures(); diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h index 086d9185199..8c4403812d1 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h @@ -27,7 +27,7 @@ #include #include -//#include "gui/new_selection_details_widget/models/tree_item.h" +//#include "gui/new_selection_details_widget/models/base_tree_item.h" #include "gui/basic_tree_model/base_tree_model.h" namespace hal @@ -35,7 +35,24 @@ namespace hal class Module; class Gate; class Net; - class TreeItem; + class BaseTreeItem; + + class NetlistElementsTreeitem : public BaseTreeItem + { + public: + enum class Type {module = 0, gate = 1, net = 2}; + private: + QString mType; + int mId; + QString mName; + public: + + NetlistElementsTreeitem(const QString& name, int id, QString tp); + QVariant getData(int column) const override; + void setData(QList data) override; + void setDataAtIndex(int index, QVariant& data) override; + int getColumnCount() const override; + }; /** * @ingroup utility_widgets-selection_details @@ -110,7 +127,7 @@ namespace hal * @param item - The item for which the type is requested. * @return The item's type. */ - itemType getTypeOfItem(TreeItem* item) const; + itemType getTypeOfItem(NetlistElementsTreeitem* item) const; /** * Get the module/gate/net id that the given item represents. @@ -119,7 +136,7 @@ namespace hal * @param item - The item from which to extract the id. * @return The corresponding module, gate, or net id. */ - int getRepresentedIdOfItem(TreeItem* item) const; + int getRepresentedIdOfItem(NetlistElementsTreeitem* item) const; /** @name Event Handler Functions */ @@ -173,12 +190,12 @@ namespace hal //1) 1 map that maps "raw element pointer (gate,net,module)" to a list of treeitems //2) 3 maps with either id->treeitems or pointer->treeitems //QMultiMap mElementToTreeitem; - QMultiMap mModuleToTreeitems; - QMultiMap mGateToTreeitems; - QMultiMap mNetToTreeitems; + QMultiMap mModuleToTreeitems; + QMultiMap mGateToTreeitems; + QMultiMap mNetToTreeitems; //necessary because setModule uses beginResetModel (should not be called by each recursive iteration) - void moduleRecursive(Module* mod, TreeItem* modItem, bool showGates = true, bool showNets = true); + void moduleRecursive(Module* mod, NetlistElementsTreeitem* modItem, bool showGates = true, bool showNets = true); /** * Utility function to determine the displayed icon for a given item @@ -186,7 +203,7 @@ namespace hal * @param item - The requested item. * @return A module, net, or gate icon depending on the item's type. */ - QIcon getIconFromItem(TreeItem* item) const; + QIcon getIconFromItem(NetlistElementsTreeitem* item) const; /** * Utility function to remove all net items of the given module item and @@ -195,7 +212,7 @@ namespace hal * * @param moduleItem - The module item to modify. */ - void updateInternalNetsOfModule(TreeItem* moduleItem); + void updateInternalNetsOfModule(NetlistElementsTreeitem* moduleItem); }; diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h index 349bc1e0422..b350d58d7ab 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h @@ -87,7 +87,7 @@ namespace hal * @param item - The (port) item. * @return The net or nullptr. */ - Net* getNetFromItem(TreeItem* item); + Net* getNetFromItem(BaseTreeItem* item); /** * Get the id of the module that is currently represented. @@ -103,7 +103,7 @@ namespace hal * @param item - The item for which the type is requested. * @return The item's type. */ - itemType getTypeOfItem(TreeItem* item) const; + itemType getTypeOfItem(BaseTreeItem* item) const; /** * Returns the pin-id if the item represents a pin or the pingroup-id @@ -112,7 +112,7 @@ namespace hal * @param item - The item. * @return The pin- or pingroup-id. */ - int getIdOfItem(TreeItem* item) const; + int getIdOfItem(BaseTreeItem* item) const; /** @name Event Handler Functions */ @@ -143,20 +143,20 @@ namespace hal int mModuleId; // perhaps remove? Module* mModule; //name is (hopefully) enough to identify - QMap mNameToTreeItem; - QMap mIdToPinItem; - QMap mIdToGroupItem; + QMap mNameToTreeItem; + QMap mIdToPinItem; + QMap mIdToGroupItem; bool mIgnoreEventsFlag; - void insertItem(TreeItem* item, TreeItem* parent, int index); - void removeItem(TreeItem* item); + void insertItem(BaseTreeItem* item, BaseTreeItem* parent, int index); + void removeItem(BaseTreeItem* item); // helper functions for dnd for more clarity - void dndGroupOnGroup(TreeItem* droppedGroup, TreeItem* onDroppedGroup); - void dndGroupBetweenGroup(TreeItem* droppedGroup, int row); - void dndPinOnGroup(TreeItem* droppedPin, TreeItem* onDroppedGroup); - void dndPinBetweenPin(TreeItem* droppedPin, TreeItem* onDroppedParent, int row); - void dndPinBetweenGroup(TreeItem* droppedPin, int row); + void dndGroupOnGroup(BaseTreeItem* droppedGroup, BaseTreeItem* onDroppedGroup); + void dndGroupBetweenGroup(BaseTreeItem* droppedGroup, int row); + void dndPinOnGroup(BaseTreeItem* droppedPin, BaseTreeItem* onDroppedGroup); + void dndPinBetweenPin(BaseTreeItem* droppedPin, BaseTreeItem* onDroppedParent, int row); + void dndPinBetweenGroup(BaseTreeItem* droppedPin, int row); }; } diff --git a/plugins/gui/include/gui/selection_details_widget/net_details_widget/net_endpoint_table.h b/plugins/gui/include/gui/selection_details_widget/net_details_widget/net_endpoint_table.h index 85c3a9b3b12..8b980ab0adf 100644 --- a/plugins/gui/include/gui/selection_details_widget/net_details_widget/net_endpoint_table.h +++ b/plugins/gui/include/gui/selection_details_widget/net_details_widget/net_endpoint_table.h @@ -32,7 +32,7 @@ namespace hal { class EndpointTableModel; class Net; - class TreeItem; + class BaseTreeItem; class NetEndpointTable : public QTableView { diff --git a/plugins/gui/include/gui/selection_details_widget/net_details_widget/net_module_table.h b/plugins/gui/include/gui/selection_details_widget/net_details_widget/net_module_table.h index 5781289741f..408e0bf6319 100644 --- a/plugins/gui/include/gui/selection_details_widget/net_details_widget/net_module_table.h +++ b/plugins/gui/include/gui/selection_details_widget/net_details_widget/net_module_table.h @@ -33,7 +33,7 @@ namespace hal { class ModuleTableModel; class Net; - class TreeItem; + class BaseTreeItem; class NetModuleTable : public QTableView { diff --git a/plugins/gui/src/basic_tree_model/base_tree_item.cpp b/plugins/gui/src/basic_tree_model/base_tree_item.cpp new file mode 100644 index 00000000000..469f5e33d79 --- /dev/null +++ b/plugins/gui/src/basic_tree_model/base_tree_item.cpp @@ -0,0 +1,134 @@ +#include "gui/basic_tree_model/base_tree_item.h" + + +namespace hal +{ + BaseTreeItem::BaseTreeItem() : mParent(nullptr) + { + + } + + + BaseTreeItem::~BaseTreeItem() + { + for(BaseTreeItem* item : mChildren) + delete item; + } + + + BaseTreeItem *BaseTreeItem::getParent() const + { + return mParent; + } + + void BaseTreeItem::setParent(BaseTreeItem *parent) + { + mParent = parent; + } + + BaseTreeItem *BaseTreeItem::getChild(int row) const + { + return (row < 0 || row >= mChildren.size()) ? nullptr : mChildren.at(row); + } + + QList BaseTreeItem::getChildren() const + { + return mChildren; + } + + void BaseTreeItem::appendChild(BaseTreeItem *child) + { + child->setParent(this); + mChildren.append(child); + } + + void BaseTreeItem::insertChild(int index, BaseTreeItem *child) + { + child->setParent(this); + mChildren.insert(index, child); + } + + BaseTreeItem* BaseTreeItem::removeChildAtPos(int row) + { + if(row < 0 || row >= mChildren.size()) + return nullptr; + else + { + BaseTreeItem* itemToRemove = mChildren.at(row); + mChildren.removeAt(row); + return itemToRemove; + } + } + + bool BaseTreeItem::removeChild(BaseTreeItem *child) + { + int index = mChildren.indexOf(child); + if(index == -1) + return false; + else + { + mChildren.removeAt(index); + return true; + } + } + + int BaseTreeItem::getChildCount() const + { + return mChildren.size(); + } + + int BaseTreeItem::getRowForChild(BaseTreeItem *child) const + { + int index = -1; + for(int i = 0; i < mChildren.size(); i++) + { + if(mChildren.at(i) == child) + { + index = i; + break; + } + } + return index; + } + + int BaseTreeItem::getOwnRow() + { + if(!mParent) + return -1; + + return mParent->getRowForChild(this); + } + + void BaseTreeItem::setAdditionalData(QString key, QVariant data) + { + mAdditionalData.insert(key, data); + } + + QVariant BaseTreeItem::getAdditionalData(QString key) const + { + return mAdditionalData.value(key, QVariant()); + } + + QVariant RootTreeItem::getData(int column) const + { + if (column <= mHeaderLabels.size()) + return mHeaderLabels.at(column); + return QVariant(); + } + + void RootTreeItem::setData(QList data) + { + mHeaderLabels.clear(); + for (int i = 0; i < data.length(); i++) { + mHeaderLabels[i] = data[i].toString(); + } + } + + void RootTreeItem::setDataAtIndex(int index, QVariant &data) + { + while (index >= mHeaderLabels.size()) + mHeaderLabels << QString(); + mHeaderLabels[index] = data.toString(); + } + +} diff --git a/plugins/gui/src/basic_tree_model/base_tree_model.cpp b/plugins/gui/src/basic_tree_model/base_tree_model.cpp index a7610902892..60f5ddb83cf 100644 --- a/plugins/gui/src/basic_tree_model/base_tree_model.cpp +++ b/plugins/gui/src/basic_tree_model/base_tree_model.cpp @@ -1,12 +1,12 @@ #include "gui/basic_tree_model/base_tree_model.h" -#include "gui/basic_tree_model/tree_item.h" +#include "gui/basic_tree_model/base_tree_item.h" namespace hal { BaseTreeModel::BaseTreeModel(QObject *parent) : QAbstractItemModel(parent) { - mRootItem = new TreeItem(); + mRootItem = new RootTreeItem(QStringList()); } QVariant BaseTreeModel::data(const QModelIndex &index, int role) const @@ -14,7 +14,7 @@ namespace hal if(!index.isValid()) return QVariant(); - TreeItem* item = getItemFromIndex(index); + BaseTreeItem* item = getItemFromIndex(index); if(!item) return QVariant(); @@ -38,8 +38,8 @@ namespace hal if(!hasIndex(row, column, parent)) return QModelIndex(); - TreeItem* parentItem = parent.isValid() ? getItemFromIndex(parent) : mRootItem; - TreeItem* childItem = parentItem->getChild(row); + BaseTreeItem* parentItem = parent.isValid() ? getItemFromIndex(parent) : mRootItem; + BaseTreeItem* childItem = parentItem->getChild(row); return (childItem) ? createIndex(row, column, childItem) : QModelIndex(); } @@ -48,11 +48,11 @@ namespace hal if(!index.isValid()) return QModelIndex(); - TreeItem* currentItem = getItemFromIndex(index); + BaseTreeItem* currentItem = getItemFromIndex(index); if(!currentItem) return QModelIndex(); - TreeItem* parentItem = currentItem->getParent(); + BaseTreeItem* parentItem = currentItem->getParent(); if(parentItem == mRootItem) return QModelIndex(); @@ -80,7 +80,7 @@ namespace hal return mRootItem->getColumnCount(); } - void BaseTreeModel::setContent(QList firstLevelItems) + void BaseTreeModel::setContent(QList firstLevelItems) { for(auto item : firstLevelItems) mRootItem->appendChild(item); @@ -92,25 +92,30 @@ namespace hal //delete all children, not the root item while(mRootItem->getChildCount() > 0) { - TreeItem* tmp = mRootItem->removeChildAtPos(0); + BaseTreeItem* tmp = mRootItem->removeChildAtPos(0); delete tmp; } endResetModel(); } - void BaseTreeModel::setHeaderLabels(QList labels) + void BaseTreeModel::setHeaderLabels(const QStringList& labels) { if(!mRootItem) - mRootItem = new TreeItem(); + mRootItem = new RootTreeItem(labels); + else + for (int i=0; isetDataAtIndex(i, qv); + } + - mRootItem->setData(labels); } - QModelIndex BaseTreeModel::getIndexFromItem(TreeItem *item) const + QModelIndex BaseTreeModel::getIndexFromItem(BaseTreeItem *item) const { assert(item); - TreeItem* parentItem = item->getParent(); + BaseTreeItem* parentItem = item->getParent(); // if the given item has no parent, it is the root item if(!parentItem) @@ -124,12 +129,12 @@ namespace hal return QModelIndex(); } - TreeItem *BaseTreeModel::getItemFromIndex(QModelIndex index) const + BaseTreeItem *BaseTreeModel::getItemFromIndex(QModelIndex index) const { - return (index.isValid()) ? static_cast(index.internalPointer()) : nullptr; + return (index.isValid()) ? static_cast(index.internalPointer()) : nullptr; } - TreeItem *BaseTreeModel::getRootItem() const + BaseTreeItem *BaseTreeModel::getRootItem() const { return mRootItem; } diff --git a/plugins/gui/src/basic_tree_model/tree_item.cpp b/plugins/gui/src/basic_tree_model/tree_item.cpp deleted file mode 100644 index e875a3a64b2..00000000000 --- a/plugins/gui/src/basic_tree_model/tree_item.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include "gui/basic_tree_model/tree_item.h" - - -namespace hal -{ - TreeItem::TreeItem() : mParent(nullptr) - { - - } - - TreeItem::TreeItem(QList columnData) : mParent(nullptr), mData(columnData) - { - - } - - TreeItem::TreeItem(const TreeItem &item) - { - mData = item.mData; - mAdditionalData = item.mAdditionalData; - } - - TreeItem::~TreeItem() - { - for(TreeItem* item : mChildren) - delete item; - } - - QVariant TreeItem::getData(int column) - { - return (column < 0 || column >= mData.size()) ? QVariant() : mData.at(column); - } - - void TreeItem::setData(QList data) - { - mData = data; - } - - void TreeItem::setDataAtIndex(int index, QVariant data) - { - if(!(index < 0 || index >= mData.size()) && !mData.empty()) - mData.replace(index, data); - } - - void TreeItem::appendData(QVariant data) - { - mData.append(data); - } - - TreeItem *TreeItem::getParent() - { - return mParent; - } - - void TreeItem::setParent(TreeItem *parent) - { - mParent = parent; - } - - TreeItem *TreeItem::getChild(int row) - { - return (row < 0 || row >= mChildren.size()) ? nullptr : mChildren.at(row); - } - - QList TreeItem::getChildren() - { - return mChildren; - } - - void TreeItem::appendChild(TreeItem *child) - { - child->setParent(this); - mChildren.append(child); - } - - void TreeItem::insertChild(int index, TreeItem *child) - { - child->setParent(this); - mChildren.insert(index, child); - } - - TreeItem* TreeItem::removeChildAtPos(int row) - { - if(row < 0 || row >= mChildren.size()) - return nullptr; - else - { - TreeItem* itemToRemove = mChildren.at(row); - mChildren.removeAt(row); - return itemToRemove; - } - } - - bool TreeItem::removeChild(TreeItem *child) - { - int index = mChildren.indexOf(child); - if(index == -1) - return false; - else - { - mChildren.removeAt(index); - return true; - } - } - - int TreeItem::getChildCount() - { - return mChildren.size(); - } - - int TreeItem::getColumnCount() - { - return mData.size(); - } - - int TreeItem::getRowForChild(TreeItem *child) - { - int index = -1; - for(int i = 0; i < mChildren.size(); i++) - { - if(mChildren.at(i) == child) - { - index = i; - break; - } - } - return index; - } - - int TreeItem::getOwnRow() - { - if(!mParent) - return -1; - - return mParent->getRowForChild(this); - } - - void TreeItem::setAdditionalData(QString key, QVariant data) - { - mAdditionalData.insert(key, data); - } - - QVariant TreeItem::getAdditionalData(QString key) - { - return mAdditionalData.value(key, QVariant()); - } - -} diff --git a/plugins/gui/src/selection_details_widget/gate_details_widget/gate_pin_tree.cpp b/plugins/gui/src/selection_details_widget/gate_details_widget/gate_pin_tree.cpp index ffce52f1003..f1ed3a05928 100644 --- a/plugins/gui/src/selection_details_widget/gate_details_widget/gate_pin_tree.cpp +++ b/plugins/gui/src/selection_details_widget/gate_details_widget/gate_pin_tree.cpp @@ -96,7 +96,7 @@ namespace hal if(!idx.isValid()) return; - TreeItem* clickedItem = mPinModel->getItemFromIndex(idx); + BaseTreeItem* clickedItem = mPinModel->getItemFromIndex(idx); QMenu menu; GatePinsTreeModel::itemType type = mPinModel->getTypeOfItem(clickedItem); bool isMiscSectionSet = false;//so that the misc-section is not set multiple times @@ -201,7 +201,7 @@ namespace hal } - void GatePinTree::buildPythonMenuForPin(QMenu &menu, TreeItem *clickedPinItem) + void GatePinTree::buildPythonMenuForPin(QMenu &menu, BaseTreeItem *clickedPinItem) { // 1.) NET-OBJECT QList netIdsOfItem = mPinModel->getNetIDsOfTreeItem(clickedPinItem); @@ -243,7 +243,7 @@ namespace hal } - void GatePinTree::buildPythonMenuForPinGroup(QMenu &menu, TreeItem *clickedPinIGrouptem) + void GatePinTree::buildPythonMenuForPinGroup(QMenu &menu, BaseTreeItem *clickedPinIGrouptem) { // 1. PYTHON LIST OF PIN GROUPS QString pythonList = "["; @@ -259,7 +259,7 @@ namespace hal }); //2. DIRECTION and TYPE(determined by the pin(s) within the group) - TreeItem* firstPinItemOfGroup = clickedPinIGrouptem->getChild(0); + BaseTreeItem* firstPinItemOfGroup = clickedPinIGrouptem->getChild(0); if(firstPinItemOfGroup) { QString pythonCommandGroupDirection = PyCodeProvider::pyCodeGateTypePinDirection(mPinModel->getCurrentGateID(), diff --git a/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp b/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp index 25ae97821af..03990971b64 100644 --- a/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp @@ -45,7 +45,7 @@ namespace hal GateType* gateType = g->get_type(); for (auto pin : gateType->get_pins()) { - TreeItem* pinItem = new TreeItem(); + BaseTreeItem* pinItem = new BaseTreeItem(); //get all infos for that pin const std::string& grouping = pin->get_group().first->get_name(); PinDirection direction = pin->get_direction(); @@ -96,11 +96,11 @@ namespace hal pinItem->setAdditionalData(keyRepresentedNetsID, QVariant::fromValue(netIDs)); if (!grouping.empty()) { - TreeItem* groupingsItem = mPinGroupingToTreeItem.value(grouping, nullptr); //since its a map, its okay + BaseTreeItem* groupingsItem = mPinGroupingToTreeItem.value(grouping, nullptr); //since its a map, its okay if (!groupingsItem) { //assume all items in the same grouping habe the same direction and type, so the grouping-item has also these types - groupingsItem = new TreeItem(QList() << QString::fromStdString(grouping) << pinDirection << pinType << ""); + groupingsItem = new BaseTreeItem(QList() << QString::fromStdString(grouping) << pinDirection << pinType << ""); groupingsItem->setAdditionalData(keyType, QVariant::fromValue(itemType::grouping)); mRootItem->appendChild(groupingsItem); mPinGroupingToTreeItem.insert(grouping, groupingsItem); @@ -118,12 +118,12 @@ namespace hal return mGateId; } - QList GatePinsTreeModel::getNetIDsOfTreeItem(TreeItem* item) + QList GatePinsTreeModel::getNetIDsOfTreeItem(BaseTreeItem* item) { return item->getAdditionalData(keyRepresentedNetsID).value>(); } - GatePinsTreeModel::itemType GatePinsTreeModel::getTypeOfItem(TreeItem* item) + GatePinsTreeModel::itemType GatePinsTreeModel::getTypeOfItem(BaseTreeItem* item) { return item->getAdditionalData(keyType).value(); } diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/module_elements_tree.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/module_elements_tree.cpp index dc38c9eb7d2..208a6c1d362 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/module_elements_tree.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/module_elements_tree.cpp @@ -61,7 +61,7 @@ namespace hal if(!clickedIndex.isValid()) return; - TreeItem* clickedItem = mModel->getItemFromIndex(clickedIndex); + BaseTreeItem* clickedItem = mModel->getItemFromIndex(clickedIndex); int id = clickedItem->getData(ModuleTreeModel::sIdColumn).toInt(); ModuleTreeModel::itemType type = mModel->getTypeOfItem(clickedItem); QMenu menu; diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp index 9d1b73c0400..b23592b3940 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp @@ -87,13 +87,13 @@ namespace hal return; //all relevant information - TreeItem* clickedItem = mPortModel->getItemFromIndex(clickedIndex); + BaseTreeItem* clickedItem = mPortModel->getItemFromIndex(clickedIndex); ModulePinsTreeModel::itemType type = mPortModel->getTypeOfItem(clickedItem); Net* n = mPortModel->getNetFromItem(clickedItem); QString name = clickedItem->getData(ModulePinsTreeModel::sNameColumn).toString(); u32 modId = mPortModel->getRepresentedModuleId(); auto mod = gNetlist->get_module_by_id(modId); - QList selectedPins; + QList selectedPins; std::pair sameGroup; bool onlyPins; std::tie(selectedPins, sameGroup, onlyPins) = getSelectedPins(); @@ -266,7 +266,7 @@ namespace hal void ModulePinsTree::appendMultiSelectionEntries(QMenu& menu, int modId) { - QList selectedPins; + QList selectedPins; std::pair sameGroup; bool onlyPins; std::tie(selectedPins, sameGroup, onlyPins) = getSelectedPins(); @@ -299,16 +299,16 @@ namespace hal } } - std::tuple, std::pair, bool> ModulePinsTree::getSelectedPins() + std::tuple, std::pair, bool> ModulePinsTree::getSelectedPins() { - QList selectedPins; //ordered - QSet alreadyProcessedPins; //only for performance purposes + QList selectedPins; //ordered + QSet alreadyProcessedPins; //only for performance purposes bool sameGroup = true; bool onlyPins = true; int groupId = -1; for (auto index : selectionModel()->selectedRows()) { - TreeItem* item = mPortModel->getItemFromIndex(index); + BaseTreeItem* item = mPortModel->getItemFromIndex(index); auto itemType = mPortModel->getTypeOfItem(item); if (itemType == ModulePinsTreeModel::itemType::pin) { diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp index 90b38a79a58..86762bcec22 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp @@ -1,6 +1,6 @@ #include "gui/selection_details_widget/module_details_widget/module_tree_model.h" #include "gui/selection_details_widget/selection_details_icon_provider.h" -#include "gui/basic_tree_model/tree_item.h" +#include "gui/basic_tree_model/base_tree_item.h" #include "hal_core/netlist/module.h" #include "hal_core/netlist/gate.h" #include "gui/gui_globals.h" @@ -33,7 +33,7 @@ namespace hal //delete all children, not the root item (manually for performance reasons) while(mRootItem->getChildCount() > 0) { - TreeItem* tmp = mRootItem->removeChildAtPos(0); + BaseTreeItem* tmp = mRootItem->removeChildAtPos(0); delete tmp; } @@ -41,7 +41,7 @@ namespace hal //add modules for(auto mod : m->get_submodules()) { - TreeItem* modItem = new TreeItem(QList() << QString::fromStdString(mod->get_name()) + BaseTreeItem* modItem = new BaseTreeItem(QList() << QString::fromStdString(mod->get_name()) << mod->get_id() << QString::fromStdString(mod->get_type())); moduleRecursive(mod, modItem); modItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::module)); @@ -52,7 +52,7 @@ namespace hal //add gates for(auto gate : m->get_gates()) { - TreeItem* gateItem = new TreeItem(QList() << QString::fromStdString(gate->get_name()) + BaseTreeItem* gateItem = new BaseTreeItem(QList() << QString::fromStdString(gate->get_name()) << gate->get_id() << QString::fromStdString(gate->get_type()->get_name())); gateItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::gate)); gateItem->setAdditionalData(mKeyRepId, gate->get_id()); @@ -78,7 +78,7 @@ namespace hal if(!index.isValid()) return QVariant(); - TreeItem* item = getItemFromIndex(index); + BaseTreeItem* item = getItemFromIndex(index); if(!item) return QVariant(); @@ -90,17 +90,17 @@ namespace hal } - ModuleTreeModel::itemType ModuleTreeModel::getTypeOfItem(TreeItem *item) const + ModuleTreeModel::itemType ModuleTreeModel::getTypeOfItem(BaseTreeItem *item) const { return item->getAdditionalData(mKeyItemType).value(); } - void ModuleTreeModel::moduleRecursive(Module *mod, TreeItem *modItem) + void ModuleTreeModel::moduleRecursive(Module *mod, BaseTreeItem *modItem) { - TreeItem* subModItem = nullptr; + BaseTreeItem* subModItem = nullptr; for(Module* subMod : mod->get_submodules()) { - subModItem = new TreeItem(QList() << QString::fromStdString(subMod->get_name()) + subModItem = new BaseTreeItem(QList() << QString::fromStdString(subMod->get_name()) << subMod->get_id() << QString::fromStdString(subMod->get_type())); moduleRecursive(subMod, subModItem); subModItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::module)); @@ -110,7 +110,7 @@ namespace hal } for(auto gate : mod->get_gates()) { - TreeItem* gateItem = new TreeItem(QList() << QString::fromStdString(gate->get_name()) + BaseTreeItem* gateItem = new BaseTreeItem(QList() << QString::fromStdString(gate->get_name()) << gate->get_id() << QString::fromStdString(gate->get_type()->get_name())); gateItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::gate)); gateItem->setAdditionalData(mKeyRepId, gate->get_id()); @@ -153,7 +153,7 @@ namespace hal beginResetModel(); for(auto gate : mod->get_gates()) { - TreeItem* gateItem = new TreeItem(QList() << QString::fromStdString(gate->get_name()) + BaseTreeItem* gateItem = new BaseTreeItem(QList() << QString::fromStdString(gate->get_name()) << gate->get_id() << QString::fromStdString(gate->get_type()->get_name())); gateItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::gate)); gateItem->setAdditionalData(mKeyRepId, gate->get_id()); @@ -164,7 +164,7 @@ namespace hal endResetModel(); } - QIcon ModuleTreeModel::getIconFromItem(TreeItem *item) const + QIcon ModuleTreeModel::getIconFromItem(BaseTreeItem *item) const { if(!item) return QIcon(); @@ -238,7 +238,7 @@ namespace hal { beginResetModel(); auto addedMod = gNetlist->get_module_by_id(added_module); - TreeItem* addedSubmodItem = new TreeItem(QList() << QString::fromStdString(addedMod->get_name()) << addedMod->get_id() + BaseTreeItem* addedSubmodItem = new BaseTreeItem(QList() << QString::fromStdString(addedMod->get_name()) << addedMod->get_id() << QString::fromStdString(addedMod->get_type())); moduleRecursive(addedMod, addedSubmodItem); addedSubmodItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::module)); @@ -258,11 +258,11 @@ namespace hal return; //1. Remove all items from maps through BFS (maybe own function?) - QQueue treeItemsQueue; + QQueue treeItemsQueue; treeItemsQueue.enqueue(removedModItem); while(!treeItemsQueue.isEmpty()) { - TreeItem* current = treeItemsQueue.dequeue(); + BaseTreeItem* current = treeItemsQueue.dequeue(); switch (getTypeOfItem(current)) { case itemType::module: mModuleToTreeitems.remove(gNetlist->get_module_by_id(current->getData(ModuleTreeModel::sIdColumn).toInt())); break; @@ -283,7 +283,7 @@ namespace hal void ModuleTreeModel::handleModuleGateAssigned(Module *m, u32 assigned_gate) { - TreeItem* modItem = mModuleToTreeitems.value(m, nullptr); + BaseTreeItem* modItem = mModuleToTreeitems.value(m, nullptr); if((int)m->get_id() == mModId) modItem = mRootItem; @@ -296,7 +296,7 @@ namespace hal if(getTypeOfItem(modItem->getChild(indexToInsert)) != itemType::module) break; - TreeItem* gateItem = new TreeItem(QList() << QString::fromStdString(assignedGate->get_name()) + BaseTreeItem* gateItem = new BaseTreeItem(QList() << QString::fromStdString(assignedGate->get_name()) << assignedGate->get_id() << QString::fromStdString(assignedGate->get_type()->get_name())); gateItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::gate)); mGateToTreeitems.insert(assignedGate, gateItem); diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp index b66f040dd03..107155d218b 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp @@ -1,6 +1,6 @@ #include "gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h" #include "gui/selection_details_widget/selection_details_icon_provider.h" -#include "gui/basic_tree_model/tree_item.h" +#include "gui/basic_tree_model/base_tree_item.h" #include "hal_core/netlist/module.h" #include "hal_core/netlist/gate.h" #include "gui/gui_globals.h" @@ -9,12 +9,67 @@ namespace hal { + + NetlistElementsTreeitem::NetlistElementsTreeitem(const QString &name, int id, QString tp) + : mType(tp), mId(id), mName(name) + {;} + + QVariant NetlistElementsTreeitem::getData(int index) const + { + switch (index) + { + case 0: { + QVariant qvName = QVariant(mName); + return qvName; + break;} + case 1: { + QVariant qvId = QVariant(mId); + return qvId; + break;} + case 2: { + QVariant qvType = QVariant(mTypee); + return qvType; + break;} + } + } + + void NetlistElementsTreeitem::setData(QList data) + { + mName = data[0].toString(); + mId = data[1].toInt(); + mType = data[2].toString(); + + } + + void NetlistElementsTreeitem::setDataAtIndex(int index, QVariant &data) + { + const char* ctyp[] = { "Module", "Gate", "Net"}; + + switch (index) + { + case 0: mName = data.toString(); break; + case 1: mId = data.toInt(); break; + case 2: + for (int j=0; j<3; j++) + if (data.toString() == ctyp[j]) + { + mType = data.toString(); + break; + } + } + } + + int NetlistElementsTreeitem::getColumnCount() const + { + return 3; + } + NetlistElementsTreeModel::NetlistElementsTreeModel(QObject *parent) : BaseTreeModel(parent), mGatesDisplayed(true), mNetsDisplayed(true), mDisplaySubmodRecursive(true), mCurrentlyDisplayingModule(false), mModId(-1) { // use root item to store header information - setHeaderLabels(QList() << "Name" << "ID" << "Type"); + setHeaderLabels(QStringList() << "Name" << "ID" << "Type"); // CONNECTIONS connect(gNetlistRelay, &NetlistRelay::gateNameChanged, this, &NetlistElementsTreeModel::gateNameChanged); @@ -38,12 +93,14 @@ namespace hal if(!index.isValid()) return QVariant(); - TreeItem* item = getItemFromIndex(index); + BaseTreeItem* item = getItemFromIndex(index); if(!item) return QVariant(); - if(role == Qt::DecorationRole && index.column() == 0) - return getIconFromItem(getItemFromIndex(index)); + if(role == Qt::DecorationRole && index.column() == 0) { + NetlistElementsTreeitem* neti = static_cast(getItemFromIndex(index)); + return getIconFromItem(neti); + } //yes, it performs the same two checks again, should be okay though (in terms of performance) return BaseTreeModel::data(index, role); @@ -83,8 +140,8 @@ namespace hal Module* mod = gNetlist->get_module_by_id(id); if(!mod) continue; - TreeItem* modItem = new TreeItem(QList() << QString::fromStdString(mod->get_name()) - << mod->get_id() << QString::fromStdString(mod->get_type())); + NetlistElementsTreeitem* modItem = new NetlistElementsTreeitem(QString::fromStdString(mod->get_name()), + mod->get_id(), QString::fromStdString(mod->get_type())); if(displayModulesRecursive) moduleRecursive(mod, modItem, showGatesInSubmods, showNetsInSubmods); modItem->setAdditionalData(keyItemType, QVariant::fromValue(itemType::module)); @@ -96,8 +153,8 @@ namespace hal for(int id : gateIds) { Gate* gate = gNetlist->get_gate_by_id(id); - TreeItem* gateItem = new TreeItem(QList() << QString::fromStdString(gate->get_name()) - << gate->get_id() << QString::fromStdString(gate->get_type()->get_name())); + NetlistElementsTreeitem* gateItem = new NetlistElementsTreeitem(QString::fromStdString(gate->get_name()), + gate->get_id(), QString::fromStdString(gate->get_type()->get_name())); gateItem->setAdditionalData(keyItemType, QVariant::fromValue(itemType::gate)); gateItem->setAdditionalData(keyRepresentedID, gate->get_id()); mRootItem->appendChild(gateItem); @@ -106,8 +163,8 @@ namespace hal for(int id : netIds) { Net* net = gNetlist->get_net_by_id(id); - TreeItem* netItem = new TreeItem(QList() << QString::fromStdString(net->get_name()) - << net->get_id() << ""); + NetlistElementsTreeitem* netItem = new NetlistElementsTreeitem(QString::fromStdString(net->get_name()), + net->get_id(), ""); netItem->setAdditionalData(keyItemType, QVariant::fromValue(itemType::net)); netItem->setAdditionalData(keyRepresentedID, net->get_id()); mRootItem->appendChild(netItem); @@ -137,21 +194,22 @@ namespace hal Q_EMIT numberOfSubmodulesChanged(mod->get_submodules().size()); } - NetlistElementsTreeModel::itemType NetlistElementsTreeModel::getTypeOfItem(TreeItem *item) const + NetlistElementsTreeModel::itemType NetlistElementsTreeModel::getTypeOfItem(NetlistElementsTreeitem *item) const { return item->getAdditionalData(keyItemType).value(); } - int NetlistElementsTreeModel::getRepresentedIdOfItem(TreeItem *item) const + int NetlistElementsTreeModel::getRepresentedIdOfItem(NetlistElementsTreeitem *item) const { return item->getAdditionalData(keyRepresentedID).toInt(); } void NetlistElementsTreeModel::gateNameChanged(Gate *g) { - for(TreeItem* gateItem : mGateToTreeitems.values(g)) + for(BaseTreeItem* gateItem : mGateToTreeitems.values(g)) { - gateItem->setDataAtIndex(sNameColumn, QString::fromStdString(g->get_name())); + QVariant data = QVariant(QString::fromStdString(g->get_name())); + gateItem->setDataAtIndex(sNameColumn, data); QModelIndex inx0 = getIndexFromItem(gateItem); QModelIndex inx1 = createIndex(inx0.row(), sNameColumn, inx0.internalPointer()); Q_EMIT dataChanged(inx0, inx1); @@ -160,8 +218,8 @@ namespace hal void NetlistElementsTreeModel::gateRemoved(Gate *g) { - QList items = mGateToTreeitems.values(g); - for(TreeItem* gateItem : items) + QList items = mGateToTreeitems.values(g); + for(NetlistElementsTreeitem* gateItem : items) { beginRemoveRows(parent(getIndexFromItem(gateItem)), gateItem->getOwnRow(), gateItem->getOwnRow()); gateItem->getParent()->removeChild(gateItem); @@ -170,7 +228,8 @@ namespace hal if(mNetsDisplayed && ( (gateItem->getParent() == mRootItem && mCurrentlyDisplayingModule) || gateItem->getParent() != mRootItem)) { beginResetModel(); - updateInternalNetsOfModule(gateItem->getParent());//perhaps for all parents? go until the mRootItem node? + NetlistElementsTreeitem* neti = static_cast(gateItem->getParent()); + updateInternalNetsOfModule(neti);//perhaps for all parents? go until the mRootItem node? endResetModel(); } delete gateItem; @@ -179,9 +238,10 @@ namespace hal void NetlistElementsTreeModel::netNameChanged(Net *n) { - for(TreeItem* netItem : mNetToTreeitems.values(n)) + for(NetlistElementsTreeitem* netItem : mNetToTreeitems.values(n)) { - netItem->setDataAtIndex(sNameColumn, QString::fromStdString(n->get_name())); + QVariant data = QVariant(QString::fromStdString(n->get_name())); + netItem->setDataAtIndex(sNameColumn, data); QModelIndex inx0 = getIndexFromItem(netItem); QModelIndex inx1 = createIndex(inx0.row(), sNameColumn, inx0.internalPointer()); Q_EMIT dataChanged(inx0, inx1); @@ -190,8 +250,8 @@ namespace hal void NetlistElementsTreeModel::netRemoved(Net *n) { - QList items = mNetToTreeitems.values(n); - for(TreeItem* netItem : items) + QList items = mNetToTreeitems.values(n); + for(NetlistElementsTreeitem* netItem : items) { beginRemoveRows(parent(getIndexFromItem(netItem)), netItem->getOwnRow(), netItem->getOwnRow()); netItem->getParent()->removeChild(netItem); @@ -203,9 +263,10 @@ namespace hal void NetlistElementsTreeModel::moduleNameChanged(Module *m) { - for(TreeItem* modItem : mModuleToTreeitems.values(m)) + for(NetlistElementsTreeitem* modItem : mModuleToTreeitems.values(m)) { - modItem->setDataAtIndex(sNameColumn, QString::fromStdString(m->get_name())); + QVariant data = QVariant(QString::fromStdString(m->get_name())); + modItem->setDataAtIndex(sNameColumn, data); QModelIndex inx0 = getIndexFromItem(modItem); Q_EMIT dataChanged(inx0, createIndex(inx0.row(), sNameColumn, inx0.internalPointer())); } @@ -213,9 +274,10 @@ namespace hal void NetlistElementsTreeModel::moduleTypeChanged(Module *m) { - for(TreeItem* modItem : mModuleToTreeitems.values(m)) + for(NetlistElementsTreeitem* modItem : mModuleToTreeitems.values(m)) { - modItem->setDataAtIndex(sTypeColumn, QString::fromStdString(m->get_type())); + QVariant data = QVariant(QString::fromStdString(m->get_type())); + modItem->setDataAtIndex(sTypeColumn, data); QModelIndex inx0 = getIndexFromItem(modItem); Q_EMIT dataChanged(inx0, createIndex(inx0.row(), sTypeColumn, inx0.internalPointer())); } @@ -226,15 +288,15 @@ namespace hal //1. go through the actual TreeItems through a BFS and remove them from the maps //2. delete the associated module tree items (beginResetModel) Module* removedMod = gNetlist->get_module_by_id(removed_module); - QList tmpSubmodItems; // they already get removed in the BFS - for(TreeItem* removedSubmodItem : mModuleToTreeitems.values(removedMod)) + QList tmpSubmodItems; // they already get removed in the BFS + for(NetlistElementsTreeitem* removedSubmodItem : mModuleToTreeitems.values(removedMod)) { tmpSubmodItems.append(removedSubmodItem); - QQueue treeItemsQueue; + QQueue treeItemsQueue; treeItemsQueue.enqueue(removedSubmodItem); while(!treeItemsQueue.isEmpty()) { - TreeItem* currentItem = treeItemsQueue.dequeue(); + NetlistElementsTreeitem* currentItem = treeItemsQueue.dequeue(); int id = currentItem->getAdditionalData(keyRepresentedID).toUInt(); switch (getTypeOfItem(currentItem)) @@ -244,17 +306,21 @@ namespace hal case itemType::net: mNetToTreeitems.remove(gNetlist->get_net_by_id(id), currentItem); break; } - for(TreeItem* child : currentItem->getChildren()) - treeItemsQueue.enqueue(child); + for(BaseTreeItem* child : currentItem->getChildren()){ + NetlistElementsTreeitem* neti = static_cast(child); + treeItemsQueue.enqueue(neti); + } } } //after clearing the maps, delete the corresponding module items (propagates through all children) beginResetModel(); - for(TreeItem* removedSubItem : tmpSubmodItems) + for(NetlistElementsTreeitem* removedSubItem : tmpSubmodItems) { removedSubItem->getParent()->removeChild(removedSubItem); - if(mNetsDisplayed) - updateInternalNetsOfModule(removedSubItem->getParent()); + if(mNetsDisplayed) { + NetlistElementsTreeitem* neti = static_cast(removedSubItem->getParent()); + updateInternalNetsOfModule(neti); + } delete removedSubItem; } endResetModel(); @@ -274,14 +340,16 @@ namespace hal Gate* assignedGate = gNetlist->get_gate_by_id(assigned_gate); //helper lambda function to parametrize the moduleItem parent (not worth own named class function) - auto appendNewGateToModule = [this, assignedGate](TreeItem* modItem){ + auto appendNewGateToModule = [this, assignedGate](BaseTreeItem* modItem){ int indexToInsert = 0; - for(; indexToInsert < modItem->getChildCount(); indexToInsert++) - if(getTypeOfItem(modItem->getChild(indexToInsert)) != itemType::module) + for(; indexToInsert < modItem->getChildCount(); indexToInsert++) { + NetlistElementsTreeitem* neti = static_cast(modItem->getChild(indexToInsert)); + if(getTypeOfItem(neti) != itemType::module) break; + } - TreeItem* gateItem = new TreeItem(QList() << QString::fromStdString(assignedGate->get_name()) - << assignedGate->get_id() << QString::fromStdString(assignedGate->get_type()->get_name())); + NetlistElementsTreeitem* gateItem = new NetlistElementsTreeitem(QString::fromStdString(assignedGate->get_name()), + assignedGate->get_id(), QString::fromStdString(assignedGate->get_type()->get_name())); gateItem->setAdditionalData(keyItemType, QVariant::fromValue(itemType::gate)); gateItem->setAdditionalData(keyRepresentedID, assignedGate->get_id()); //beginInsertRows(getIndexFromItem(modItem), indexToInsert, indexToInsert); @@ -289,8 +357,10 @@ namespace hal modItem->insertChild(indexToInsert, gateItem); //endInsertRows(); mGateToTreeitems.insert(assignedGate, gateItem); - if(mNetsDisplayed) - updateInternalNetsOfModule(modItem); + if(mNetsDisplayed) { + NetlistElementsTreeitem* neti = static_cast(modItem); + updateInternalNetsOfModule(neti); + } endResetModel(); }; @@ -299,7 +369,7 @@ namespace hal appendNewGateToModule(mRootItem); //standard case in which you do the same as obove, but just go through each module item - for(TreeItem* modItem : mModuleToTreeitems.values(m)) + for(BaseTreeItem* modItem : mModuleToTreeitems.values(m)) appendNewGateToModule(modItem); } @@ -317,16 +387,18 @@ namespace hal beginResetModel(); Module* addedModule = gNetlist->get_module_by_id(added_module); - auto appendNewSubmodItem = [this, addedModule](TreeItem* parentModItem){ - TreeItem* addedSubmodItem = new TreeItem(QList() << QString::fromStdString(addedModule->get_name()) << addedModule->get_id() - << QString::fromStdString(addedModule->get_type())); + auto appendNewSubmodItem = [this, addedModule](BaseTreeItem* parentModItem){ + NetlistElementsTreeitem* addedSubmodItem = new NetlistElementsTreeitem(QString::fromStdString(addedModule->get_name()), + addedModule->get_id(), QString::fromStdString(addedModule->get_type())); moduleRecursive(addedModule, addedSubmodItem, mGatesDisplayed, mNetsDisplayed); addedSubmodItem->setAdditionalData(keyItemType, QVariant::fromValue(itemType::module)); addedSubmodItem->setAdditionalData(keyRepresentedID, addedModule->get_id()); parentModItem->insertChild(0, addedSubmodItem); mModuleToTreeitems.insert(addedModule, addedSubmodItem); - if(mNetsDisplayed) - updateInternalNetsOfModule(parentModItem); + if(mNetsDisplayed) { + NetlistElementsTreeitem* neti = static_cast(parentModItem); + updateInternalNetsOfModule(neti); + } }; //special case when a module is represented with setModule @@ -337,19 +409,19 @@ namespace hal } //standard case for all displayed things - for(TreeItem* parentModItem : mModuleToTreeitems.values(m)) + for(NetlistElementsTreeitem* parentModItem : mModuleToTreeitems.values(m)) appendNewSubmodItem(parentModItem); endResetModel(); } - void NetlistElementsTreeModel::moduleRecursive(Module* mod, TreeItem* modItem, bool showGates, bool showNets) + void NetlistElementsTreeModel::moduleRecursive(Module* mod, NetlistElementsTreeitem* modItem, bool showGates, bool showNets) { - TreeItem* subModItem = nullptr; + NetlistElementsTreeitem* subModItem = nullptr; for(Module* subMod : mod->get_submodules()) { - subModItem = new TreeItem(QList() << QString::fromStdString(subMod->get_name()) - << subMod->get_id() << QString::fromStdString(subMod->get_type())); + subModItem = new NetlistElementsTreeitem(QString::fromStdString(subMod->get_name()), + subMod->get_id(), QString::fromStdString(subMod->get_type())); moduleRecursive(subMod, subModItem, showGates); subModItem->setAdditionalData(keyItemType, QVariant::fromValue(itemType::module)); subModItem->setAdditionalData(keyRepresentedID, subMod->get_id()); @@ -360,8 +432,8 @@ namespace hal { for(auto gate : mod->get_gates()) { - TreeItem* gateItem = new TreeItem(QList() << QString::fromStdString(gate->get_name()) - << gate->get_id() << QString::fromStdString(gate->get_type()->get_name())); + NetlistElementsTreeitem* gateItem = new NetlistElementsTreeitem(QString::fromStdString(gate->get_name()), + gate->get_id(), QString::fromStdString(gate->get_type()->get_name())); gateItem->setAdditionalData(keyItemType, QVariant::fromValue(itemType::gate)); gateItem->setAdditionalData(keyRepresentedID, gate->get_id()); modItem->appendChild(gateItem); @@ -372,8 +444,8 @@ namespace hal { for(auto net : mod->get_internal_nets()) { - TreeItem* netItem = new TreeItem(QList() << QString::fromStdString(net->get_name()) - << net->get_id() << ""); + NetlistElementsTreeitem* netItem = new NetlistElementsTreeitem(QString::fromStdString(net->get_name()), + net->get_id(), ""); netItem->setAdditionalData(keyItemType, QVariant::fromValue(itemType::net)); netItem->setAdditionalData(keyRepresentedID, net->get_id()); modItem->appendChild(netItem); @@ -382,7 +454,7 @@ namespace hal } } - QIcon NetlistElementsTreeModel::getIconFromItem(TreeItem *item) const + QIcon NetlistElementsTreeModel::getIconFromItem(NetlistElementsTreeitem *item) const { if(!item) return QIcon(); @@ -399,21 +471,21 @@ namespace hal } } - void NetlistElementsTreeModel::updateInternalNetsOfModule(TreeItem *moduleItem) + void NetlistElementsTreeModel::updateInternalNetsOfModule(NetlistElementsTreeitem *moduleItem) { int moduleId = (moduleItem == mRootItem) ? mModId : moduleItem->getAdditionalData(keyRepresentedID).toInt(); Module* mod = gNetlist->get_module_by_id(moduleId); //remove and delte the last child of the module-item until no net items are left - while(moduleItem->getChildCount() > 0 && getTypeOfItem(moduleItem->getChild(moduleItem->getChildCount()-1)) == itemType::net) + while(moduleItem->getChildCount() > 0 && getTypeOfItem(static_cast(moduleItem->getChild(moduleItem->getChildCount()-1))) == itemType::net) { - TreeItem* lastNetItem = moduleItem->removeChildAtPos(moduleItem->getChildCount()-1); + NetlistElementsTreeitem* lastNetItem = static_cast(moduleItem->removeChildAtPos(moduleItem->getChildCount()-1)); mNetToTreeitems.remove(gNetlist->get_net_by_id(lastNetItem->getAdditionalData(keyRepresentedID).toUInt()), lastNetItem); delete lastNetItem; } //append (potentionally) new internal nets for(Net* n : mod->get_internal_nets()) { - TreeItem* netItem = new TreeItem(QList() << QString::fromStdString(n->get_name()) << n->get_id() << ""); + NetlistElementsTreeitem* netItem = new NetlistElementsTreeitem(QString::fromStdString(n->get_name()),n->get_id(), ""); //netItem->setAdditionalData(keyItemType, itemType::net); netItem->setAdditionalData(keyItemType, QVariant::fromValue(itemType::net)); netItem->setAdditionalData(keyRepresentedID, n->get_id()); @@ -422,4 +494,5 @@ namespace hal } } + } diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp index 138ed0814e4..1453d6c0ef1 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp @@ -1,6 +1,6 @@ #include "gui/selection_details_widget/module_details_widget/port_tree_model.h" -#include "gui/basic_tree_model/tree_item.h" +#include "gui/basic_tree_model/base_tree_item.h" #include "gui/gui_globals.h" #include "gui/input_dialog/input_dialog.h" #include "gui/user_action/action_add_items_to_object.h" @@ -21,7 +21,7 @@ namespace hal { ModulePinsTreeModel::ModulePinsTreeModel(QObject* parent) : BaseTreeModel(parent), mIgnoreEventsFlag(false) { - setHeaderLabels(QList() << "Name" + setHeaderLabels(QStringList() << "Name" << "Direction" << "Type" << "Connected Net"); @@ -348,13 +348,13 @@ namespace hal auto pinGroupDirection = QString::fromStdString(enum_to_string((pinGroup->get_direction()))); auto pinGroupType = QString::fromStdString(enum_to_string(pinGroup->get_type())); - TreeItem* pinGroupItem = new TreeItem(QList() << pinGroupName << pinGroupDirection << pinGroupType << ""); + BaseTreeItem* pinGroupItem = new BaseTreeItem(QList() << pinGroupName << pinGroupDirection << pinGroupType << ""); pinGroupItem->setAdditionalData(keyType, QVariant::fromValue(itemType::group)); // port multi bit pinGroupItem->setAdditionalData(keyId, pinGroup->get_id()); mIdToGroupItem.insert(pinGroup->get_id(), pinGroupItem); for(ModulePin* pin : pinGroup->get_pins()) { - TreeItem* pinItem = new TreeItem(QList() << QString::fromStdString(pin->get_name()) + BaseTreeItem* pinItem = new BaseTreeItem(QList() << QString::fromStdString(pin->get_name()) << QString::fromStdString(enum_to_string(pin->get_direction())) << QString::fromStdString(enum_to_string(pin->get_type())) << QString::fromStdString(pin->get_net()->get_name())); @@ -422,7 +422,7 @@ namespace hal Q_EMIT numberOfPortsChanged(m->get_pins().size()); } - Net* ModulePinsTreeModel::getNetFromItem(TreeItem* item) + Net* ModulePinsTreeModel::getNetFromItem(BaseTreeItem* item) { if (mModuleId == -1) //no current module = no represented net return nullptr; @@ -449,12 +449,12 @@ namespace hal return mModuleId; } - ModulePinsTreeModel::itemType ModulePinsTreeModel::getTypeOfItem(TreeItem* item) const + ModulePinsTreeModel::itemType ModulePinsTreeModel::getTypeOfItem(BaseTreeItem* item) const { return item->getAdditionalData(keyType).value(); } - int ModulePinsTreeModel::getIdOfItem(TreeItem* item) const + int ModulePinsTreeModel::getIdOfItem(BaseTreeItem* item) const { return item->getAdditionalData(keyId).toInt(); } @@ -468,7 +468,7 @@ namespace hal } } - void ModulePinsTreeModel::dndGroupOnGroup(TreeItem *droppedGroup, TreeItem *onDroppedGroup) + void ModulePinsTreeModel::dndGroupOnGroup(BaseTreeItem *droppedGroup, BaseTreeItem *onDroppedGroup) { // SPECIFY: 1) create completely new group, all pins in that, delete old 2 groups // 2) just add all pins from dropped group to "ondroppedgroup", then rename? @@ -497,7 +497,7 @@ namespace hal } - void ModulePinsTreeModel::dndGroupBetweenGroup(TreeItem *droppedGroup, int row) + void ModulePinsTreeModel::dndGroupBetweenGroup(BaseTreeItem *droppedGroup, int row) { mIgnoreEventsFlag = true; int ownRow = droppedGroup->getOwnRow(); @@ -516,7 +516,7 @@ namespace hal mIgnoreEventsFlag = false; } - void ModulePinsTreeModel::dndPinOnGroup(TreeItem *droppedPin, TreeItem *onDroppedGroup) + void ModulePinsTreeModel::dndPinOnGroup(BaseTreeItem *droppedPin, BaseTreeItem *onDroppedGroup) { mIgnoreEventsFlag = true; QSet e; @@ -535,7 +535,7 @@ namespace hal mIgnoreEventsFlag = false; } - void ModulePinsTreeModel::dndPinBetweenPin(TreeItem *droppedPin, TreeItem *onDroppedParent, int row) + void ModulePinsTreeModel::dndPinBetweenPin(BaseTreeItem *droppedPin, BaseTreeItem *onDroppedParent, int row) { mIgnoreEventsFlag = true; int desiredIdx = row; @@ -579,7 +579,7 @@ namespace hal mIgnoreEventsFlag = false; } - void ModulePinsTreeModel::dndPinBetweenGroup(TreeItem *droppedPin, int row) + void ModulePinsTreeModel::dndPinBetweenGroup(BaseTreeItem *droppedPin, int row) { // row is needed for when groups can change its order within the module Q_UNUSED(row) @@ -599,7 +599,7 @@ namespace hal auto pinGroupDirection = QString::fromStdString(enum_to_string((newGroup->get_direction()))); auto pinGroupType = QString::fromStdString(enum_to_string(newGroup->get_type())); - TreeItem* pinGroupItem = new TreeItem(QList() << pinGroupName << pinGroupDirection << pinGroupType << ""); + BaseTreeItem* pinGroupItem = new BaseTreeItem(QList() << pinGroupName << pinGroupDirection << pinGroupType << ""); pinGroupItem->setAdditionalData(keyType, QVariant::fromValue(itemType::group)); pinGroupItem->setAdditionalData(keyId, newGroup->get_id()); @@ -617,7 +617,7 @@ namespace hal mIgnoreEventsFlag = false; } - void ModulePinsTreeModel::insertItem(TreeItem* item, TreeItem* parent, int index) + void ModulePinsTreeModel::insertItem(BaseTreeItem* item, BaseTreeItem* parent, int index) { // fun fact: if an item is inserted above an item that is expanded, the tree collapses all indeces beginInsertRows(getIndexFromItem(parent), index, index); @@ -627,7 +627,7 @@ namespace hal getTypeOfItem(item) == itemType::pin ? mIdToPinItem.insert(getIdOfItem(item), item) : mIdToGroupItem.insert(getIdOfItem(item), item); //mIdToPinItem.insert(getIdOfItem(item), item); } - void ModulePinsTreeModel::removeItem(TreeItem* item) + void ModulePinsTreeModel::removeItem(BaseTreeItem* item) { beginRemoveRows(parent(getIndexFromItem(item)), item->getOwnRow(), item->getOwnRow()); item->getParent()->removeChild(item); diff --git a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_item.cpp b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_item.cpp index 1fbdd78594e..989e9516d6f 100644 --- a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_item.cpp +++ b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_item.cpp @@ -1,5 +1,5 @@ #include "gui/gui_globals.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" +#include "gui/selection_details_widget/tree_navigation/selection_base_tree_item.h" #include "gui/selection_details_widget/selection_details_icon_provider.h" namespace hal diff --git a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_model.cpp b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_model.cpp index 9e61ffcfc85..89b0dc5c19c 100644 --- a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_model.cpp @@ -1,5 +1,5 @@ #include "gui/selection_details_widget/tree_navigation/selection_tree_model.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" +#include "gui/selection_details_widget/tree_navigation/selection_base_tree_item.h" #include "gui/gui_globals.h" #include "hal_core/netlist/gate.h" #include "hal_core/netlist/net.h" diff --git a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp index 3f98627c2bb..b902ccfb333 100644 --- a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp +++ b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp @@ -1,6 +1,6 @@ #include "gui/selection_details_widget/tree_navigation/selection_tree_proxy.h" #include "gui/selection_details_widget/tree_navigation/selection_tree_model.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" +#include "gui/selection_details_widget/tree_navigation/selection_base_tree_item.h" #include "gui/gui_globals.h" diff --git a/plugins/simulator/waveform_viewer/src/wave_widget.cpp b/plugins/simulator/waveform_viewer/src/wave_widget.cpp index 34564856e00..62ee1ce6a4b 100644 --- a/plugins/simulator/waveform_viewer/src/wave_widget.cpp +++ b/plugins/simulator/waveform_viewer/src/wave_widget.cpp @@ -26,7 +26,7 @@ #include "gui/grouping/grouping_manager_widget.h" #include "gui/grouping/grouping_table_model.h" #include "gui/selection_details_widget/selection_details_widget.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" +#include "gui/selection_details_widget/tree_navigation/selection_base_tree_item.h" #include "gui/gui_globals.h" namespace hal { From 146b5a4f9330e2fc7557c7c27a9bfbfe874512d9 Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 4 Jul 2023 11:59:42 +0200 Subject: [PATCH 02/36] WIP: Update models to use BaseTreeItem --- .../gui/basic_tree_model/base_tree_item.h | 8 +- .../gui/basic_tree_model/base_tree_model.h | 2 +- .../gate_details_widget/pin_tree_model.h | 19 ++++ .../module_details_widget/module_tree_model.h | 19 ++++ .../netlist_elements_tree_model.h | 4 +- .../module_details_widget/port_tree_model.h | 19 ++++ .../src/basic_tree_model/base_tree_item.cpp | 5 + .../gate_details_widget/pin_tree_model.cpp | 84 +++++++++++++- .../module_tree_model.cpp | 104 ++++++++++++++---- .../netlist_elements_tree_model.cpp | 13 ++- .../module_details_widget/port_tree_model.cpp | 86 +++++++++++++-- .../tree_navigation/selection_tree_item.cpp | 2 +- .../tree_navigation/selection_tree_model.cpp | 2 +- .../tree_navigation/selection_tree_proxy.cpp | 2 +- 14 files changed, 322 insertions(+), 47 deletions(-) diff --git a/plugins/gui/include/gui/basic_tree_model/base_tree_item.h b/plugins/gui/include/gui/basic_tree_model/base_tree_item.h index 7a7a657ab7d..68f5ea461a9 100644 --- a/plugins/gui/include/gui/basic_tree_model/base_tree_item.h +++ b/plugins/gui/include/gui/basic_tree_model/base_tree_item.h @@ -92,14 +92,14 @@ namespace hal * @param index - The column to set the new data. * @param data - The new column data. */ - virtual void setDataAtIndex(int index, QVariant& data); + virtual void setDataAtIndex(int index, QVariant& data) = 0; /** * Appends a new column to the item. * * @param data - The data of the new column. */ - virtual void appendData(QVariant data); + virtual void appendData(QVariant data) = 0; /** * Get the item's parent. @@ -254,14 +254,14 @@ namespace hal * @param index - The column to set the new data. * @param data - The new column data. */ - void setDataAtIndex(int index, QVariant& data); + void setDataAtIndex(int index, QVariant& data) override; /** * Appends a new column to the item. * * @param data - The data of the new column. */ - void appendData(QVariant data); + void appendData(QVariant data) override; /** * Get number of sections for which header label exist. diff --git a/plugins/gui/include/gui/basic_tree_model/base_tree_model.h b/plugins/gui/include/gui/basic_tree_model/base_tree_model.h index 860aa7abaaf..a654035c4e9 100644 --- a/plugins/gui/include/gui/basic_tree_model/base_tree_model.h +++ b/plugins/gui/include/gui/basic_tree_model/base_tree_model.h @@ -141,7 +141,7 @@ namespace hal BaseTreeItem* getRootItem() const; protected: - BaseTreeItem* mRootItem; + RootTreeItem* mRootItem; }; } diff --git a/plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h b/plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h index a9bb61b9836..142601fa32a 100644 --- a/plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h @@ -34,6 +34,25 @@ namespace hal class Gate; + class PinTreeItem : public BaseTreeItem + { + + private: + std::string mPinName; + QString mPinDirection; + QString mPinType; + QString mNetName; + public: + + PinTreeItem(const std::string& pinName, QString pinDirection, QString pinTypee, QString netName); + PinTreeItem(); + QVariant getData(int column) const override; + void setData(QList data) override; + void setDataAtIndex(int index, QVariant& data) override; + void appendData(QVariant data) override; + int getColumnCount() const override; + }; + /** * @ingroup gui * @brief A model to display the pins of a gate. diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h index 68df1446122..bf2c7d7ee29 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h @@ -27,6 +27,8 @@ #include "hal_core/defines.h" #include #include +#include + namespace hal { @@ -35,6 +37,23 @@ namespace hal class Net; class BaseTreeItem; + class ModuleTreeitem : public BaseTreeItem + { + + private: + std::string mType; + int mId; + std::string mName; + public: + + ModuleTreeitem(const std::string& name, int id, std::string tp); + QVariant getData(int column) const override; + void setData(QList data) override; + void setDataAtIndex(int index, QVariant& data) override; + void appendData(QVariant data) override; + int getColumnCount() const override; + }; + class ModuleTreeModel : public BaseTreeModel { Q_OBJECT diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h index 8c4403812d1..5bb90aa7240 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h @@ -39,8 +39,7 @@ namespace hal class NetlistElementsTreeitem : public BaseTreeItem { - public: - enum class Type {module = 0, gate = 1, net = 2}; + private: QString mType; int mId; @@ -51,6 +50,7 @@ namespace hal QVariant getData(int column) const override; void setData(QList data) override; void setDataAtIndex(int index, QVariant& data) override; + void appendData(QVariant data) override; int getColumnCount() const override; }; diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h index b350d58d7ab..b94d2a47d22 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h @@ -35,6 +35,25 @@ namespace hal class Net; + class PortTreeItem : public BaseTreeItem + { + + private: + QString mPinName; + QString mPinDirection; + QString mPinType; + QString mNetName; + public: + + PortTreeItem(QString pinName, QString pinDirection, QString pinTypee, QString netName); + PortTreeItem(); + QVariant getData(int column) const override; + void setData(QList data) override; + void setDataAtIndex(int index, QVariant& data) override; + void appendData(QVariant data) override; + int getColumnCount() const override; + }; + /** * @brief A model to represent the ports of a module. */ diff --git a/plugins/gui/src/basic_tree_model/base_tree_item.cpp b/plugins/gui/src/basic_tree_model/base_tree_item.cpp index 469f5e33d79..c0d0ce9e539 100644 --- a/plugins/gui/src/basic_tree_model/base_tree_item.cpp +++ b/plugins/gui/src/basic_tree_model/base_tree_item.cpp @@ -131,4 +131,9 @@ namespace hal mHeaderLabels[index] = data.toString(); } + void RootTreeItem::appendData(QVariant data) + { + + } + } diff --git a/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp b/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp index 03990971b64..f9b7ea9703f 100644 --- a/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp @@ -12,12 +12,81 @@ namespace hal { + PinTreeItem::PinTreeItem(const std::string &pinName, QString pinDirection, QString pinType, QString netName) + :mPinName(pinName), mPinDirection(pinDirection), mPinType(pinType), mNetName(netName) + {;} + + PinTreeItem::PinTreeItem() + {;} + + QVariant PinTreeItem::getData(int index) const + { + switch (index) + { + case 0: { + QVariant qvPinName = QVariant(QString::fromStdString(mPinName)); + return qvPinName; + break;} + case 1: { + QVariant qvPinDirection = QVariant(mPinDirection); + return qvPinDirection; + break;} + case 2: { + QVariant qvPinType = QVariant(mPinType); + return qvPinType; + break;} + case 3: { + QVariant qvNetName = QVariant(mNetName); + return qvNetName; + break;} + } + } + + void PinTreeItem::setData(QList data) + { + mPinName = data[0].toString().toStdString(); + mPinDirection = data[1].toString(); + mPinType = data[2].toString(); + mNetName = data[3].toString(); + } + + void PinTreeItem::setDataAtIndex(int index, QVariant &data) + { + switch (index) + { + case 0: { + mPinName = data.toString().toStdString(); + break;} + case 1: { + mPinDirection = data.toString(); + break;} + case 2: { + mPinType = data.toString(); + break;} + case 3: { + mNetName = data.toString(); + break;} + } + + + } + + void PinTreeItem::appendData(QVariant data) + { + + } + + int PinTreeItem::getColumnCount() const + { + return 4; + } + GatePinsTreeModel::GatePinsTreeModel(QObject* parent) : BaseTreeModel(parent) { - setHeaderLabels(QList() << "Name" - << "Direction" - << "Type" - << "Connected Net"); + setHeaderLabels(QStringList() << "Name" + << "Direction" + << "Type" + << "Connected Net"); //added to store a list of (multiple) net ids in a given treeitem (perhaps dont do this //at all, handle it in the view? (since the gate-id and pin name is accessable, the nets can be evaluated there @@ -45,7 +114,7 @@ namespace hal GateType* gateType = g->get_type(); for (auto pin : gateType->get_pins()) { - BaseTreeItem* pinItem = new BaseTreeItem(); + PinTreeItem* pinItem = new PinTreeItem(); //get all infos for that pin const std::string& grouping = pin->get_group().first->get_name(); PinDirection direction = pin->get_direction(); @@ -100,7 +169,7 @@ namespace hal if (!groupingsItem) { //assume all items in the same grouping habe the same direction and type, so the grouping-item has also these types - groupingsItem = new BaseTreeItem(QList() << QString::fromStdString(grouping) << pinDirection << pinType << ""); + groupingsItem = new PinTreeItem(grouping, pinDirection, pinType, ""); groupingsItem->setAdditionalData(keyType, QVariant::fromValue(itemType::grouping)); mRootItem->appendChild(groupingsItem); mPinGroupingToTreeItem.insert(grouping, groupingsItem); @@ -136,4 +205,7 @@ namespace hal return g->get_type()->get_pins().size(); } + + + } // namespace hal diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp index 86762bcec22..d04b547c2f5 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp @@ -9,9 +9,69 @@ namespace hal { + + ModuleTreeitem::ModuleTreeitem(const std::string &name, int id, std::string tp) + : mType(tp), mId(id), mName(name) + {;} + + QVariant ModuleTreeitem::getData(int index) const + { + switch (index) + { + case 0: { + QVariant qvName = QVariant(QString::fromStdString(mName)); + return qvName; + break;} + case 1: { + QVariant qvId = QVariant(mId); + return qvId; + break;} + case 2: { + QVariant qvType = QVariant(QString::fromStdString(mType)); + return qvType; + break;} + } + } + + void ModuleTreeitem::setData(QList data) + { + mName = data[0].toString().toStdString(); + mId = data[1].toInt(); + mType = data[2].toString().toStdString(); + } + + void ModuleTreeitem::setDataAtIndex(int index, QVariant &data) + { + const char* ctyp[] = { "module", "gate"}; + + switch (index) + { + case 0: mName = data.toString().toStdString(); break; + case 1: mId = data.toInt(); break; + case 2: + for (int j=0; j<3; j++) + if (data.toString() == ctyp[j]) + { + mType = data.toString().toStdString(); + break; + } + } + } + + void ModuleTreeitem::appendData(QVariant data) + { + + } + + int ModuleTreeitem::getColumnCount() const + { + return 3; + } + + ModuleTreeModel::ModuleTreeModel(QObject* parent) : BaseTreeModel(parent), mModId(-1) { - setHeaderLabels(QList() << "Name" << "ID" << "Type"); + setHeaderLabels(QStringList() << "Name" << "ID" << "Type"); } ModuleTreeModel::~ModuleTreeModel() @@ -41,8 +101,8 @@ namespace hal //add modules for(auto mod : m->get_submodules()) { - BaseTreeItem* modItem = new BaseTreeItem(QList() << QString::fromStdString(mod->get_name()) - << mod->get_id() << QString::fromStdString(mod->get_type())); + ModuleTreeitem* modItem = new ModuleTreeitem(mod->get_name(), + mod->get_id(), mod->get_type()); moduleRecursive(mod, modItem); modItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::module)); modItem->setAdditionalData(mKeyRepId, mod->get_id()); @@ -52,8 +112,8 @@ namespace hal //add gates for(auto gate : m->get_gates()) { - BaseTreeItem* gateItem = new BaseTreeItem(QList() << QString::fromStdString(gate->get_name()) - << gate->get_id() << QString::fromStdString(gate->get_type()->get_name())); + ModuleTreeitem* gateItem = new ModuleTreeitem(gate->get_name(), + gate->get_id(), gate->get_type()->get_name()); gateItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::gate)); gateItem->setAdditionalData(mKeyRepId, gate->get_id()); mRootItem->appendChild(gateItem); @@ -97,11 +157,11 @@ namespace hal void ModuleTreeModel::moduleRecursive(Module *mod, BaseTreeItem *modItem) { - BaseTreeItem* subModItem = nullptr; + ModuleTreeitem* subModItem = nullptr; for(Module* subMod : mod->get_submodules()) { - subModItem = new BaseTreeItem(QList() << QString::fromStdString(subMod->get_name()) - << subMod->get_id() << QString::fromStdString(subMod->get_type())); + subModItem = new ModuleTreeitem(subMod->get_name(), + subMod->get_id(), subMod->get_type()); moduleRecursive(subMod, subModItem); subModItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::module)); subModItem->setAdditionalData(mKeyRepId, subMod->get_id()); @@ -110,8 +170,8 @@ namespace hal } for(auto gate : mod->get_gates()) { - BaseTreeItem* gateItem = new BaseTreeItem(QList() << QString::fromStdString(gate->get_name()) - << gate->get_id() << QString::fromStdString(gate->get_type()->get_name())); + ModuleTreeitem* gateItem = new ModuleTreeitem(gate->get_name(), + gate->get_id(), gate->get_type()->get_name()); gateItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::gate)); gateItem->setAdditionalData(mKeyRepId, gate->get_id()); modItem->appendChild(gateItem); @@ -153,8 +213,8 @@ namespace hal beginResetModel(); for(auto gate : mod->get_gates()) { - BaseTreeItem* gateItem = new BaseTreeItem(QList() << QString::fromStdString(gate->get_name()) - << gate->get_id() << QString::fromStdString(gate->get_type()->get_name())); + ModuleTreeitem* gateItem = new ModuleTreeitem(gate->get_name(), + gate->get_id(), gate->get_type()->get_name()); gateItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::gate)); gateItem->setAdditionalData(mKeyRepId, gate->get_id()); modItem->appendChild(gateItem); @@ -238,8 +298,8 @@ namespace hal { beginResetModel(); auto addedMod = gNetlist->get_module_by_id(added_module); - BaseTreeItem* addedSubmodItem = new BaseTreeItem(QList() << QString::fromStdString(addedMod->get_name()) << addedMod->get_id() - << QString::fromStdString(addedMod->get_type())); + ModuleTreeitem* addedSubmodItem = new ModuleTreeitem(addedMod->get_name(), addedMod->get_id(), + addedMod->get_type()); moduleRecursive(addedMod, addedSubmodItem); addedSubmodItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::module)); addedSubmodItem->setAdditionalData(mKeyRepId, addedMod->get_id()); @@ -296,8 +356,8 @@ namespace hal if(getTypeOfItem(modItem->getChild(indexToInsert)) != itemType::module) break; - BaseTreeItem* gateItem = new BaseTreeItem(QList() << QString::fromStdString(assignedGate->get_name()) - << assignedGate->get_id() << QString::fromStdString(assignedGate->get_type()->get_name())); + ModuleTreeitem* gateItem = new ModuleTreeitem(assignedGate->get_name(), + assignedGate->get_id(), assignedGate->get_type()->get_name()); gateItem->setAdditionalData(mKeyItemType, QVariant::fromValue(itemType::gate)); mGateToTreeitems.insert(assignedGate, gateItem); //beginInsertRows(getIndexFromItem(modItem), indexToInsert, indexToInsert); @@ -336,7 +396,8 @@ namespace hal auto gateItem = mGateToTreeitems.value(g, nullptr); if(gateItem) { - gateItem->setDataAtIndex(sNameColumn, QString::fromStdString(g->get_name())); + QVariant qv = QVariant(QString::fromStdString(g->get_name())); + gateItem->setDataAtIndex(sNameColumn, qv); QModelIndex inx0 = getIndexFromItem(gateItem); QModelIndex inx1 = createIndex(inx0.row(), sNameColumn, inx0.internalPointer()); Q_EMIT dataChanged(inx0, inx1); @@ -348,7 +409,8 @@ namespace hal auto moduleItem = mModuleToTreeitems.value(m, nullptr); if(moduleItem) { - moduleItem->setDataAtIndex(sNameColumn, QString::fromStdString(m->get_name())); + QVariant qv = QVariant(QString::fromStdString(m->get_name())); + moduleItem->setDataAtIndex(sNameColumn, qv); QModelIndex inx0 = getIndexFromItem(moduleItem); QModelIndex inx1 = createIndex(inx0.row(), sNameColumn, inx0.internalPointer()); Q_EMIT dataChanged(inx0, inx1); @@ -360,7 +422,8 @@ namespace hal auto moduleItem = mModuleToTreeitems.value(m, nullptr); if(moduleItem) { - moduleItem->setDataAtIndex(sTypeColumn, QString::fromStdString(m->get_type())); + QVariant qv = QVariant(QString::fromStdString(m->get_type())); + moduleItem->setDataAtIndex(sTypeColumn, qv); QModelIndex inx0 = getIndexFromItem(moduleItem); QModelIndex inx1 = createIndex(inx0.row(), sTypeColumn, inx0.internalPointer()); Q_EMIT dataChanged(inx0, inx1); @@ -416,4 +479,7 @@ namespace hal mEventsConnected = true; } + + + } diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp index 107155d218b..536d24d6103 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp @@ -27,7 +27,7 @@ namespace hal return qvId; break;} case 2: { - QVariant qvType = QVariant(mTypee); + QVariant qvType = QVariant(mType); return qvType; break;} } @@ -43,7 +43,7 @@ namespace hal void NetlistElementsTreeitem::setDataAtIndex(int index, QVariant &data) { - const char* ctyp[] = { "Module", "Gate", "Net"}; + const char* ctyp[] = { "module", "gate", "net"}; switch (index) { @@ -59,6 +59,11 @@ namespace hal } } + void NetlistElementsTreeitem::appendData(QVariant data) + { + + } + int NetlistElementsTreeitem::getColumnCount() const { return 3; @@ -473,7 +478,9 @@ namespace hal void NetlistElementsTreeModel::updateInternalNetsOfModule(NetlistElementsTreeitem *moduleItem) { - int moduleId = (moduleItem == mRootItem) ? mModId : moduleItem->getAdditionalData(keyRepresentedID).toInt(); + BaseTreeItem* moduleItemBase = static_cast(moduleItem); + BaseTreeItem* mRootBase = static_cast(mRootItem); + int moduleId = (moduleItemBase == mRootBase) ? mModId : moduleItem->getAdditionalData(keyRepresentedID).toInt(); Module* mod = gNetlist->get_module_by_id(moduleId); //remove and delte the last child of the module-item until no net items are left while(moduleItem->getChildCount() > 0 && getTypeOfItem(static_cast(moduleItem->getChild(moduleItem->getChildCount()-1))) == itemType::net) diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp index 1453d6c0ef1..b9368a2d143 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp @@ -19,12 +19,77 @@ namespace hal { + PortTreeItem::PortTreeItem(QString pinName, QString pinDirection, QString pinTypee, QString netName) + { + + } + + QVariant PortTreeItem::getData(int index) const + { + switch (index) + { + case 0: { + QVariant qvPinName = QVariant(mPinName); + return qvPinName; + break;} + case 1: { + QVariant qvPinDirection = QVariant(mPinDirection); + return qvPinDirection; + break;} + case 2: { + QVariant qvPinType = QVariant(mPinType); + return qvPinType; + break;} + case 3: { + QVariant qvNetName = QVariant(mNetName); + return qvNetName; + break;} + } + } + + void PortTreeItem::setData(QList data) + { + mPinName = data[0].toString(); + mPinDirection = data[1].toString(); + mPinType = data[2].toString(); + mNetName = data[3].toString(); + } + + void PortTreeItem::setDataAtIndex(int index, QVariant &data) + { + switch (index) + { + case 0: { + mPinName = data.toString(); + break;} + case 1: { + mPinDirection = data.toString(); + break;} + case 2: { + mPinType = data.toString(); + break;} + case 3: { + mNetName = data.toString(); + break;} + } + } + + void PortTreeItem::appendData(QVariant data) + { + + } + + int PortTreeItem::getColumnCount() const + { + return 4; + } + ModulePinsTreeModel::ModulePinsTreeModel(QObject* parent) : BaseTreeModel(parent), mIgnoreEventsFlag(false) { setHeaderLabels(QStringList() << "Name" - << "Direction" - << "Type" - << "Connected Net"); + << "Direction" + << "Type" + << "Connected Net"); setModule(gNetlist->get_module_by_id(1)); //connections @@ -348,16 +413,16 @@ namespace hal auto pinGroupDirection = QString::fromStdString(enum_to_string((pinGroup->get_direction()))); auto pinGroupType = QString::fromStdString(enum_to_string(pinGroup->get_type())); - BaseTreeItem* pinGroupItem = new BaseTreeItem(QList() << pinGroupName << pinGroupDirection << pinGroupType << ""); + PortTreeItem* pinGroupItem = new PortTreeItem(pinGroupName, pinGroupDirection, pinGroupType, ""); pinGroupItem->setAdditionalData(keyType, QVariant::fromValue(itemType::group)); // port multi bit pinGroupItem->setAdditionalData(keyId, pinGroup->get_id()); mIdToGroupItem.insert(pinGroup->get_id(), pinGroupItem); for(ModulePin* pin : pinGroup->get_pins()) { - BaseTreeItem* pinItem = new BaseTreeItem(QList() << QString::fromStdString(pin->get_name()) - << QString::fromStdString(enum_to_string(pin->get_direction())) - << QString::fromStdString(enum_to_string(pin->get_type())) - << QString::fromStdString(pin->get_net()->get_name())); + PortTreeItem* pinItem = new PortTreeItem(QString::fromStdString(pin->get_name()), + QString::fromStdString(enum_to_string(pin->get_direction())), + QString::fromStdString(enum_to_string(pin->get_type())), + QString::fromStdString(pin->get_net()->get_name())); pinItem->setAdditionalData(keyType, QVariant::fromValue(itemType::pin)); pinItem->setAdditionalData(keyId, pin->get_id()); pinGroupItem->appendChild(pinItem); @@ -599,7 +664,7 @@ namespace hal auto pinGroupDirection = QString::fromStdString(enum_to_string((newGroup->get_direction()))); auto pinGroupType = QString::fromStdString(enum_to_string(newGroup->get_type())); - BaseTreeItem* pinGroupItem = new BaseTreeItem(QList() << pinGroupName << pinGroupDirection << pinGroupType << ""); + PortTreeItem* pinGroupItem = new PortTreeItem(pinGroupName, pinGroupDirection, pinGroupType, ""); pinGroupItem->setAdditionalData(keyType, QVariant::fromValue(itemType::group)); pinGroupItem->setAdditionalData(keyId, newGroup->get_id()); @@ -638,4 +703,7 @@ namespace hal //mIdToPinItem.remove(getIdOfItem(item)); //delete item; } + + + } // namespace hal diff --git a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_item.cpp b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_item.cpp index 989e9516d6f..1fbdd78594e 100644 --- a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_item.cpp +++ b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_item.cpp @@ -1,5 +1,5 @@ #include "gui/gui_globals.h" -#include "gui/selection_details_widget/tree_navigation/selection_base_tree_item.h" +#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" #include "gui/selection_details_widget/selection_details_icon_provider.h" namespace hal diff --git a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_model.cpp b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_model.cpp index 89b0dc5c19c..9e61ffcfc85 100644 --- a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_model.cpp @@ -1,5 +1,5 @@ #include "gui/selection_details_widget/tree_navigation/selection_tree_model.h" -#include "gui/selection_details_widget/tree_navigation/selection_base_tree_item.h" +#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" #include "gui/gui_globals.h" #include "hal_core/netlist/gate.h" #include "hal_core/netlist/net.h" diff --git a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp index b902ccfb333..3f98627c2bb 100644 --- a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp +++ b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_proxy.cpp @@ -1,6 +1,6 @@ #include "gui/selection_details_widget/tree_navigation/selection_tree_proxy.h" #include "gui/selection_details_widget/tree_navigation/selection_tree_model.h" -#include "gui/selection_details_widget/tree_navigation/selection_base_tree_item.h" +#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" #include "gui/gui_globals.h" From baaaddb1b64cf8be572327a1ebd03391c329424f Mon Sep 17 00:00:00 2001 From: joern274 Date: Tue, 4 Jul 2023 13:55:06 +0200 Subject: [PATCH 03/36] adapt header name in wave_widget --- plugins/gui/include/gui/module_widget/module_widget.h | 2 -- plugins/simulator/waveform_viewer/src/wave_widget.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/gui/include/gui/module_widget/module_widget.h b/plugins/gui/include/gui/module_widget/module_widget.h index 475fef1b1ef..d8250e0d016 100644 --- a/plugins/gui/include/gui/module_widget/module_widget.h +++ b/plugins/gui/include/gui/module_widget/module_widget.h @@ -180,8 +180,6 @@ namespace hal QAction* mFilterAction; - QSortFilterProxyModel* mCurrentModel; - QList mRegexps; bool mIgnoreSelectionChange; diff --git a/plugins/simulator/waveform_viewer/src/wave_widget.cpp b/plugins/simulator/waveform_viewer/src/wave_widget.cpp index 62ee1ce6a4b..34564856e00 100644 --- a/plugins/simulator/waveform_viewer/src/wave_widget.cpp +++ b/plugins/simulator/waveform_viewer/src/wave_widget.cpp @@ -26,7 +26,7 @@ #include "gui/grouping/grouping_manager_widget.h" #include "gui/grouping/grouping_table_model.h" #include "gui/selection_details_widget/selection_details_widget.h" -#include "gui/selection_details_widget/tree_navigation/selection_base_tree_item.h" +#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" #include "gui/gui_globals.h" namespace hal { From 01912eece6aada71ee14f6563c673e75d463e421 Mon Sep 17 00:00:00 2001 From: Skaleee Date: Wed, 5 Jul 2023 20:20:27 +0200 Subject: [PATCH 04/36] Added buttons for the ModuleWidget to toggle the visibility of nets and gates. Their functionality is not yet implemented. --- .../gui/module_model/module_proxy_model.h | 15 +++ .../include/gui/module_widget/module_widget.h | 49 +++++++- plugins/gui/resources/stylesheet/dark.qss | 12 ++ plugins/gui/resources/stylesheet/light.qss | 12 ++ .../src/module_model/module_proxy_model.cpp | 16 ++- .../gui/src/module_widget/module_widget.cpp | 116 ++++++++++++++++++ 6 files changed, 217 insertions(+), 3 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_proxy_model.h b/plugins/gui/include/gui/module_model/module_proxy_model.h index d142763de15..e8317727f33 100644 --- a/plugins/gui/include/gui/module_model/module_proxy_model.h +++ b/plugins/gui/include/gui/module_model/module_proxy_model.h @@ -64,6 +64,18 @@ namespace hal */ void setSortMechanism(gui_utility::mSortMechanism sortMechanism); + /** + * Toggles whether or not nets are accepted by the filter. NOT YET ACTUALLY IMPLEMENTED + * @returns true if nets are filtered out now. false if not. + */ + bool toggleFilterNets(); + + /** + * Toggles whether or not gates are accepted by the filter. NOT YET ACTUALLY IMPLEMENTED + * @returns true if gates are filtered out now. false if not. + */ + bool toggleFilterGates(); + protected: /** * Overrides QSortFilterProxyModel::filterAcceptsRow to implement the filter logic based on the regular @@ -89,5 +101,8 @@ namespace hal private: gui_utility::mSortMechanism mSortMechanism; + + bool mFilterNets; + bool mFilterGates; }; } diff --git a/plugins/gui/include/gui/module_widget/module_widget.h b/plugins/gui/include/gui/module_widget/module_widget.h index 475fef1b1ef..49584671321 100644 --- a/plugins/gui/include/gui/module_widget/module_widget.h +++ b/plugins/gui/include/gui/module_widget/module_widget.h @@ -55,6 +55,14 @@ namespace hal class ModuleWidget : public ContentWidget { Q_OBJECT + Q_PROPERTY(QString showNetsIconPath READ showNetsIconPath WRITE setShowNetsIconPath) + Q_PROPERTY(QString showNetsIconStyle READ showNetsIconStyle WRITE setShowNetsIconStyle) + Q_PROPERTY(QString hideNetsIconPath READ hideNetsIconPath WRITE setHideNetsIconPath) + Q_PROPERTY(QString hideNetsIconStyle READ hideNetsIconStyle WRITE setHideNetsIconStyle) + Q_PROPERTY(QString showGatesIconPath READ showGatesIconPath WRITE setShowGatesIconPath) + Q_PROPERTY(QString showGatesIconStyle READ showGatesIconStyle WRITE setShowGatesIconStyle) + Q_PROPERTY(QString hideGatesIconPath READ hideGatesIconPath WRITE setHideGatesIconPath) + Q_PROPERTY(QString hideGatesIconStyle READ hideGatesIconStyle WRITE setHideGatesIconStyle) Q_PROPERTY(QString searchIconPath READ searchIconPath WRITE setSearchIconPath) Q_PROPERTY(QString searchIconStyle READ searchIconStyle WRITE setSearchIconStyle) Q_PROPERTY(QString searchActiveIconStyle READ searchActiveIconStyle WRITE setSearchActiveIconStyle) @@ -100,6 +108,14 @@ namespace hal /** @name Q_PROPERTY READ Functions */ ///@{ + QString showNetsIconPath() const; + QString showNetsIconStyle() const; + QString hideNetsIconPath() const; + QString hideNetsIconStyle() const; + QString showGatesIconPath() const; + QString showGatesIconStyle() const; + QString hideGatesIconPath() const; + QString hideGatesIconStyle() const; QString searchIconPath() const; QString searchIconStyle() const; QString searchActiveIconStyle() const; @@ -108,6 +124,14 @@ namespace hal /** @name Q_PROPERTY WRITE Functions */ ///@{ + void setShowNetsIconPath(const QString &path); + void setShowNetsIconStyle(const QString &path); + void setHideNetsIconPath(const QString &path); + void setHideNetsIconStyle(const QString &path); + void setShowGatesIconPath(const QString &path); + void setShowGatesIconStyle(const QString &path); + void setHideGatesIconPath(const QString &path); + void setHideGatesIconStyle(const QString &path); void setSearchIconPath(const QString &path); void setSearchIconStyle(const QString &style); void setSearchActiveIconStyle(const QString &style); @@ -169,19 +193,40 @@ namespace hal */ void handleModuleRemoved(Module* module, u32 module_id); + private Q_SLOTS: + /** + * Q_SLOT to toggle the visibility of nets in the module widget. Called when the 'Toggle Net Visibility'-buttons was clicked. + */ + void handleToggleNetsClicked(); + + /** + * Q_SLOT to toggle the visibility of gates in the module widget. Called when the 'Toggle Gate Visibility'-buttons was clicked. + */ + void handleToggleGatesClicked(); + private: ModuleTreeView* mTreeView; Searchbar* mSearchbar; + QAction* mToggleNetsAction; + QString mShowNetsIconPath; + QString mShowNetsIconStyle; + QString mHideNetsIconPath; + QString mHideNetsIconStyle; + + QAction* mToggleGatesAction; + QString mShowGatesIconPath; + QString mShowGatesIconStyle; + QString mHideGatesIconPath; + QString mHideGatesIconStyle; + QString mSearchIconPath; QString mSearchIconStyle; QString mSearchActiveIconStyle; QAction* mFilterAction; - QSortFilterProxyModel* mCurrentModel; - QList mRegexps; bool mIgnoreSelectionChange; diff --git a/plugins/gui/resources/stylesheet/dark.qss b/plugins/gui/resources/stylesheet/dark.qss index 2b5e28b84e8..dc9fb90ec6f 100755 --- a/plugins/gui/resources/stylesheet/dark.qss +++ b/plugins/gui/resources/stylesheet/dark.qss @@ -1176,6 +1176,18 @@ hal--Toolbar QPushButton:checked:hover { } hal--ModuleWidget { + qproperty-showNetsIconStyle: "all->#e8e8e8"; + qproperty-showNetsIconPath: ":/icons/ne_net"; + + qproperty-hideNetsIconStyle: "all->#e8e8e8"; + qproperty-hideNetsIconPath: ":/icons/ne_no_net"; + + qproperty-showGatesIconStyle: "all->#e8e8e8"; + qproperty-showGatesIconPath: ":/icons/ne_gate"; + + qproperty-hideGatesIconStyle: "all->#e8e8e8"; + qproperty-hideGatesIconPath: ":/icons/ne_no_gate"; + qproperty-searchActiveIconStyle: "all->#30ac4f"; qproperty-searchIconStyle: "all->#e8e8e8"; qproperty-searchIconPath: ":/icons/search"; diff --git a/plugins/gui/resources/stylesheet/light.qss b/plugins/gui/resources/stylesheet/light.qss index 5bcc77f0a1e..3e7a16379c3 100755 --- a/plugins/gui/resources/stylesheet/light.qss +++ b/plugins/gui/resources/stylesheet/light.qss @@ -1200,6 +1200,18 @@ hal--Toolbar QPushButton:checked:hover { } hal--ModuleWidget { + qproperty-showNetsIconStyle: "all->#FFFFFF"; + qproperty-showNetsIconPath: ":/icons/ne_net"; + + qproperty-hideNetsIconStyle: "all->#FFFFFF"; + qproperty-hideNetsIconPath: ":/icons/ne_no_net"; + + qproperty-showGatesIconStyle: "all->#FFFFFF"; + qproperty-showGatesIconPath: ":/icons/ne_gate"; + + qproperty-hideGatesIconStyle: "all->#FFFFFF"; + qproperty-hideGatesIconPath: ":/icons/ne_no_gate"; + qproperty-searchActiveIconStyle: "all->#30ac4f"; qproperty-searchIconStyle: "all->#FFFFFF"; qproperty-searchIconPath: ":/icons/search"; diff --git a/plugins/gui/src/module_model/module_proxy_model.cpp b/plugins/gui/src/module_model/module_proxy_model.cpp index 482fbc96ac2..3783b04317b 100644 --- a/plugins/gui/src/module_model/module_proxy_model.cpp +++ b/plugins/gui/src/module_model/module_proxy_model.cpp @@ -5,7 +5,7 @@ namespace hal { - ModuleProxyModel::ModuleProxyModel(QObject* parent) : QSortFilterProxyModel(parent), mSortMechanism(gui_utility::mSortMechanism::lexical) + ModuleProxyModel::ModuleProxyModel(QObject* parent) : QSortFilterProxyModel(parent), mSortMechanism(gui_utility::mSortMechanism::lexical), mFilterNets(false), mFilterGates(false) { // QTS PROXY MODELS ARE DUMB, IMPLEMENT CUSTOM SOLUTION OR SWITCH TO A DIFFERENT FILTER METHOD @@ -14,6 +14,20 @@ namespace hal // STYLED DELEGATES USE THAT DATA STRUCTURE TO DRAW THEMSELVES } + bool ModuleProxyModel::toggleFilterNets() + { + mFilterNets = !mFilterNets; + invalidateFilter(); + return mFilterNets; + } + + bool ModuleProxyModel::toggleFilterGates() + { + mFilterGates = !mFilterGates; + invalidateFilter(); + return mFilterGates; + } + bool ModuleProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { if(filterRegularExpression().pattern().isEmpty()) diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index f5948460a20..acc4268112f 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -32,6 +32,8 @@ namespace hal : ContentWidget("Modules", parent), mTreeView(new ModuleTreeView(this)), mSearchbar(new Searchbar(this)), + mToggleNetsAction(new QAction(this)), + mToggleGatesAction(new QAction(this)), mModuleProxyModel(new ModuleProxyModel(this)) { @@ -39,7 +41,12 @@ namespace hal connect(mTreeView, &QTreeView::customContextMenuRequested, this, &ModuleWidget::handleTreeViewContextMenuRequested); + mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mShowNetsIconStyle, mShowNetsIconPath)); + mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mShowGatesIconStyle, mShowGatesIconPath)); mSearchAction->setIcon(gui_utility::getStyledSvgIcon(mSearchIconStyle, mSearchIconPath)); + + mToggleNetsAction->setToolTip("Toggle Net Visibility"); + mToggleGatesAction->setToolTip("Toggle Gate Visibility"); mSearchAction->setToolTip("Search"); mModuleProxyModel->setFilterKeyColumn(-1); @@ -73,10 +80,39 @@ namespace hal connect(mSearchAction, &QAction::triggered, this, &ModuleWidget::toggleSearchbar); connect(mSearchbar, &Searchbar::textEdited, this, &ModuleWidget::updateSearchIcon); + + connect(mToggleNetsAction, &QAction::triggered, this, &ModuleWidget::handleToggleNetsClicked); + connect(mToggleGatesAction, &QAction::triggered, this, &ModuleWidget::handleToggleGatesClicked); + } + + void ModuleWidget::handleToggleNetsClicked() + { + if(mModuleProxyModel->toggleFilterNets()) + { + mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mHideNetsIconStyle, mHideNetsIconPath)); + } + else + { + mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mShowNetsIconStyle, mShowNetsIconPath)); + } + } + + void ModuleWidget::handleToggleGatesClicked() + { + if(mModuleProxyModel->toggleFilterGates()) + { + mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mHideGatesIconStyle, mHideGatesIconPath)); + } + else + { + mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mShowGatesIconStyle, mShowGatesIconPath)); + } } void ModuleWidget::setupToolbar(Toolbar* toolbar) { + toolbar->addAction(mToggleNetsAction); + toolbar->addAction(mToggleGatesAction); toolbar->addAction(mSearchAction); } @@ -295,6 +331,46 @@ namespace hal return mModuleProxyModel; } + QString ModuleWidget::showNetsIconPath() const + { + return mShowNetsIconPath; + } + + QString ModuleWidget::showNetsIconStyle() const + { + return mShowNetsIconStyle; + } + + QString ModuleWidget::hideNetsIconPath() const + { + return mHideNetsIconPath; + } + + QString ModuleWidget::hideNetsIconStyle() const + { + return mHideNetsIconStyle; + } + + QString ModuleWidget::showGatesIconPath() const + { + return mShowGatesIconPath; + } + + QString ModuleWidget::showGatesIconStyle() const + { + return mShowGatesIconStyle; + } + + QString ModuleWidget::hideGatesIconPath() const + { + return mHideGatesIconPath; + } + + QString ModuleWidget::hideGatesIconStyle() const + { + return mHideGatesIconStyle; + } + QString ModuleWidget::searchIconPath() const { return mSearchIconPath; @@ -310,6 +386,46 @@ namespace hal return mSearchActiveIconStyle; } + void ModuleWidget::setShowNetsIconPath(const QString& path) + { + mShowNetsIconPath = path; + } + + void ModuleWidget::setShowNetsIconStyle(const QString& path) + { + mShowNetsIconStyle = path; + } + + void ModuleWidget::setHideNetsIconPath(const QString& path) + { + mHideNetsIconPath = path; + } + + void ModuleWidget::setHideNetsIconStyle(const QString& path) + { + mHideNetsIconStyle = path; + } + + void ModuleWidget::setShowGatesIconPath(const QString& path) + { + mShowGatesIconPath = path; + } + + void ModuleWidget::setShowGatesIconStyle(const QString& path) + { + mShowGatesIconStyle = path; + } + + void ModuleWidget::setHideGatesIconPath(const QString& path) + { + mHideGatesIconPath = path; + } + + void ModuleWidget::setHideGatesIconStyle(const QString& path) + { + mHideGatesIconStyle = path; + } + void ModuleWidget::setSearchIconPath(const QString& path) { mSearchIconPath = path; From b8d3b1693f0e409bd4c298018d36ce41c934896e Mon Sep 17 00:00:00 2001 From: Skaleee Date: Tue, 11 Jul 2023 02:44:48 +0200 Subject: [PATCH 05/36] Added header and more columns to module widget. --- .../include/gui/module_model/module_item.h | 7 ++-- plugins/gui/src/module_model/module_item.cpp | 34 ++++++++++++++++--- plugins/gui/src/module_model/module_model.cpp | 21 ++++++++---- .../gui/src/module_widget/module_widget.cpp | 2 +- 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_item.h b/plugins/gui/include/gui/module_model/module_item.h index 2a692fea251..1845481f012 100644 --- a/plugins/gui/include/gui/module_model/module_item.h +++ b/plugins/gui/include/gui/module_model/module_item.h @@ -43,12 +43,14 @@ namespace hal class ModuleItem { public: + enum class TreeItemType {Top, Module, Gate, Net}; + /** * Constructor. * * @param id - The id of the module this item represents */ - ModuleItem(const u32 id); + ModuleItem(const u32 id, const TreeItemType type = TreeItemType::Module); /** * Appends a child ModuleItem to this ModuleItem. @@ -199,9 +201,10 @@ namespace hal private: ModuleItem* mParent; - QList mChildItems; + QList mChildItems; // memory leak? qDeleteAll() or mChildItems.clear()? in Destructor u32 mId; + TreeItemType mType; QString mName; QColor mColor; diff --git a/plugins/gui/src/module_model/module_item.cpp b/plugins/gui/src/module_model/module_item.cpp index 3293d0ae39a..b15eb2beeed 100644 --- a/plugins/gui/src/module_model/module_item.cpp +++ b/plugins/gui/src/module_model/module_item.cpp @@ -7,13 +7,14 @@ namespace hal { - ModuleItem::ModuleItem(const u32 id) : + ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : mParent(nullptr), mId(id), + mType(type), mName(QString::fromStdString(gNetlist->get_module_by_id(id)->get_name())), mColor(gNetlistRelay->getModuleColor(id)), mHighlighted(false) - {;} + {} void ModuleItem::insertChild(int row, ModuleItem* child) { @@ -32,6 +33,9 @@ namespace hal void ModuleItem::appendExistingChildIfAny(const QMap& moduleMap) { + if(mType != TreeItemType::Module && mType != TreeItemType::Top) + return; + Module* m = gNetlist->get_module_by_id(mId); Q_ASSERT(m); for (Module* subm : m->get_submodules()) @@ -88,9 +92,29 @@ namespace hal QVariant ModuleItem::data(int column) const { // DEBUG CODE, USE STYLED DELEGATES OR SOMETHING - if (column != 0) - return QVariant(); - return mName; + if(column == 0) + return mName; + else if (column == 1) + return mId; + else if(column == 2) + { + switch(mType) + { + case TreeItemType::Module: + { + Module* module = gNetlist->get_module_by_id(mId); + if(!module) + return QVariant(); + return QString::fromStdString(module->get_type()); + } + case TreeItemType::Gate: + Gate* gate = gNetlist->get_gate_by_id(mId); + if(!gate) + return QVariant(); + return QString::fromStdString(gate->get_type()->get_name()); + } + } + return QVariant(); } QString ModuleItem::name() const diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 267da560738..a08386188e0 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -20,16 +20,18 @@ namespace hal { // BEHAVIOR FOR ILLEGAL INDICES IS UNDEFINED // SEE QT DOCUMENTATION + if (!hasIndex(row, column, parent)) + return QModelIndex(); if (!parent.isValid()) { - if (row == 0 && column == 0 && mTopModuleItem) - return createIndex(0, 0, mTopModuleItem); + if (row == 0 && column >= 0 && column < 3 && mTopModuleItem) + return createIndex(0, column, mTopModuleItem); else return QModelIndex(); } - if (column != 0 || parent.column() != 0) + if (column < 0 || column >= 3 || parent.column() < 0 || parent.column() >= 3) return QModelIndex(); ModuleItem* parent_item = getItem(parent); @@ -86,8 +88,8 @@ namespace hal if (!parent.isValid()) // ?? return 1; - if (parent.column() != 0) - return 0; + //if (parent.column() != 0) + // return 0; ModuleItem* parent_item = getItem(parent); @@ -98,7 +100,7 @@ namespace hal { Q_UNUSED(parent) - return 1; + return 3; } QVariant ModuleModel::data(const QModelIndex& index, int role) const @@ -151,10 +153,15 @@ namespace hal QVariant ModuleModel::headerData(int section, Qt::Orientation orientation, int role) const { - Q_UNUSED(section) + /*Q_UNUSED(section) Q_UNUSED(orientation) Q_UNUSED(role) + return QVariant();*/ + const char* horizontalHeader[] = { "Name", "ID", "Type"}; + if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section < columnCount()) + return QString(horizontalHeader[section]); + return QVariant(); } diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index acc4268112f..f8e6249fe20 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -60,7 +60,7 @@ namespace hal mTreeView->setContextMenuPolicy(Qt::CustomContextMenu); mTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers); mTreeView->setFrameStyle(QFrame::NoFrame); - mTreeView->header()->close(); + //mTreeView->header()->close(); mTreeView->setExpandsOnDoubleClick(false); mTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection); mTreeView->expandAll(); From e724872d6550157b92592a3c10ec00dcf42a8a35 Mon Sep 17 00:00:00 2001 From: Skaleee Date: Fri, 14 Jul 2023 15:14:08 +0200 Subject: [PATCH 06/36] Added gates and nets to the ModuleModel. --- .../include/gui/module_model/module_item.h | 33 ++-- .../include/gui/module_model/module_model.h | 63 +++++-- plugins/gui/src/module_model/module_item.cpp | 26 ++- plugins/gui/src/module_model/module_model.cpp | 166 +++++++++++++++--- 4 files changed, 236 insertions(+), 52 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_item.h b/plugins/gui/include/gui/module_model/module_item.h index 1845481f012..579f6cc0579 100644 --- a/plugins/gui/include/gui/module_model/module_item.h +++ b/plugins/gui/include/gui/module_model/module_item.h @@ -38,17 +38,21 @@ namespace hal * @ingroup gui * @brief An item in the ModuleModel. * - * The ModuleItem is one item in the ModuleModel item model. It represents one module of the netlist. + * The ModuleItem is one item in the ModuleModel item model. It represents either a module, a gate or a net of the netlist. */ class ModuleItem { public: - enum class TreeItemType {Top, Module, Gate, Net}; + /** + * The possible types that a ModuleItem in the ModuleModel can have. + */ + enum class TreeItemType {Module, Gate, Net}; /** * Constructor. * - * @param id - The id of the module this item represents + * @param id - The id of the netlist item this ModuleItem represents + * @param type - The type of the netlist item */ ModuleItem(const u32 id, const TreeItemType type = TreeItemType::Module); @@ -121,7 +125,7 @@ namespace hal const ModuleItem* constChild(int row) const; /** - * Gets the current amount of children of this ModuleItem + * Gets the current amount of children of this ModuleItem. * * @returns the amount of children */ @@ -143,21 +147,21 @@ namespace hal int row() const; /** - * Gets the name of the module this ModuleItem represents. + * Gets the name of the netlist item this ModuleItem represents. * - * @returns the modules name + * @returns the netlist items name */ QString name() const; /** - * Gets the id of the module this ModuleItem represents. + * Gets the id of the netlist item this ModuleItem represents. * * @returns the module id */ u32 id() const; /** - * Gets the color of the module this ModuleItem represents. + * Gets the color of the netlist item this ModuleItem represents. * * @returns the module color */ @@ -166,10 +170,17 @@ namespace hal /** * Checks if this ModuleItem is currently highlighted. * - * @returns true iff this ModuleItem is currently highlighted. + * @returns true if this ModuleItem is currently highlighted. */ bool highlighted() const; + /** + * Gets the type of the netlist item this ModuleItem represents. + * + * @returns the ModuleItem type + */ + TreeItemType getType() const; + /** * Sets the parent ModuleItem of this ModuleItem. * @@ -182,7 +193,7 @@ namespace hal * * @param name - The new name */ - void set_name(const QString& name); + void setName(const QString& name); /** * Sets the color of the module this ModuleItem represents. @@ -201,7 +212,7 @@ namespace hal private: ModuleItem* mParent; - QList mChildItems; // memory leak? qDeleteAll() or mChildItems.clear()? in Destructor + QList mChildItems; u32 mId; TreeItemType mType; diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index c7e972552f6..f8d2bb56836 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -28,6 +28,7 @@ #include "hal_core/defines.h" #include "gui/gui_utils/sort.h" #include "hal_core/netlist/module.h" +#include "gui/module_model/module_item.h" #include #include @@ -116,7 +117,7 @@ namespace hal /** * Returns the data for the given role and section in the header with the specified orientation. - * Since the model has not headers, an empty QVariant is always returned. + * //Since the model has not headers, an empty QVariant is always returned. // REMOVE THIS LINE? * * @param section - The section * @param orientation - The orientation @@ -130,26 +131,27 @@ namespace hal /** * Returns the ModuleItem stored under the specified model index. * - * @param index - The model index to get the module item from + * @param index - The model index to get the ModuleItem from * @returns the module item at the specified index */ ModuleItem* getItem(const QModelIndex& index) const; /** - * Returns the module index where the specified ModuleItem can be found. + * Returns the index where the specified ModuleItem can be found. * - * @param item - The module item to search for in the item model + * @param item - The ModuleItem to search for in the item model * @returns the model index of the specified ModuleItem */ QModelIndex getIndex(const ModuleItem* const item) const; /** - * Returns the ModuleItem for a specified module id. + * Returns the ModuleItem for a specified id and type. * - * @param module_id - The id of the module to get the ModuleItem for - * @returns the ModuleItem with the id module_id + * @param module_id - The id of the ModuleItem + * @param type - The type of the ModuleItem + * @returns the ModuleItem with the specified id and type. */ - ModuleItem* getItem(const u32 module_id) const; + ModuleItem* getItem(const u32 id, ModuleItem::TreeItemType type = ModuleItem::TreeItemType::Module) const; /** * Initializes the item model using the global netlist object gNetlist. @@ -157,7 +159,7 @@ namespace hal void init(); /** - * Clears the item model. + * Clears the item model and deletes all ModuleItems. */ void clear(); @@ -170,21 +172,51 @@ namespace hal void addModule(const u32 id, const u32 parent_module); /** - * Recursively adds all given modules with all their sub modules (and their submodules and so on...) to - * the item model. + * Add a gate to the item model. For the specified gate a new ModuleItem is created and stored. + * + * @param id - The id of the gate to add. + * @param parent_module - The id of the parent module of the gate to add. + */ + void addGate(const u32 id, const u32 parent_module); + + /** + * Add a net to the item model. For the specified net a new ModuleItem is created and stored. + * + * @param id - The id of the net to add. + * @param parent_module - The id of the parent module of the net to add. + */ + void addNet(const u32 id, const u32 parent_module); + + /** + * Recursively adds all given modules with all their sub modules (and their submodules and so on...) + * and the gates and nets of those modules to the item model. * * @param modules - The list of modules which should be added to the item model together - * with all their submodules. + * with all their submodules, gates and nets. */ void addRecursively(const std::vector& modules); /** * Removes a module from the item model. The specified module MUST be contained in the item model. * - * @param id - The id of the model to remove + * @param id - The id of the module to remove */ void remove_module(const u32 id); + /** + * Removes a gate from the item model. The specified gate MUST be contained in the item model. + * + * @param id - The id of the gate to remove + */ + void remove_gate(const u32 id); + + /** + * Removes a net from the item model. The specified net MUST be contained in the item model. + * + * @param id - The id of the net to remove + */ + void remove_net(const u32 id); + /** * Updates the ModuleItem for the specified module. The specified module MUST be contained in the item model. * @@ -242,7 +274,10 @@ namespace hal private: ModuleItem* mTopModuleItem; - QMap mModuleItems; + QMap mModuleMap; + QMap mGateMap; + QMap mNetMap; + std::array*, 3> mModuleItemMaps = {&mModuleMap, &mGateMap, &mNetMap}; QMap mModuleColors; bool mIsModifying; diff --git a/plugins/gui/src/module_model/module_item.cpp b/plugins/gui/src/module_model/module_item.cpp index b15eb2beeed..a5aec2f5815 100644 --- a/plugins/gui/src/module_model/module_item.cpp +++ b/plugins/gui/src/module_model/module_item.cpp @@ -11,10 +11,22 @@ namespace hal mParent(nullptr), mId(id), mType(type), - mName(QString::fromStdString(gNetlist->get_module_by_id(id)->get_name())), - mColor(gNetlistRelay->getModuleColor(id)), mHighlighted(false) - {} + { + switch(type) + { + case TreeItemType::Module: + mName = QString::fromStdString(gNetlist->get_module_by_id(id)->get_name()); + mColor = gNetlistRelay->getModuleColor(id); + break; + case TreeItemType::Gate: + mName = QString::fromStdString(gNetlist->get_gate_by_id(id)->get_name()); + break; + case TreeItemType::Net: + mName = QString::fromStdString(gNetlist->get_net_by_id(id)->get_name()); + break; + } + } void ModuleItem::insertChild(int row, ModuleItem* child) { @@ -33,7 +45,7 @@ namespace hal void ModuleItem::appendExistingChildIfAny(const QMap& moduleMap) { - if(mType != TreeItemType::Module && mType != TreeItemType::Top) + if(mType != TreeItemType::Module) // only module can have children return; Module* m = gNetlist->get_module_by_id(mId); @@ -137,12 +149,16 @@ namespace hal return mHighlighted; } + ModuleItem::TreeItemType ModuleItem::getType() const{ + return mType; + } + void ModuleItem::setParent(ModuleItem* parent) { mParent = parent; } - void ModuleItem::set_name(const QString& name) + void ModuleItem::setName(const QString& name) { mName = name; } diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index a08386188e0..0fc40f96833 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -9,7 +9,6 @@ #include "hal_core/netlist/gate.h" #include "hal_core/netlist/net.h" - namespace hal { ModuleModel::ModuleModel(QObject* parent) : QAbstractItemModel(parent), mTopModuleItem(nullptr) @@ -120,9 +119,21 @@ namespace hal if (index.column() == 0) { QString runIconStyle = "all->" + item->color().name(); - QString runIconPath = ":/icons/filled-circle"; - - return gui_utility::getStyledSvgIcon(runIconStyle, runIconPath); + //QString runIconPath = ":/icons/filled-circle"; + QString moduleIconPath = ":/icons/ne_module"; + QString gateIconPath = ":/icons/ne_gate"; + QString netIconPath = ":/icons/ne_net"; + + switch(item->getType()){ + case ModuleItem::TreeItemType::Module: + return gui_utility::getStyledSvgIcon(runIconStyle, moduleIconPath); + case ModuleItem::TreeItemType::Gate: + runIconStyle = "all->" + item->parent()->color().name(); + return gui_utility::getStyledSvgIcon(runIconStyle, gateIconPath); + case ModuleItem::TreeItemType::Net: + runIconStyle = "all->" + item->parent()->color().name(); + return gui_utility::getStyledSvgIcon(runIconStyle, netIconPath); + } } break; } @@ -198,8 +209,7 @@ namespace hal { setModuleColor(1, QColor(96, 110, 112)); ModuleItem* item = new ModuleItem(1); - - mModuleItems.insert(1, item); + mModuleMap.insert(1, item); beginInsertRows(index(0, 0, QModelIndex()), 0, 0); mTopModuleItem = item; @@ -218,6 +228,11 @@ namespace hal // recursively insert modules Module* m = gNetlist->get_top_module(); addRecursively(m->get_submodules()); + // add remaining gates and modules + for(auto g : m->get_gates()) + addGate(g->get_id(), 1); + for(auto n: m->get_internal_nets()) + addNet(n->get_id(), 1); } void ModuleModel::clear() @@ -226,10 +241,16 @@ namespace hal mTopModuleItem = nullptr; - for (ModuleItem* m : mModuleItems) + for (ModuleItem* m : mModuleMap) delete m; - - mModuleItems.clear(); + for (ModuleItem* g : mGateMap) + delete g; + for (ModuleItem* n : mNetMap) + delete n; + + mModuleMap.clear(); + mGateMap.clear(); + mNetMap.clear(); mModuleColors.clear(); endResetModel(); @@ -239,15 +260,63 @@ namespace hal { assert(gNetlist->get_module_by_id(id)); assert(gNetlist->get_module_by_id(parent_module)); - assert(!mModuleItems.contains(id)); - assert(mModuleItems.contains(parent_module)); + assert(!mModuleMap.contains(id)); + assert(mModuleMap.contains(parent_module)); ModuleItem* item = new ModuleItem(id); - item->appendExistingChildIfAny(mModuleItems); - ModuleItem* parent = mModuleItems.value(parent_module); + item->appendExistingChildIfAny(mModuleMap); + ModuleItem* parent = mModuleMap.value(parent_module); + + item->setParent(parent); + mModuleMap.insert(id, item); + + QModelIndex index = getIndex(parent); + + int row = parent->childCount(); + mIsModifying = true; + beginInsertRows(index, row, row); + parent->insertChild(row, item); + mIsModifying = false; + endInsertRows(); + } + + void ModuleModel::addGate(u32 id, u32 parent_module) + { + assert(gNetlist->get_gate_by_id(id)); + assert(gNetlist->get_module_by_id(parent_module)); + assert(!mGateMap.contains(id)); + assert(mModuleMap.contains(parent_module)); + ModuleItem* item = new ModuleItem(id, ModuleItem::TreeItemType::Gate); + //item->appendExistingChildIfAny(mModuleMap); + ModuleItem* parent = mModuleMap.value(parent_module); item->setParent(parent); - mModuleItems.insert(id, item); + mGateMap.insert(id, item); + + QModelIndex index = getIndex(parent); + + int row = parent->childCount(); + mIsModifying = true; + beginInsertRows(index, row, row); + parent->insertChild(row, item); + mIsModifying = false; + endInsertRows(); + } + + + void ModuleModel::addNet(u32 id, u32 parent_module) + { + assert(gNetlist->get_net_by_id(id)); + assert(gNetlist->get_module_by_id(parent_module)); + assert(!mNetMap.contains(id)); + assert(mModuleMap.contains(parent_module)); + + ModuleItem* item = new ModuleItem(id, ModuleItem::TreeItemType::Net); + //item->appendExistingChildIfAny(mModuleMap); + ModuleItem* parent = mModuleMap.value(parent_module); + + item->setParent(parent); + mNetMap.insert(id, item); QModelIndex index = getIndex(parent); @@ -265,6 +334,11 @@ namespace hal { addModule(m->get_id(), m->get_parent_module()->get_id()); addRecursively(m->get_submodules()); + + for(auto &g : m->get_gates()) + addGate(g->get_id(), m->get_id()); + for(auto &n : m->get_internal_nets()) + addNet(n->get_id(), m->get_id()); } } @@ -272,9 +346,57 @@ namespace hal { assert(id != 1); assert(gNetlist->get_module_by_id(id)); - assert(mModuleItems.contains(id)); + assert(mModuleMap.contains(id)); + + ModuleItem* item = mModuleMap.value(id); + ModuleItem* parent = item->parent(); + assert(item); + assert(parent); + + QModelIndex index = getIndex(parent); + + int row = item->row(); + + mIsModifying = true; + beginRemoveRows(index, row, row); + parent->removeChild(item); + mIsModifying = false; + endRemoveRows(); + + mModuleMap.remove(id); + delete item; + } + + void ModuleModel::remove_gate(const u32 id) + { + assert(gNetlist->get_gate_by_id(id)); + assert(mGateMap.contains(id)); + + ModuleItem* item = mGateMap.value(id); + ModuleItem* parent = item->parent(); + assert(item); + assert(parent); + + QModelIndex index = getIndex(parent); + + int row = item->row(); + + mIsModifying = true; + beginRemoveRows(index, row, row); + parent->removeChild(item); + mIsModifying = false; + endRemoveRows(); + + mGateMap.remove(id); + delete item; + } + + void ModuleModel::remove_net(const u32 id) + { + assert(gNetlist->get_net_by_id(id)); + assert(mModuleMap.contains(id)); - ModuleItem* item = mModuleItems.value(id); + ModuleItem* item = mNetMap.value(id); ModuleItem* parent = item->parent(); assert(item); assert(parent); @@ -289,28 +411,28 @@ namespace hal mIsModifying = false; endRemoveRows(); - mModuleItems.remove(id); + mNetMap.remove(id); delete item; } void ModuleModel::updateModule(u32 id) // SPLIT ??? { assert(gNetlist->get_module_by_id(id)); - assert(mModuleItems.contains(id)); + assert(mModuleMap.contains(id)); - ModuleItem* item = mModuleItems.value(id); + ModuleItem* item = mModuleMap.value(id); assert(item); - item->set_name(QString::fromStdString(gNetlist->get_module_by_id(id)->get_name())); // REMOVE & ADD AGAIN + item->setName(QString::fromStdString(gNetlist->get_module_by_id(id)->get_name())); // REMOVE & ADD AGAIN item->setColor(gNetlistRelay->getModuleColor(id)); QModelIndex index = getIndex(item); Q_EMIT dataChanged(index, index); } - ModuleItem* ModuleModel::getItem(u32 module_id) const + ModuleItem* ModuleModel::getItem(u32 id, ModuleItem::TreeItemType type) const { - return mModuleItems.value(module_id); + return mModuleItemMaps[(int)type]->value(id); } QColor ModuleModel::moduleColor(u32 id) const From e69c13745e524115dfcd820b711f00b200056928 Mon Sep 17 00:00:00 2001 From: Skaleee Date: Fri, 14 Jul 2023 19:17:35 +0200 Subject: [PATCH 07/36] Fixed crash when clicking element in ModuleWidget. Also nets are now added only once to the ModuleModel. --- .../include/gui/module_model/module_model.h | 2 +- plugins/gui/src/module_model/module_model.cpp | 22 ++++++++++++++----- .../gui/src/module_widget/module_widget.cpp | 9 ++++++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index f8d2bb56836..829b95fbadc 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -194,7 +194,7 @@ namespace hal * @param modules - The list of modules which should be added to the item model together * with all their submodules, gates and nets. */ - void addRecursively(const std::vector& modules); + void addRecursively(const std::vector& modules, QSet& added_nets); /** * Removes a module from the item model. The specified module MUST be contained in the item model. diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 0fc40f96833..7bc9e6d82be 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -227,12 +227,17 @@ namespace hal // recursively insert modules Module* m = gNetlist->get_top_module(); - addRecursively(m->get_submodules()); + QSet added_nets; + addRecursively(m->get_submodules(), added_nets); // add remaining gates and modules for(auto g : m->get_gates()) addGate(g->get_id(), 1); - for(auto n: m->get_internal_nets()) - addNet(n->get_id(), 1); + for(auto n : m->get_internal_nets()){ + int size = added_nets.size(); + added_nets.insert(n->get_id()); + if(added_nets.size() > size) + addNet(n->get_id(), m->get_id()); + } } void ModuleModel::clear() @@ -328,17 +333,22 @@ namespace hal endInsertRows(); } - void ModuleModel::addRecursively(const std::vector& modules) + void ModuleModel::addRecursively(const std::vector& modules, QSet& added_nets) { for (auto &m : modules) { addModule(m->get_id(), m->get_parent_module()->get_id()); - addRecursively(m->get_submodules()); + addRecursively(m->get_submodules(), added_nets); for(auto &g : m->get_gates()) addGate(g->get_id(), m->get_id()); for(auto &n : m->get_internal_nets()) - addNet(n->get_id(), m->get_id()); + { + int size = added_nets.size(); + added_nets.insert(n->get_id()); + if(added_nets.size() > size) + addNet(n->get_id(), m->get_id()); + } } } diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index f8e6249fe20..42de43a3637 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -241,8 +241,13 @@ namespace hal for (const auto& index : current_selection) { - u32 module_id = getModuleItemFromIndex(index)->id(); - gSelectionRelay->addModule(module_id); + ModuleItem* mi = getModuleItemFromIndex(index); + if(mi->getType() == ModuleItem::TreeItemType::Module) + gSelectionRelay->addModule(mi->id()); + else if(mi->getType() == ModuleItem::TreeItemType::Gate) + gSelectionRelay->addGate(mi->id()); + else if(mi->getType() == ModuleItem::TreeItemType::Net) + gSelectionRelay->addNet(mi->id()); } if (current_selection.size() == 1) From 5e2e9d15d9d12a50aec7fc669ba1b7c207e1cdec Mon Sep 17 00:00:00 2001 From: Skaleee Date: Sat, 15 Jul 2023 20:02:46 +0200 Subject: [PATCH 08/36] use SelectionDetailsProvider::getIcon() instead of getStyledSvgIcon() --- plugins/gui/src/module_model/module_model.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 7bc9e6d82be..870e337f998 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -5,6 +5,7 @@ #include "gui/gui_globals.h" #include "gui/gui_utils/graphics.h" //#include "gui/ModuleModel/ModuleItem.h" +#include "gui/selection_details_widget/selection_details_icon_provider.h" #include "hal_core/netlist/gate.h" #include "hal_core/netlist/net.h" @@ -118,21 +119,13 @@ namespace hal { if (index.column() == 0) { - QString runIconStyle = "all->" + item->color().name(); - //QString runIconPath = ":/icons/filled-circle"; - QString moduleIconPath = ":/icons/ne_module"; - QString gateIconPath = ":/icons/ne_gate"; - QString netIconPath = ":/icons/ne_net"; - switch(item->getType()){ case ModuleItem::TreeItemType::Module: - return gui_utility::getStyledSvgIcon(runIconStyle, moduleIconPath); + return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::ModuleIcon, item->id())); case ModuleItem::TreeItemType::Gate: - runIconStyle = "all->" + item->parent()->color().name(); - return gui_utility::getStyledSvgIcon(runIconStyle, gateIconPath); + return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::GateIcon, item->id())); case ModuleItem::TreeItemType::Net: - runIconStyle = "all->" + item->parent()->color().name(); - return gui_utility::getStyledSvgIcon(runIconStyle, netIconPath); + return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::NetIcon, item->id())); } } break; From 84c95228553e0c061d6caaf318286c91e775f78b Mon Sep 17 00:00:00 2001 From: Skaleee Date: Sun, 16 Jul 2023 16:53:25 +0200 Subject: [PATCH 09/36] Visibility of nets and gates can now be toggled. Also added sorting by type. --- .../gui/module_model/module_proxy_model.h | 10 +++-- .../src/module_model/module_proxy_model.cpp | 39 ++++++++++++------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_proxy_model.h b/plugins/gui/include/gui/module_model/module_proxy_model.h index e8317727f33..7954fe021a1 100644 --- a/plugins/gui/include/gui/module_model/module_proxy_model.h +++ b/plugins/gui/include/gui/module_model/module_proxy_model.h @@ -65,13 +65,13 @@ namespace hal void setSortMechanism(gui_utility::mSortMechanism sortMechanism); /** - * Toggles whether or not nets are accepted by the filter. NOT YET ACTUALLY IMPLEMENTED + * Toggles whether or not nets are accepted by the filter. * @returns true if nets are filtered out now. false if not. */ bool toggleFilterNets(); /** - * Toggles whether or not gates are accepted by the filter. NOT YET ACTUALLY IMPLEMENTED + * Toggles whether or not gates are accepted by the filter. * @returns true if gates are filtered out now. false if not. */ bool toggleFilterGates(); @@ -79,7 +79,8 @@ namespace hal protected: /** * Overrides QSortFilterProxyModel::filterAcceptsRow to implement the filter logic based on the regular - * expression stored by setFilterRegularExpression.
+ * expression stored by setFilterRegularExpression. Also filters nets or gates, depending on the state + * of the toggle buttons.
* Returns true if the item in the row indicated by sourceRow and sourceParent should be included * in the model. * TODO: Filtering seems to be broken. Can't search for submodules. Works only for the topmodule. @@ -91,7 +92,8 @@ namespace hal bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override; /** - * Implements a comparison operator used for sorting. In this case it is based on the module names. + * Implements a comparison operator used for sorting. + * In this case it is based on the ModuleItem names and types. * * @param source_left - The model index of the left element * @param source_right - The model index of the right element diff --git a/plugins/gui/src/module_model/module_proxy_model.cpp b/plugins/gui/src/module_model/module_proxy_model.cpp index 3783b04317b..cddf8ae44fa 100644 --- a/plugins/gui/src/module_model/module_proxy_model.cpp +++ b/plugins/gui/src/module_model/module_proxy_model.cpp @@ -30,30 +30,39 @@ namespace hal bool ModuleProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { + QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent); + if(!sourceIndex.isValid()) + return true; + auto item = static_cast(sourceIndex.internalPointer()); + + if(mFilterGates && item->getType() == ModuleItem::TreeItemType::Gate) + return false; + if(mFilterNets && item->getType() == ModuleItem::TreeItemType::Net) + return false; + if(filterRegularExpression().pattern().isEmpty()) return true; - QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent); - if(sourceIndex.isValid()) + if(item->childCount() == 0) + return sourceModel()->data(sourceIndex, filterRole()).toString().contains(filterRegularExpression()); + + bool shouldBeDisplayed = sourceModel()->data(sourceIndex, filterRole()).toString().contains(filterRegularExpression());; + //go through all children and return the check of itself and the check of the children + for(int i = 0; i < item->childCount(); i++) { - auto item = static_cast(sourceIndex.internalPointer()); - if(item->childCount() == 0) - return sourceModel()->data(sourceIndex, filterRole()).toString().contains(filterRegularExpression()); - - bool shouldBeDisplayed = sourceModel()->data(sourceIndex, filterRole()).toString().contains(filterRegularExpression());; - //go through all children and return the check of itself and the check of the children - for(int i = 0; i < item->childCount(); i++) - { - shouldBeDisplayed = shouldBeDisplayed || filterAcceptsRow(i, sourceIndex); - } - - return shouldBeDisplayed; + shouldBeDisplayed = shouldBeDisplayed || filterAcceptsRow(i, sourceIndex); } - return true; + + return shouldBeDisplayed; } bool ModuleProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { + ModuleItem* item_left = static_cast(source_left.internalPointer()); + ModuleItem* item_right = static_cast(source_right.internalPointer()); + if(item_left->getType() != item_right->getType()) + return item_left->getType() < item_right->getType(); + QString name_left = source_left.data().toString(); QString name_right = source_right.data().toString(); if (sortCaseSensitivity() == Qt::CaseInsensitive) From 528b3e8f58bf28717f12ef729fa4e8a0d059b3b1 Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 18 Jul 2023 15:27:26 +0200 Subject: [PATCH 10/36] WIP: Use PortTreeItem instead of BaseTreeItem --- .../module_details_widget/port_tree_model.h | 18 ++++++------- .../module_ports_tree.cpp | 4 +-- .../module_details_widget/port_tree_model.cpp | 26 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h index b94d2a47d22..5167f9bfc48 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h @@ -45,7 +45,7 @@ namespace hal QString mNetName; public: - PortTreeItem(QString pinName, QString pinDirection, QString pinTypee, QString netName); + PortTreeItem(QString pinName, QString pinDirection, QString pinType, QString netName); PortTreeItem(); QVariant getData(int column) const override; void setData(QList data) override; @@ -106,7 +106,7 @@ namespace hal * @param item - The (port) item. * @return The net or nullptr. */ - Net* getNetFromItem(BaseTreeItem* item); + Net* getNetFromItem(PortTreeItem* item); /** * Get the id of the module that is currently represented. @@ -122,7 +122,7 @@ namespace hal * @param item - The item for which the type is requested. * @return The item's type. */ - itemType getTypeOfItem(BaseTreeItem* item) const; + itemType getTypeOfItem(PortTreeItem* item) const; /** * Returns the pin-id if the item represents a pin or the pingroup-id @@ -167,15 +167,15 @@ namespace hal QMap mIdToGroupItem; bool mIgnoreEventsFlag; - void insertItem(BaseTreeItem* item, BaseTreeItem* parent, int index); - void removeItem(BaseTreeItem* item); + void insertItem(PortTreeItem* item, BaseTreeItem* parent, int index); + void removeItem(PortTreeItem* item); // helper functions for dnd for more clarity void dndGroupOnGroup(BaseTreeItem* droppedGroup, BaseTreeItem* onDroppedGroup); - void dndGroupBetweenGroup(BaseTreeItem* droppedGroup, int row); - void dndPinOnGroup(BaseTreeItem* droppedPin, BaseTreeItem* onDroppedGroup); - void dndPinBetweenPin(BaseTreeItem* droppedPin, BaseTreeItem* onDroppedParent, int row); - void dndPinBetweenGroup(BaseTreeItem* droppedPin, int row); + void dndGroupBetweenGroup(PortTreeItem* droppedGroup, int row); + void dndPinOnGroup(PortTreeItem* droppedPin, BaseTreeItem* onDroppedGroup); + void dndPinBetweenPin(PortTreeItem* droppedPin, BaseTreeItem* onDroppedParent, int row); + void dndPinBetweenGroup(PortTreeItem* droppedPin, int row); }; } diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp index b23592b3940..c4c34d3d2a2 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp @@ -87,7 +87,7 @@ namespace hal return; //all relevant information - BaseTreeItem* clickedItem = mPortModel->getItemFromIndex(clickedIndex); + PortTreeItem* clickedItem = static_cast(mPortModel->getItemFromIndex(clickedIndex)); ModulePinsTreeModel::itemType type = mPortModel->getTypeOfItem(clickedItem); Net* n = mPortModel->getNetFromItem(clickedItem); QString name = clickedItem->getData(ModulePinsTreeModel::sNameColumn).toString(); @@ -308,7 +308,7 @@ namespace hal int groupId = -1; for (auto index : selectionModel()->selectedRows()) { - BaseTreeItem* item = mPortModel->getItemFromIndex(index); + PortTreeItem* item = static_cast(mPortModel->getItemFromIndex(index)); auto itemType = mPortModel->getTypeOfItem(item); if (itemType == ModulePinsTreeModel::itemType::pin) { diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp index b9368a2d143..4f59d385de0 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp @@ -144,7 +144,7 @@ namespace hal return new QMimeData(); QMimeData* data = new QMimeData(); - auto item = getItemFromIndex(indexes.at(0)); + auto item = static_cast(getItemFromIndex(indexes.at(0))); QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); QString type = getTypeOfItem(item) == itemType::pin ? "pin" : "group"; @@ -164,7 +164,7 @@ namespace hal QDataStream dataStream(&encItem, QIODevice::ReadOnly); dataStream >> type >> id; - auto droppedItem = (type == "group") ? mIdToGroupItem.value(id) : mIdToPinItem.value(id); + auto droppedItem = (type == "group") ? static_cast(mIdToGroupItem.value(id)) : static_cast(mIdToPinItem.value(id)); //auto droppedParentItem = droppedItem->getParent(); auto parentItem = getItemFromIndex(parent); @@ -344,7 +344,7 @@ namespace hal auto encItem = data->data("pintreemodel/item"); QDataStream dataStream(&encItem, QIODevice::ReadOnly); dataStream >> type >> id; - auto parentItem = getItemFromIndex(parent); + auto parentItem = static_cast(getItemFromIndex(parent)); qDebug() << "type: " << type << ", id" << id << ", row: " << row; // construct a "drop-matrix" here, but only 4(5) things are NOT allowed (so check for these): @@ -487,7 +487,7 @@ namespace hal Q_EMIT numberOfPortsChanged(m->get_pins().size()); } - Net* ModulePinsTreeModel::getNetFromItem(BaseTreeItem* item) + Net* ModulePinsTreeModel::getNetFromItem(PortTreeItem* item) { if (mModuleId == -1) //no current module = no represented net return nullptr; @@ -514,7 +514,7 @@ namespace hal return mModuleId; } - ModulePinsTreeModel::itemType ModulePinsTreeModel::getTypeOfItem(BaseTreeItem* item) const + ModulePinsTreeModel::itemType ModulePinsTreeModel::getTypeOfItem(PortTreeItem* item) const { return item->getAdditionalData(keyType).value(); } @@ -562,7 +562,7 @@ namespace hal } - void ModulePinsTreeModel::dndGroupBetweenGroup(BaseTreeItem *droppedGroup, int row) + void ModulePinsTreeModel::dndGroupBetweenGroup(PortTreeItem *droppedGroup, int row) { mIgnoreEventsFlag = true; int ownRow = droppedGroup->getOwnRow(); @@ -581,7 +581,7 @@ namespace hal mIgnoreEventsFlag = false; } - void ModulePinsTreeModel::dndPinOnGroup(BaseTreeItem *droppedPin, BaseTreeItem *onDroppedGroup) + void ModulePinsTreeModel::dndPinOnGroup(PortTreeItem *droppedPin, BaseTreeItem *onDroppedGroup) { mIgnoreEventsFlag = true; QSet e; @@ -593,14 +593,14 @@ namespace hal removeItem(droppedPin); insertItem(droppedPin, onDroppedGroup, onDroppedGroup->getChildCount()); if(!(oldParent->getChildCount())){ - removeItem(oldParent); + removeItem(static_cast(oldParent)); delete oldParent; } //setModule(mModule); mIgnoreEventsFlag = false; } - void ModulePinsTreeModel::dndPinBetweenPin(BaseTreeItem *droppedPin, BaseTreeItem *onDroppedParent, int row) + void ModulePinsTreeModel::dndPinBetweenPin(PortTreeItem *droppedPin, BaseTreeItem *onDroppedParent, int row) { mIgnoreEventsFlag = true; int desiredIdx = row; @@ -637,14 +637,14 @@ namespace hal removeItem(droppedPin); insertItem(droppedPin, onDroppedParent, desiredIdx); if(!(oldParent->getChildCount())){ - removeItem(oldParent); + removeItem(static_cast(oldParent)); delete oldParent; } //setModule(mModule); mIgnoreEventsFlag = false; } - void ModulePinsTreeModel::dndPinBetweenGroup(BaseTreeItem *droppedPin, int row) + void ModulePinsTreeModel::dndPinBetweenGroup(PortTreeItem *droppedPin, int row) { // row is needed for when groups can change its order within the module Q_UNUSED(row) @@ -682,7 +682,7 @@ namespace hal mIgnoreEventsFlag = false; } - void ModulePinsTreeModel::insertItem(BaseTreeItem* item, BaseTreeItem* parent, int index) + void ModulePinsTreeModel::insertItem(PortTreeItem* item, BaseTreeItem* parent, int index) { // fun fact: if an item is inserted above an item that is expanded, the tree collapses all indeces beginInsertRows(getIndexFromItem(parent), index, index); @@ -692,7 +692,7 @@ namespace hal getTypeOfItem(item) == itemType::pin ? mIdToPinItem.insert(getIdOfItem(item), item) : mIdToGroupItem.insert(getIdOfItem(item), item); //mIdToPinItem.insert(getIdOfItem(item), item); } - void ModulePinsTreeModel::removeItem(BaseTreeItem* item) + void ModulePinsTreeModel::removeItem(PortTreeItem* item) { beginRemoveRows(parent(getIndexFromItem(item)), item->getOwnRow(), item->getOwnRow()); item->getParent()->removeChild(item); From ddbbd142cdccff441b74893e82d1f1b3963d6f0e Mon Sep 17 00:00:00 2001 From: joern274 Date: Tue, 18 Jul 2023 20:39:06 +0200 Subject: [PATCH 11/36] PortTreeItem constructor implemented --- .../module_details_widget/port_tree_model.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp index 4f59d385de0..02d7878975f 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp @@ -20,9 +20,8 @@ namespace hal { PortTreeItem::PortTreeItem(QString pinName, QString pinDirection, QString pinTypee, QString netName) - { - - } + : mPinName(pinName), mPinDirection(pinDirection), mPinType(pinTypee), mNetName(netName) + {;} QVariant PortTreeItem::getData(int index) const { From e7ded8208a320072ce375d991e41f4e803a02469 Mon Sep 17 00:00:00 2001 From: Skaleee Date: Thu, 20 Jul 2023 19:49:45 +0200 Subject: [PATCH 12/36] Try to fix github build test for mac. --- plugins/gui/include/gui/module_model/module_model.h | 2 +- plugins/gui/src/module_model/module_model.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index 829b95fbadc..18f9240d57a 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -277,7 +277,7 @@ namespace hal QMap mModuleMap; QMap mGateMap; QMap mNetMap; - std::array*, 3> mModuleItemMaps = {&mModuleMap, &mGateMap, &mNetMap}; + std::array*, 3> mModuleItemMaps; QMap mModuleColors; bool mIsModifying; diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 870e337f998..316e712522d 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -14,6 +14,7 @@ namespace hal { ModuleModel::ModuleModel(QObject* parent) : QAbstractItemModel(parent), mTopModuleItem(nullptr) { + mModuleItemMaps = {&mModuleMap, &mGateMap, &mNetMap}; } QModelIndex ModuleModel::index(int row, int column, const QModelIndex& parent) const From b26ca38ae29e30b3567ce6fb4eff37522e0f566b Mon Sep 17 00:00:00 2001 From: Skaleee Date: Thu, 20 Jul 2023 20:20:19 +0200 Subject: [PATCH 13/36] Try fixing again. --- plugins/gui/include/gui/module_model/module_model.h | 3 ++- plugins/gui/src/module_model/module_model.cpp | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index 18f9240d57a..e455d464143 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -35,6 +35,7 @@ #include #include #include +#include namespace hal { @@ -277,7 +278,7 @@ namespace hal QMap mModuleMap; QMap mGateMap; QMap mNetMap; - std::array*, 3> mModuleItemMaps; + std::array*, 3> mModuleItemMaps = {&mModuleMap, &mGateMap, &mNetMap};; QMap mModuleColors; bool mIsModifying; diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 316e712522d..870e337f998 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -14,7 +14,6 @@ namespace hal { ModuleModel::ModuleModel(QObject* parent) : QAbstractItemModel(parent), mTopModuleItem(nullptr) { - mModuleItemMaps = {&mModuleMap, &mGateMap, &mNetMap}; } QModelIndex ModuleModel::index(int row, int column, const QModelIndex& parent) const From cbd879c279b5bd999943614dc7f23207bd15fa07 Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 10 Oct 2023 11:46:19 +0200 Subject: [PATCH 14/36] fix the context menu for gates and nets in the module widget --- .../include/gui/module_widget/module_widget.h | 5 + .../gui/src/module_widget/module_widget.cpp | 121 +++++++++++++++--- 2 files changed, 108 insertions(+), 18 deletions(-) diff --git a/plugins/gui/include/gui/module_widget/module_widget.h b/plugins/gui/include/gui/module_widget/module_widget.h index 12ae81450b3..f52387597a9 100644 --- a/plugins/gui/include/gui/module_widget/module_widget.h +++ b/plugins/gui/include/gui/module_widget/module_widget.h @@ -244,6 +244,11 @@ namespace hal void openModuleInView(const QModelIndex& index); + void openGateInView(const QModelIndex& index); + + void changeGateName(const QModelIndex& index); + + ModuleItem* getModuleItemFromIndex(const QModelIndex& index); }; diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index cf466cc653c..fa257287f64 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -10,6 +10,7 @@ #include "gui/user_action/action_create_object.h" #include "gui/user_action/action_unfold_module.h" #include "gui/user_action/user_action_compound.h" +#include "gui/user_action/action_rename_object.h" #include "hal_core/netlist/gate.h" #include "hal_core/netlist/module.h" #include "hal_core/netlist/net.h" @@ -25,6 +26,7 @@ #include #include #include +#include namespace hal { @@ -172,27 +174,73 @@ namespace hal if (!index.isValid()) return; + ModuleItem::TreeItemType type = getModuleItemFromIndex(index)->getType(); + QMenu context_menu; - QAction isolate_action("Isolate in new view", &context_menu); - QAction add_selection_action("Add selected gates to module", &context_menu); - QAction add_child_action("Add child module", &context_menu); - QAction change_name_action("Change module name", &context_menu); - QAction change_type_action("Change module type", &context_menu); - QAction change_color_action("Change module color", &context_menu); - QAction delete_action("Delete module", &context_menu); - - context_menu.addAction(&isolate_action); - context_menu.addAction(&add_selection_action); - context_menu.addAction(&add_child_action); - context_menu.addAction(&change_name_action); - context_menu.addAction(&change_type_action); - context_menu.addAction(&change_color_action); + QAction isolate_action; + QAction add_selection_action; + QAction add_child_action; + QAction change_name_action; + QAction change_type_action; + QAction change_color_action; + QAction delete_action; + + switch(type) { + + case ModuleItem::TreeItemType::Module:{ + isolate_action.setText("Isolate in new view"); + isolate_action.setParent(&context_menu); + + add_selection_action.setText("Add selected gates to module"); + add_selection_action.setParent(&context_menu); + + add_child_action.setText("Add child module"); + add_child_action.setParent(&context_menu); + + change_name_action.setText("Change module name"); + change_name_action.setParent(&context_menu); + + change_type_action.setText("Change module type"); + change_type_action.setParent(&context_menu); + + change_color_action.setText("Change module color"); + change_color_action.setParent(&context_menu); + + delete_action.setText("Delete module"); + delete_action.setParent(&context_menu); + break; + } + case ModuleItem::TreeItemType::Gate: { + isolate_action.setText("Isolate in new view"); + isolate_action.setParent(&context_menu); + + change_name_action.setText("Change Gate name"); + change_name_action.setParent(&context_menu); + break; + } + case ModuleItem::TreeItemType::Net: { + return; + } + } + + if (type == ModuleItem::TreeItemType::Gate || type == ModuleItem::TreeItemType::Module){ + context_menu.addAction(&isolate_action); + context_menu.addAction(&change_name_action); + + } + + if (type == ModuleItem::TreeItemType::Module){ + context_menu.addAction(&add_selection_action); + context_menu.addAction(&add_child_action); + context_menu.addAction(&change_type_action); + context_menu.addAction(&change_color_action); + } u32 module_id = getModuleItemFromIndex(index)->id(); auto module = gNetlist->get_module_by_id(module_id); - if(!(module == gNetlist->get_top_module())) + if(!(module == gNetlist->get_top_module()) && type == ModuleItem::TreeItemType::Module) context_menu.addAction(&delete_action); QAction* clicked = context_menu.exec(mTreeView->viewport()->mapToGlobal(point)); @@ -200,7 +248,9 @@ namespace hal if (!clicked) return; - if (clicked == &isolate_action) + if (clicked == &isolate_action && type == ModuleItem::TreeItemType::Gate) + openGateInView(index); + else if (clicked == &isolate_action) openModuleInView(index); if (clicked == &add_selection_action) @@ -212,7 +262,9 @@ namespace hal mTreeView->setExpanded(index, true); } - if (clicked == &change_name_action) + if (clicked == &change_name_action && type == ModuleItem::TreeItemType::Gate) + changeGateName(index); + else if (clicked == &change_name_action) gNetlistRelay->changeModuleName(getModuleItemFromIndex(index)->id()); if (clicked == &change_type_action) @@ -221,8 +273,10 @@ namespace hal if (clicked == &change_color_action) gNetlistRelay->changeModuleColor(getModuleItemFromIndex(index)->id()); - if (clicked == &delete_action) + if (clicked == &delete_action){ gNetlistRelay->deleteModule(getModuleItemFromIndex(index)->id()); + } + } void ModuleWidget::handleModuleRemoved(Module* module, u32 module_id) @@ -278,6 +332,37 @@ namespace hal openModuleInView(getModuleItemFromIndex(index)->id(), false); } + void ModuleWidget::openGateInView(const QModelIndex &index) + { + QSet gateId; + QSet moduleId; + QString name; + + name = gGraphContextManager->nextViewName("Isolated View"); + gateId.insert(getModuleItemFromIndex(index)->id()); + + UserActionCompound* act = new UserActionCompound; + act->setUseCreatedObject(); + act->addAction(new ActionCreateObject(UserActionObjectType::Context, name)); + act->addAction(new ActionAddItemsToObject(moduleId, gateId)); + act->exec(); + } + + void ModuleWidget::changeGateName(const QModelIndex &index) + { + QString oldName = getModuleItemFromIndex(index)->name(); + + bool confirm; + QString newName = QInputDialog::getText(this, "Change gate name", "New name:", QLineEdit::Normal, oldName, &confirm); + + if (confirm && !newName.isEmpty()) + { + ActionRenameObject* act = new ActionRenameObject(newName); + act->setObject(UserActionObject(getModuleItemFromIndex(index)->id(), UserActionObjectType::ObjectType::Gate)); + act->exec(); + } + } + void ModuleWidget::openModuleInView(u32 moduleId, bool unfold) { const Module* module = gNetlist->get_module_by_id(moduleId); From 9b2395bc6591b9909babae427b8cfe926f3ffb1e Mon Sep 17 00:00:00 2001 From: Skaleee Date: Sat, 14 Oct 2023 23:23:52 +0200 Subject: [PATCH 15/36] Relayed create/delete events for Gates/Modules to ModuleModel --- .../include/gui/module_model/module_model.h | 18 ++++- plugins/gui/src/module_model/module_model.cpp | 79 +++++++++++-------- .../gui/src/netlist_relay/netlist_relay.cpp | 12 ++- 3 files changed, 70 insertions(+), 39 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index e455d464143..e4ecbe1c309 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -189,13 +189,23 @@ namespace hal void addNet(const u32 id, const u32 parent_module); /** - * Recursively adds all given modules with all their sub modules (and their submodules and so on...) + * Recursively adds the given module with all of its submodules (and their submodules and so on...) * and the gates and nets of those modules to the item model. * - * @param modules - The list of modules which should be added to the item model together - * with all their submodules, gates and nets. + * @param module - The module which should be added to the item model together with all its + * submodules, gates and nets. + * @param added_nets - A set of ids of nets. It's used to keep track of the nets that have already been added + * to the item model during the recursion. You can pass an empty set to add all nets. */ - void addRecursively(const std::vector& modules, QSet& added_nets); + void addRecursively(const Module* module, QSet& added_nets); + + /** + * Updates the parent of the ModuleItem corresponding to the specified module. + * The new parent must already be set in the Module object. + * + * @param module - The module whose ModuleItem will be reattached to a new parent in the item model. + */ + void changeParentModule(const Module* module); /** * Removes a module from the item model. The specified module MUST be contained in the item model. diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 870e337f998..39027fa6ae1 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -221,16 +221,7 @@ namespace hal // recursively insert modules Module* m = gNetlist->get_top_module(); QSet added_nets; - addRecursively(m->get_submodules(), added_nets); - // add remaining gates and modules - for(auto g : m->get_gates()) - addGate(g->get_id(), 1); - for(auto n : m->get_internal_nets()){ - int size = added_nets.size(); - added_nets.insert(n->get_id()); - if(added_nets.size() > size) - addNet(n->get_id(), m->get_id()); - } + addRecursively(m, added_nets); } void ModuleModel::clear() @@ -262,18 +253,17 @@ namespace hal assert(mModuleMap.contains(parent_module)); ModuleItem* item = new ModuleItem(id); - item->appendExistingChildIfAny(mModuleMap); ModuleItem* parent = mModuleMap.value(parent_module); item->setParent(parent); mModuleMap.insert(id, item); QModelIndex index = getIndex(parent); - + int row = parent->childCount(); mIsModifying = true; beginInsertRows(index, row, row); - parent->insertChild(row, item); + parent->appendChild(item); mIsModifying = false; endInsertRows(); } @@ -284,8 +274,8 @@ namespace hal assert(gNetlist->get_module_by_id(parent_module)); assert(!mGateMap.contains(id)); assert(mModuleMap.contains(parent_module)); + ModuleItem* item = new ModuleItem(id, ModuleItem::TreeItemType::Gate); - //item->appendExistingChildIfAny(mModuleMap); ModuleItem* parent = mModuleMap.value(parent_module); item->setParent(parent); @@ -296,7 +286,7 @@ namespace hal int row = parent->childCount(); mIsModifying = true; beginInsertRows(index, row, row); - parent->insertChild(row, item); + parent->appendChild(item); mIsModifying = false; endInsertRows(); } @@ -310,7 +300,6 @@ namespace hal assert(mModuleMap.contains(parent_module)); ModuleItem* item = new ModuleItem(id, ModuleItem::TreeItemType::Net); - //item->appendExistingChildIfAny(mModuleMap); ModuleItem* parent = mModuleMap.value(parent_module); item->setParent(parent); @@ -321,28 +310,56 @@ namespace hal int row = parent->childCount(); mIsModifying = true; beginInsertRows(index, row, row); - parent->insertChild(row, item); + parent->appendChild(item); mIsModifying = false; endInsertRows(); } - void ModuleModel::addRecursively(const std::vector& modules, QSet& added_nets) + void ModuleModel::addRecursively(const Module* module, QSet& added_nets) { - for (auto &m : modules) + if(!module->is_top_module()) + addModule(module->get_id(), module->get_parent_module()->get_id()); + for(auto &m : module->get_submodules()) + addRecursively(m, added_nets); + + for(auto &g : module->get_gates()) + addGate(g->get_id(), module->get_id()); + for(auto &n : module->get_internal_nets()) { - addModule(m->get_id(), m->get_parent_module()->get_id()); - addRecursively(m->get_submodules(), added_nets); + int size = added_nets.size(); + added_nets.insert(n->get_id()); + if(added_nets.size() > size) + addNet(n->get_id(), module->get_id()); + } + } - for(auto &g : m->get_gates()) - addGate(g->get_id(), m->get_id()); - for(auto &n : m->get_internal_nets()) - { - int size = added_nets.size(); - added_nets.insert(n->get_id()); - if(added_nets.size() > size) - addNet(n->get_id(), m->get_id()); - } - } + void ModuleModel::changeParentModule(const Module* module){ + assert(module); + u32 id = module->get_id(); + assert(id != 1); + assert(mModuleMap.contains(id)); + ModuleItem* item = mModuleMap.value(id); + ModuleItem* oldParent = item->parent(); + assert(oldParent); + + assert(module->get_parent_module()); + if(oldParent->id() == module->get_parent_module()->get_id()) + return; + + assert(mModuleMap.contains(module->get_parent_module()->get_id())); + ModuleItem* newParent = mModuleMap.value(module->get_parent_module()->get_id()); + + QModelIndex oldIndex = getIndex(oldParent); + QModelIndex newIndex = getIndex(newParent); + int row = item->row(); + + mIsModifying = true; + beginMoveRows(oldIndex, row, row, newIndex, newParent->childCount()); + oldParent->removeChild(item); + newParent->appendChild(item); + item->setParent(newParent); + mIsModifying = false; + endMoveRows(); } void ModuleModel::remove_module(const u32 id) diff --git a/plugins/gui/src/netlist_relay/netlist_relay.cpp b/plugins/gui/src/netlist_relay/netlist_relay.cpp index 92655c372ae..bf7706168a4 100644 --- a/plugins/gui/src/netlist_relay/netlist_relay.cpp +++ b/plugins/gui/src/netlist_relay/netlist_relay.cpp @@ -376,6 +376,7 @@ namespace hal // suppress actions if we receive this for the top module if (mod->get_parent_module() != nullptr) { + mModuleModel->addModule(mod->get_id(), mod->get_parent_module()->get_id()); mModuleModel->setRandomColor(mod->get_id()); } @@ -388,6 +389,7 @@ namespace hal //< no associated_data mModuleModel->removeColor(mod->get_id()); + mModuleModel->remove_module(mod->get_id()); gGraphContextManager->handleModuleRemoved(mod); gSelectionRelay->handleModuleRemoved(mod->get_id()); @@ -408,14 +410,14 @@ namespace hal case ModuleEvent::event::parent_changed: { //< no associated_data + mModuleModel->changeParentModule(mod); + Q_EMIT moduleParentChanged(mod); break; } case ModuleEvent::event::submodule_added: { //< associated_data = id of added module - mModuleModel->addModule(associated_data, mod->get_id()); - gGraphContextManager->handleModuleSubmoduleAdded(mod, associated_data); Q_EMIT moduleSubmoduleAdded(mod, associated_data); @@ -424,8 +426,6 @@ namespace hal case ModuleEvent::event::submodule_removed: { //< associated_data = id of removed module - mModuleModel->remove_module(associated_data); - gGraphContextManager->handleModuleSubmoduleRemoved(mod, associated_data); Q_EMIT moduleSubmoduleRemoved(mod, associated_data); @@ -434,6 +434,8 @@ namespace hal case ModuleEvent::event::gate_assigned: { //< associated_data = id of inserted gate + mModuleModel->addGate(associated_data, mod->get_id()); + gGraphContextManager->handleModuleGateAssigned(mod, associated_data); Q_EMIT moduleGateAssigned(mod, associated_data); @@ -442,6 +444,8 @@ namespace hal case ModuleEvent::event::gate_removed: { //< associated_data = id of removed gate + mModuleModel->remove_gate(associated_data); + gGraphContextManager->handleModuleGateRemoved(mod, associated_data); Q_EMIT moduleGateRemoved(mod, associated_data); From 8569a3a4ea2d1330e631ef7e267904affb2da220 Mon Sep 17 00:00:00 2001 From: Skaleee <78816681+Skaleee@users.noreply.github.com> Date: Sun, 15 Oct 2023 21:27:21 +0200 Subject: [PATCH 16/36] FIx loading colors into ModuleModel --- .../gui/include/gui/module_model/module_item.h | 15 --------------- .../src/grouping/grouping_color_serializer.cpp | 4 +++- plugins/gui/src/module_model/module_item.cpp | 11 ----------- plugins/gui/src/module_model/module_model.cpp | 5 ++--- 4 files changed, 5 insertions(+), 30 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_item.h b/plugins/gui/include/gui/module_model/module_item.h index 579f6cc0579..f61ce42b727 100644 --- a/plugins/gui/include/gui/module_model/module_item.h +++ b/plugins/gui/include/gui/module_model/module_item.h @@ -160,13 +160,6 @@ namespace hal */ u32 id() const; - /** - * Gets the color of the netlist item this ModuleItem represents. - * - * @returns the module color - */ - QColor color() const; - /** * Checks if this ModuleItem is currently highlighted. * @@ -195,13 +188,6 @@ namespace hal */ void setName(const QString& name); - /** - * Sets the color of the module this ModuleItem represents. - * - * @param color - The new color - */ - void setColor(const QColor& color); - /** * Marks/Unmarks this ModuleItem as highlighted. * @@ -218,7 +204,6 @@ namespace hal TreeItemType mType; QString mName; - QColor mColor; bool mHighlighted; }; } diff --git a/plugins/gui/src/grouping/grouping_color_serializer.cpp b/plugins/gui/src/grouping/grouping_color_serializer.cpp index 097cf87d98c..fc6169d4f78 100644 --- a/plugins/gui/src/grouping/grouping_color_serializer.cpp +++ b/plugins/gui/src/grouping/grouping_color_serializer.cpp @@ -126,9 +126,11 @@ namespace hal { QModelIndex inx = mm->index(irow,0,parent); const ModuleItem* mItem = mm->getItem(inx); if (!mItem) continue; + if(mItem->getType() != ModuleItem::TreeItemType::Module) continue; + QJsonObject mcEntry; mcEntry["id"] = (int) mItem->id(); - mcEntry["color"] = mItem->color().name(QColor::HexArgb); + mcEntry["color"] = mm->moduleColor(mItem->id()).name(QColor::HexArgb); mcArr.append(mcEntry); serializeColorRecursion(mcArr,mm,inx); } diff --git a/plugins/gui/src/module_model/module_item.cpp b/plugins/gui/src/module_model/module_item.cpp index a5aec2f5815..ac4119dec11 100644 --- a/plugins/gui/src/module_model/module_item.cpp +++ b/plugins/gui/src/module_model/module_item.cpp @@ -17,7 +17,6 @@ namespace hal { case TreeItemType::Module: mName = QString::fromStdString(gNetlist->get_module_by_id(id)->get_name()); - mColor = gNetlistRelay->getModuleColor(id); break; case TreeItemType::Gate: mName = QString::fromStdString(gNetlist->get_gate_by_id(id)->get_name()); @@ -139,11 +138,6 @@ namespace hal return mId; } - QColor ModuleItem::color() const - { - return mColor; - } - bool ModuleItem::highlighted() const { return mHighlighted; @@ -163,11 +157,6 @@ namespace hal mName = name; } - void ModuleItem::setColor(const QColor& color) - { - mColor = color; - } - void ModuleItem::setHighlighted(const bool highlighted) { mHighlighted = highlighted; diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 39027fa6ae1..165600749cd 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -4,7 +4,7 @@ #include "gui/gui_globals.h" #include "gui/gui_utils/graphics.h" -//#include "gui/ModuleModel/ModuleItem.h" + #include "gui/selection_details_widget/selection_details_icon_provider.h" #include "hal_core/netlist/gate.h" @@ -121,7 +121,7 @@ namespace hal { switch(item->getType()){ case ModuleItem::TreeItemType::Module: - return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::ModuleIcon, item->id())); + return QIcon(gui_utility::getStyledSvgIcon("all->" + mModuleColors[item->id()].name(QColor::HexRgb), ":/icons/ne_module")); case ModuleItem::TreeItemType::Gate: return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::GateIcon, item->id())); case ModuleItem::TreeItemType::Net: @@ -444,7 +444,6 @@ namespace hal assert(item); item->setName(QString::fromStdString(gNetlist->get_module_by_id(id)->get_name())); // REMOVE & ADD AGAIN - item->setColor(gNetlistRelay->getModuleColor(id)); QModelIndex index = getIndex(item); Q_EMIT dataChanged(index, index); From 0a1c7346dc65577b44762d86bd16e9e2fa27c25b Mon Sep 17 00:00:00 2001 From: joern274 Date: Mon, 16 Oct 2023 12:46:33 +0200 Subject: [PATCH 17/36] Fix: color changed event should be emitted by model where color change occurs --- .../include/gui/module_model/module_model.h | 8 ++++ .../include/gui/netlist_relay/netlist_relay.h | 11 ----- .../module_details_tab_widget.h | 5 +++ .../selection_details_icon_provider.h | 12 +++++ plugins/gui/src/module_model/module_model.cpp | 1 + .../gui/src/netlist_relay/netlist_relay.cpp | 2 - .../module_details_tab_widget.cpp | 20 ++++++++- .../selection_details_icon_provider.cpp | 45 ++++++++++++++----- .../user_action/action_set_object_color.cpp | 4 +- 9 files changed, 79 insertions(+), 29 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index e4ecbe1c309..a360d5a96f5 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -51,6 +51,14 @@ namespace hal { Q_OBJECT + Q_SIGNALS: + /** + * Q_SIGNAL to notify that the color of a module has been changed. + * + * @param m - The module with the changed color + */ + void moduleColorChanged(u32 id) const; + public: /** * Constructor.
diff --git a/plugins/gui/include/gui/netlist_relay/netlist_relay.h b/plugins/gui/include/gui/netlist_relay/netlist_relay.h index 03a8bd3fb1b..2915e88f782 100644 --- a/plugins/gui/include/gui/netlist_relay/netlist_relay.h +++ b/plugins/gui/include/gui/netlist_relay/netlist_relay.h @@ -584,17 +584,6 @@ namespace hal */ void groupingModuleRemoved(Grouping* grp, u32 id) const; - /*======================================= - Other Signals - ========================================*/ - - /** - * Q_SIGNAL to notify that the color of a module has been changed. - * - * @param m - The module with the changed color - */ - void moduleColorChanged(Module* m) const; - public Q_SLOTS: /** * Q_SLOT to handle that a netlist has been opened. diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_tab_widget.h b/plugins/gui/include/gui/selection_details_widget/module_details_tab_widget.h index 108276203fa..e1d86d99dd8 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_tab_widget.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_tab_widget.h @@ -71,6 +71,9 @@ namespace hal */ void clear(); + private Q_SLOTS: + void handleModuleColorChanged(u32 id); + private: //general tab @@ -96,5 +99,7 @@ namespace hal //comment tab CommentWidget* mCommentWidget; + //store module id + u32 mModuleId; }; } diff --git a/plugins/gui/include/gui/selection_details_widget/selection_details_icon_provider.h b/plugins/gui/include/gui/selection_details_widget/selection_details_icon_provider.h index 2075ddb180a..b2cd0e2853e 100644 --- a/plugins/gui/include/gui/selection_details_widget/selection_details_icon_provider.h +++ b/plugins/gui/include/gui/selection_details_widget/selection_details_icon_provider.h @@ -31,6 +31,7 @@ #include #include #include +#include namespace hal { @@ -47,6 +48,7 @@ namespace hal private Q_SLOTS: void loadIcons(int istyle); + void handleModuleColorChanged(u32 id); private: QHash mDefaultIcons; QHash mGateIcons; @@ -58,5 +60,15 @@ namespace hal static SelectionDetailsIconProvider* instance(); static SettingsItemDropdown* sIconSizeSetting; }; + + class ModuleIconInstance : public QIcon + { + u32 mId; + friend class SelectionDetailsIconProvider; + static QHash sInstances; + public: + ModuleIconInstance(u32 id, const QIcon& icon); + ~ModuleIconInstance(); + }; } diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 165600749cd..6b2267ba9a1 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -463,6 +463,7 @@ namespace hal { QColor retval = mModuleColors.value(id); mModuleColors[id] = col; + Q_EMIT moduleColorChanged(id); return retval; } diff --git a/plugins/gui/src/netlist_relay/netlist_relay.cpp b/plugins/gui/src/netlist_relay/netlist_relay.cpp index bf7706168a4..cd622124d8d 100644 --- a/plugins/gui/src/netlist_relay/netlist_relay.cpp +++ b/plugins/gui/src/netlist_relay/netlist_relay.cpp @@ -140,8 +140,6 @@ namespace hal ActionSetObjectColor* act = new ActionSetObjectColor(color); act->setObject(UserActionObject(id, UserActionObjectType::Module)); act->exec(); - - Q_EMIT moduleColorChanged(m); } void NetlistRelay::addSelectionToModule(const u32 id) diff --git a/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp b/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp index 37fbd29284d..b64065bc2ff 100644 --- a/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp @@ -7,10 +7,13 @@ #include "gui/comment_system/widgets/comment_widget.h" #include "hal_core/netlist/module.h" +#include "gui/gui_globals.h" +#include "gui/module_model/module_model.h" namespace hal { - ModuleDetailsTabWidget::ModuleDetailsTabWidget(QWidget* parent) : DetailsTabWidget(parent) + ModuleDetailsTabWidget::ModuleDetailsTabWidget(QWidget* parent) + : DetailsTabWidget(parent), mModuleId(0) { setIcon(SelectionDetailsIconProvider::ModuleIcon); @@ -48,11 +51,24 @@ namespace hal mCommentWidget = new CommentWidget(this); QTabWidget::addTab(mCommentWidget, "Comments"); + connect(gNetlistRelay->getModuleModel(),&ModuleModel::moduleColorChanged,this,&ModuleDetailsTabWidget::handleModuleColorChanged); } + void ModuleDetailsTabWidget::handleModuleColorChanged(u32 id) + { + if (!mModuleId || mModuleId != id) return; + setIcon(SelectionDetailsIconProvider::ModuleIcon,mModuleId); + } + void ModuleDetailsTabWidget::setModule(Module* module) { - if (module) setIcon(SelectionDetailsIconProvider::ModuleIcon, module->get_id()); + if (module) + { + setIcon(SelectionDetailsIconProvider::ModuleIcon, module->get_id()); + mModuleId = module->get_id(); + } + else + mModuleId = 0; //pass module or other stuff to widgets mModuleInfoTable->setModule(module); mPinsTree->setModule(module); diff --git a/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp b/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp index a3bd1fddd1b..798734922de 100644 --- a/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp +++ b/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp @@ -3,6 +3,7 @@ #include "gui/gui_globals.h" #include "gui/main_window/main_window.h" #include "gui/settings/settings_items/settings_item_dropdown.h" +#include "gui/module_model/module_model.h" #include #include @@ -30,6 +31,7 @@ namespace hal SelectionDetailsIconProvider* SelectionDetailsIconProvider::instance() { + Q_ASSERT(gNetlistRelay); // make sure it does not get called before event relay is installed if (!inst) inst = new SelectionDetailsIconProvider(); return inst; } @@ -38,9 +40,19 @@ namespace hal : QObject(parent) { connect(MainWindow::sSettingStyle, &SettingsItemDropdown::intChanged,this,&SelectionDetailsIconProvider::loadIcons); + connect(gNetlistRelay->getModuleModel(),&ModuleModel::moduleColorChanged,this,&SelectionDetailsIconProvider::handleModuleColorChanged); loadIcons(MainWindow::sSettingStyle->value().toInt()); } + void SelectionDetailsIconProvider::handleModuleColorChanged(u32 id) + { + auto it = ModuleIconInstance::sInstances.find(id); + if (it == ModuleIconInstance::sInstances.end()) return; + delete it.value(); + QColor col = gNetlistRelay->getModuleColor(id); + new ModuleIconInstance(id,gui_utility::getStyledSvgIcon("all->" + col.name(QColor::HexRgb), ":/icons/ne_module")); + } + void SelectionDetailsIconProvider::loadIcons(int istyle) { MainWindow::StyleSheetOption theme = static_cast(istyle); @@ -75,7 +87,7 @@ namespace hal const QIcon* SelectionDetailsIconProvider::getIcon(IconCategory catg, u32 itemId) { Gate* g = nullptr; - Module* m = nullptr; + QColor col; switch (catg) { @@ -92,18 +104,14 @@ namespace hal } break; case ModuleIcon: - m = gNetlist->get_module_by_id(itemId); - if (m) + col = gNetlistRelay->getModuleColor(itemId); + if (col.isValid()) { - QColor col = gNetlistRelay->getModuleColor(itemId); - if (col.isValid()) - { - const QIcon* moduleColorIcon = mModuleIcons.value(m,nullptr); - if (moduleColorIcon) return moduleColorIcon; - moduleColorIcon = new QIcon(gui_utility::getStyledSvgIcon("all->" + col.name(QColor::HexRgb), ":/icons/ne_module")); - mModuleIcons.insert(m, moduleColorIcon); - return moduleColorIcon; - } + auto it = ModuleIconInstance::sInstances.find(itemId); + if (it != ModuleIconInstance::sInstances.end()) + return it.value(); + + return new ModuleIconInstance(itemId,gui_utility::getStyledSvgIcon("all->" + col.name(QColor::HexRgb), ":/icons/ne_module")); } break; default: @@ -111,4 +119,17 @@ namespace hal } return mDefaultIcons.value(catg); } + + QHash ModuleIconInstance::sInstances; + + ModuleIconInstance::ModuleIconInstance(u32 id, const QIcon &icon) + : QIcon(icon), mId(id) + { + sInstances[mId] = this; + } + + ModuleIconInstance::~ModuleIconInstance() + { + sInstances.remove(mId); + } } diff --git a/plugins/gui/src/user_action/action_set_object_color.cpp b/plugins/gui/src/user_action/action_set_object_color.cpp index f6818a66a6b..b84061ec8e9 100644 --- a/plugins/gui/src/user_action/action_set_object_color.cpp +++ b/plugins/gui/src/user_action/action_set_object_color.cpp @@ -50,8 +50,8 @@ namespace hal oldColor = gNetlistRelay->getModuleModel()->setModuleColor(mObject.id(),mColor); gNetlistRelay->getModuleModel()->updateModule(mObject.id()); - // Since color is our Overlay over the netlist data, no event is - // automatically fired. We need to take care of that ourselves here. + // Set module color will fire moduleColorChanged event. + // However, gGraphContextManager is not in the receiver list and has to be updated manually gGraphContextManager->handleModuleColorChanged(gNetlist->get_module_by_id(mObject.id())); break; case UserActionObjectType::Grouping: From 6887e77e9365687d1217cdf6ea8ce617a935cb96 Mon Sep 17 00:00:00 2001 From: Skaleee <78816681+Skaleee@users.noreply.github.com> Date: Mon, 16 Oct 2023 18:54:32 +0200 Subject: [PATCH 18/36] Change ModuleModel to only use cached Icons. --- .../include/gui/module_model/module_model.h | 2 +- .../selection_details_icon_provider.h | 15 ++-------- plugins/gui/src/module_model/module_model.cpp | 2 +- .../selection_details_icon_provider.cpp | 28 ++++++------------- .../user_action/action_set_object_color.cpp | 1 - 5 files changed, 12 insertions(+), 36 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index a360d5a96f5..0734720b58a 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -55,7 +55,7 @@ namespace hal /** * Q_SIGNAL to notify that the color of a module has been changed. * - * @param m - The module with the changed color + * @param id - Id of the module with the changed color */ void moduleColorChanged(u32 id) const; diff --git a/plugins/gui/include/gui/selection_details_widget/selection_details_icon_provider.h b/plugins/gui/include/gui/selection_details_widget/selection_details_icon_provider.h index b2cd0e2853e..a9d9cdf8cba 100644 --- a/plugins/gui/include/gui/selection_details_widget/selection_details_icon_provider.h +++ b/plugins/gui/include/gui/selection_details_widget/selection_details_icon_provider.h @@ -52,7 +52,7 @@ namespace hal private: QHash mDefaultIcons; QHash mGateIcons; - QHash mModuleIcons; + QHash mModuleIcons; static bool sSettingsInitialized; static bool initSettings(); public: @@ -60,15 +60,4 @@ namespace hal static SelectionDetailsIconProvider* instance(); static SettingsItemDropdown* sIconSizeSetting; }; - - class ModuleIconInstance : public QIcon - { - u32 mId; - friend class SelectionDetailsIconProvider; - static QHash sInstances; - public: - ModuleIconInstance(u32 id, const QIcon& icon); - ~ModuleIconInstance(); - }; -} - +} \ No newline at end of file diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 6b2267ba9a1..01b25f9ff5e 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -121,7 +121,7 @@ namespace hal { switch(item->getType()){ case ModuleItem::TreeItemType::Module: - return QIcon(gui_utility::getStyledSvgIcon("all->" + mModuleColors[item->id()].name(QColor::HexRgb), ":/icons/ne_module")); + return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::ModuleIcon, item->id())); case ModuleItem::TreeItemType::Gate: return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::GateIcon, item->id())); case ModuleItem::TreeItemType::Net: diff --git a/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp b/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp index 798734922de..78e1da8352f 100644 --- a/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp +++ b/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp @@ -46,11 +46,11 @@ namespace hal void SelectionDetailsIconProvider::handleModuleColorChanged(u32 id) { - auto it = ModuleIconInstance::sInstances.find(id); - if (it == ModuleIconInstance::sInstances.end()) return; + auto it = mModuleIcons.find(id); + if (it == mModuleIcons.end()) return; delete it.value(); QColor col = gNetlistRelay->getModuleColor(id); - new ModuleIconInstance(id,gui_utility::getStyledSvgIcon("all->" + col.name(QColor::HexRgb), ":/icons/ne_module")); + mModuleIcons[id] = new QIcon(gui_utility::getStyledSvgIcon("all->" + col.name(QColor::HexRgb), ":/icons/ne_module")); } void SelectionDetailsIconProvider::loadIcons(int istyle) @@ -107,11 +107,12 @@ namespace hal col = gNetlistRelay->getModuleColor(itemId); if (col.isValid()) { - auto it = ModuleIconInstance::sInstances.find(itemId); - if (it != ModuleIconInstance::sInstances.end()) + auto it = mModuleIcons.find(itemId); + if (it != mModuleIcons.end()) return it.value(); - - return new ModuleIconInstance(itemId,gui_utility::getStyledSvgIcon("all->" + col.name(QColor::HexRgb), ":/icons/ne_module")); + QIcon* newIcon = new QIcon(gui_utility::getStyledSvgIcon("all->" + col.name(QColor::HexRgb), ":/icons/ne_module")); + mModuleIcons[itemId] = newIcon; + return newIcon; } break; default: @@ -119,17 +120,4 @@ namespace hal } return mDefaultIcons.value(catg); } - - QHash ModuleIconInstance::sInstances; - - ModuleIconInstance::ModuleIconInstance(u32 id, const QIcon &icon) - : QIcon(icon), mId(id) - { - sInstances[mId] = this; - } - - ModuleIconInstance::~ModuleIconInstance() - { - sInstances.remove(mId); - } } diff --git a/plugins/gui/src/user_action/action_set_object_color.cpp b/plugins/gui/src/user_action/action_set_object_color.cpp index b84061ec8e9..b0efee35d90 100644 --- a/plugins/gui/src/user_action/action_set_object_color.cpp +++ b/plugins/gui/src/user_action/action_set_object_color.cpp @@ -48,7 +48,6 @@ namespace hal { case UserActionObjectType::Module: oldColor = gNetlistRelay->getModuleModel()->setModuleColor(mObject.id(),mColor); - gNetlistRelay->getModuleModel()->updateModule(mObject.id()); // Set module color will fire moduleColorChanged event. // However, gGraphContextManager is not in the receiver list and has to be updated manually From ad485b826562d5c90724aff1a84e0204837c8267 Mon Sep 17 00:00:00 2001 From: Skaleee <78816681+Skaleee@users.noreply.github.com> Date: Wed, 18 Oct 2023 03:34:29 +0200 Subject: [PATCH 19/36] Updated Core Documentation --- include/hal_core/netlist/netlist.h | 1 + src/python_bindings/bindings/netlist.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/include/hal_core/netlist/netlist.h b/include/hal_core/netlist/netlist.h index 48f550918cf..415db8badbf 100644 --- a/include/hal_core/netlist/netlist.h +++ b/include/hal_core/netlist/netlist.h @@ -476,6 +476,7 @@ namespace hal /** * Remove a module from the netlist. + * Submodules, gates and nets under this module will be moved to the parent of this module. * * @param[in] module - The module. * @returns True on success, false otherwise. diff --git a/src/python_bindings/bindings/netlist.cpp b/src/python_bindings/bindings/netlist.cpp index 012f6de1255..3b30eb2b882 100644 --- a/src/python_bindings/bindings/netlist.cpp +++ b/src/python_bindings/bindings/netlist.cpp @@ -517,6 +517,7 @@ namespace hal py_netlist.def("delete_module", &Netlist::delete_module, py::arg("module"), R"( Remove a module from the netlist. + Submodules, gates and nets under this module will be moved to the parent of this module. :param module: The module. :type module: hal_py.Module From 71e00b1568893c7d52820e982a12f4ca42add74c Mon Sep 17 00:00:00 2001 From: Julia Date: Fri, 20 Oct 2023 15:39:15 +0200 Subject: [PATCH 20/36] make ModuleItem inherit from BaseTreeItem and ModuleModel inherit from BaseTreeModel WIP --- .../include/gui/module_model/module_item.h | 11 +++++++-- .../include/gui/module_model/module_model.h | 4 ++-- .../module_details_widget/module_tree_model.h | 2 ++ plugins/gui/src/module_model/module_item.cpp | 24 +++++++++++++++++-- plugins/gui/src/module_model/module_model.cpp | 6 ++--- .../gui/src/module_widget/module_widget.cpp | 15 +++++++++++- .../module_tree_model.cpp | 1 - 7 files changed, 51 insertions(+), 12 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_item.h b/plugins/gui/include/gui/module_model/module_item.h index f61ce42b727..0443d17f5cd 100644 --- a/plugins/gui/include/gui/module_model/module_item.h +++ b/plugins/gui/include/gui/module_model/module_item.h @@ -26,6 +26,8 @@ #pragma once #include "hal_core/defines.h" +#include "gui/basic_tree_model/base_tree_model.h" + #include #include @@ -40,7 +42,7 @@ namespace hal * * The ModuleItem is one item in the ModuleModel item model. It represents either a module, a gate or a net of the netlist. */ - class ModuleItem + class ModuleItem : public BaseTreeItem { public: /** @@ -48,6 +50,11 @@ namespace hal */ enum class TreeItemType {Module, Gate, Net}; + void setData(QList data) override; + void setDataAtIndex(int index, QVariant& data) override; + void appendData(QVariant data) override; + int getColumnCount() const override; + /** * Constructor. * @@ -137,7 +144,7 @@ namespace hal * @param column - The column to get the data for * @returns the data in the specified column of this ModuleItem */ - QVariant data(int column) const; + QVariant getData(int column) const override; /** * Gets the index of this ModuleItem in the list of children ModuleItems of its parent. diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index 0734720b58a..d691e7702da 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -30,6 +30,7 @@ #include "hal_core/netlist/module.h" #include "gui/module_model/module_item.h" + #include #include #include @@ -39,7 +40,6 @@ namespace hal { - class ModuleItem; /** * @ingroup gui @@ -47,7 +47,7 @@ namespace hal * * The ModuleModel is the item model that represents the modules and their hierarchy in the netlist. */ - class ModuleModel : public QAbstractItemModel + class ModuleModel : public BaseTreeModel { Q_OBJECT diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h index bf2c7d7ee29..0608a6bd89f 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h @@ -23,6 +23,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#pragma once + #include "gui/basic_tree_model/base_tree_model.h" #include "hal_core/defines.h" #include diff --git a/plugins/gui/src/module_model/module_item.cpp b/plugins/gui/src/module_model/module_item.cpp index ac4119dec11..a0159b99676 100644 --- a/plugins/gui/src/module_model/module_item.cpp +++ b/plugins/gui/src/module_model/module_item.cpp @@ -7,7 +7,27 @@ namespace hal { - ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : +void ModuleItem::setData(QList data) +{ + +} + +void ModuleItem::setDataAtIndex(int index, QVariant &data) +{ + +} + +void ModuleItem::appendData(QVariant data) +{ + +} + +int ModuleItem::getColumnCount() const +{ + +} + +ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : mParent(nullptr), mId(id), mType(type), @@ -100,7 +120,7 @@ namespace hal return 0; } - QVariant ModuleItem::data(int column) const + QVariant ModuleItem::getData(int column) const { // DEBUG CODE, USE STYLED DELEGATES OR SOMETHING if(column == 0) diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 01b25f9ff5e..bd0a70c0f81 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -1,7 +1,5 @@ #include "gui/module_model/module_model.h" -#include "gui/module_model/module_item.h" - #include "gui/gui_globals.h" #include "gui/gui_utils/graphics.h" @@ -12,7 +10,7 @@ namespace hal { - ModuleModel::ModuleModel(QObject* parent) : QAbstractItemModel(parent), mTopModuleItem(nullptr) + ModuleModel::ModuleModel(QObject* parent) : BaseTreeModel(parent), mTopModuleItem(nullptr) { } @@ -132,7 +130,7 @@ namespace hal } case Qt::DisplayRole: { - return item->data(index.column()); + return item->getData(index.column()); } case Qt::ForegroundRole: { diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index fa257287f64..b07d54a9ad6 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace hal { @@ -185,6 +186,7 @@ namespace hal QAction change_type_action; QAction change_color_action; QAction delete_action; + QAction extractPythonAction; switch(type) { @@ -212,6 +214,10 @@ namespace hal break; } case ModuleItem::TreeItemType::Gate: { + extractPythonAction.setIcon(QIcon(":/icons/python")); + extractPythonAction.setText("Extract Gate as python code (copy to clipboard)"); + extractPythonAction.setParent(&context_menu); + isolate_action.setText("Isolate in new view"); isolate_action.setParent(&context_menu); @@ -224,13 +230,16 @@ namespace hal } } - if (type == ModuleItem::TreeItemType::Gate || type == ModuleItem::TreeItemType::Module){ + if (type == ModuleItem::TreeItemType::Gate){ + context_menu.addAction(&extractPythonAction); context_menu.addAction(&isolate_action); context_menu.addAction(&change_name_action); } if (type == ModuleItem::TreeItemType::Module){ + context_menu.addAction(&isolate_action); + context_menu.addAction(&change_name_action); context_menu.addAction(&add_selection_action); context_menu.addAction(&add_child_action); context_menu.addAction(&change_type_action); @@ -248,6 +257,10 @@ namespace hal if (!clicked) return; + if (clicked == &extractPythonAction){ + QApplication::clipboard()->setText("netlist.get_gate_by_id(" + QString::number(getModuleItemFromIndex(index)->id()) + ")"); + } + if (clicked == &isolate_action && type == ModuleItem::TreeItemType::Gate) openGateInView(index); else if (clicked == &isolate_action) diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp index d04b547c2f5..c6b16cdd36f 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp @@ -1,6 +1,5 @@ #include "gui/selection_details_widget/module_details_widget/module_tree_model.h" #include "gui/selection_details_widget/selection_details_icon_provider.h" -#include "gui/basic_tree_model/base_tree_item.h" #include "hal_core/netlist/module.h" #include "hal_core/netlist/gate.h" #include "gui/gui_globals.h" From 7a8d034530f1c9dfebdbe9550aea2bd68100b9bd Mon Sep 17 00:00:00 2001 From: Julia Date: Sat, 21 Oct 2023 16:36:42 +0200 Subject: [PATCH 21/36] change ModuleItem to inherit from BaseTreeItem and ModuleModel to inherit from BaseTreeModel --- plugins/gui/src/module_model/module_item.cpp | 68 +++++++++++++------ .../gate_details_widget/pin_tree_model.cpp | 5 +- .../netlist_elements_tree_model.cpp | 5 +- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/plugins/gui/src/module_model/module_item.cpp b/plugins/gui/src/module_model/module_item.cpp index a0159b99676..3719efad404 100644 --- a/plugins/gui/src/module_model/module_item.cpp +++ b/plugins/gui/src/module_model/module_item.cpp @@ -7,25 +7,6 @@ namespace hal { -void ModuleItem::setData(QList data) -{ - -} - -void ModuleItem::setDataAtIndex(int index, QVariant &data) -{ - -} - -void ModuleItem::appendData(QVariant data) -{ - -} - -int ModuleItem::getColumnCount() const -{ - -} ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : mParent(nullptr), @@ -148,6 +129,48 @@ ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : return QVariant(); } + void ModuleItem::setData(QList data) + { + setName(data[0].toString()); + switch(mType) + { + case TreeItemType::Module: + { + Module* module = gNetlist->get_module_by_id(mId); + if(!module) + return; + module->set_type(data[3].toString().toStdString()); + } + case TreeItemType::Gate: + return; + } + } + + void ModuleItem::setDataAtIndex(int index, QVariant &data) + { + if(index == 0) { + setName(data.toString()); + return; + } + else if (index == 1) + return; + else if(index == 2) + { + switch(mType) + { + case TreeItemType::Module: + { + Module* module = gNetlist->get_module_by_id(mId); + if(!module) + return; + module->set_type(data.toString().toStdString()); + } + case TreeItemType::Gate: + return; + } + } + } + QString ModuleItem::name() const { return mName; @@ -181,4 +204,11 @@ ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : { mHighlighted = highlighted; } + + int ModuleItem::getColumnCount() const + { + return 3; + } + + void ModuleItem::appendData(QVariant data) {} } diff --git a/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp b/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp index f9b7ea9703f..3b2a9e9138b 100644 --- a/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp @@ -71,10 +71,7 @@ namespace hal } - void PinTreeItem::appendData(QVariant data) - { - - } + void PinTreeItem::appendData(QVariant data) {} int PinTreeItem::getColumnCount() const { diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp index 536d24d6103..0073b6e8a0c 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp @@ -59,10 +59,7 @@ namespace hal } } - void NetlistElementsTreeitem::appendData(QVariant data) - { - - } + void NetlistElementsTreeitem::appendData(QVariant data) {} int NetlistElementsTreeitem::getColumnCount() const { From f99d00016972fea89d3275837f816eec15eba03d Mon Sep 17 00:00:00 2001 From: Julia Date: Sun, 29 Oct 2023 20:47:31 +0100 Subject: [PATCH 22/36] Add actions to the context menu in the Module Widget --- .../gui/src/module_widget/module_widget.cpp | 70 ++++++++++++++++--- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index b07d54a9ad6..f8b33546608 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -15,6 +15,8 @@ #include "hal_core/netlist/module.h" #include "hal_core/netlist/net.h" #include "gui/module_model/module_model.h" +#include "gui/graph_tab_widget/graph_tab_widget.h" + #include #include #include @@ -187,10 +189,15 @@ namespace hal QAction change_color_action; QAction delete_action; QAction extractPythonAction; + QAction focus_in_view; switch(type) { case ModuleItem::TreeItemType::Module:{ + extractPythonAction.setIcon(QIcon(":/icons/python")); + extractPythonAction.setText("Extract Module as python code (copy to clipboard)"); + extractPythonAction.setParent(&context_menu); + isolate_action.setText("Isolate in new view"); isolate_action.setParent(&context_menu); @@ -211,6 +218,9 @@ namespace hal delete_action.setText("Delete module"); delete_action.setParent(&context_menu); + + focus_in_view.setText("Focus item in Graph View"); + focus_in_view.setParent(&context_menu); break; } case ModuleItem::TreeItemType::Gate: { @@ -223,10 +233,19 @@ namespace hal change_name_action.setText("Change Gate name"); change_name_action.setParent(&context_menu); + + focus_in_view.setText("Focus item in Graph View"); + focus_in_view.setParent(&context_menu); break; } case ModuleItem::TreeItemType::Net: { - return; + extractPythonAction.setIcon(QIcon(":/icons/python")); + extractPythonAction.setText("Extract Net as python code (copy to clipboard)"); + extractPythonAction.setParent(&context_menu); + + focus_in_view.setText("Focus item in Graph View"); + focus_in_view.setParent(&context_menu); + break; } } @@ -234,16 +253,24 @@ namespace hal context_menu.addAction(&extractPythonAction); context_menu.addAction(&isolate_action); context_menu.addAction(&change_name_action); + context_menu.addAction(&focus_in_view); } if (type == ModuleItem::TreeItemType::Module){ + context_menu.addAction(&extractPythonAction); context_menu.addAction(&isolate_action); context_menu.addAction(&change_name_action); context_menu.addAction(&add_selection_action); context_menu.addAction(&add_child_action); context_menu.addAction(&change_type_action); context_menu.addAction(&change_color_action); + context_menu.addAction(&focus_in_view); + } + + if (type == ModuleItem::TreeItemType::Net){ + context_menu.addAction(&extractPythonAction); + context_menu.addAction(&focus_in_view); } u32 module_id = getModuleItemFromIndex(index)->id(); @@ -258,13 +285,22 @@ namespace hal return; if (clicked == &extractPythonAction){ - QApplication::clipboard()->setText("netlist.get_gate_by_id(" + QString::number(getModuleItemFromIndex(index)->id()) + ")"); + switch(type) + { + case ModuleItem::TreeItemType::Module: QApplication::clipboard()->setText("netlist.get_Module_by_id(" + QString::number(getModuleItemFromIndex(index)->id()) + ")"); break; + case ModuleItem::TreeItemType::Gate: QApplication::clipboard()->setText("netlist.get_gate_by_id(" + QString::number(getModuleItemFromIndex(index)->id()) + ")"); break; + case ModuleItem::TreeItemType::Net: QApplication::clipboard()->setText("netlist.get_net_by_id(" + QString::number(getModuleItemFromIndex(index)->id()) + ")"); break; + } } - if (clicked == &isolate_action && type == ModuleItem::TreeItemType::Gate) - openGateInView(index); - else if (clicked == &isolate_action) - openModuleInView(index); + if (clicked == &isolate_action) + { + switch(type) + { + case ModuleItem::TreeItemType::Module: openModuleInView(index); break; + case ModuleItem::TreeItemType::Gate: openGateInView(index); break; + } + } if (clicked == &add_selection_action) gNetlistRelay->addSelectionToModule(getModuleItemFromIndex(index)->id()); @@ -275,10 +311,14 @@ namespace hal mTreeView->setExpanded(index, true); } - if (clicked == &change_name_action && type == ModuleItem::TreeItemType::Gate) - changeGateName(index); - else if (clicked == &change_name_action) - gNetlistRelay->changeModuleName(getModuleItemFromIndex(index)->id()); + if (clicked == &change_name_action) + { + switch(type) + { + case ModuleItem::TreeItemType::Module: gNetlistRelay->changeModuleName(getModuleItemFromIndex(index)->id()); break; + case ModuleItem::TreeItemType::Gate: changeGateName(index); break; + } + } if (clicked == &change_type_action) gNetlistRelay->changeModuleType(getModuleItemFromIndex(index)->id()); @@ -290,6 +330,16 @@ namespace hal gNetlistRelay->deleteModule(getModuleItemFromIndex(index)->id()); } + if (clicked == &focus_in_view){ + switch(type) + { + case ModuleItem::TreeItemType::Module: gContentManager->getGraphTabWidget()->handleModuleFocus(getModuleItemFromIndex(index)->id()); break; + case ModuleItem::TreeItemType::Gate: gContentManager->getGraphTabWidget()->handleGateFocus(getModuleItemFromIndex(index)->id()); break; + case ModuleItem::TreeItemType::Net: gContentManager->getGraphTabWidget()->handleNetFocus(getModuleItemFromIndex(index)->id()); break; + } + + } + } void ModuleWidget::handleModuleRemoved(Module* module, u32 module_id) From 52edfec44bf9c6a538fbe752095311d7bc6a49cb Mon Sep 17 00:00:00 2001 From: joern274 Date: Tue, 7 Nov 2023 11:53:08 +0100 Subject: [PATCH 23/36] Moved module color management to separate class --- .../gui/grouping/grouping_color_serializer.h | 15 -- plugins/gui/include/gui/gui_utils/graphics.h | 9 - .../gui/module_model/module_color_manager.h | 125 ++++++++++++++ .../include/gui/module_model/module_model.h | 42 ----- .../include/gui/netlist_relay/netlist_relay.h | 13 +- .../grouping/grouping_color_serializer.cpp | 91 +--------- plugins/gui/src/gui_utils/graphics.cpp | 14 -- .../src/module_model/module_color_manager.cpp | 155 ++++++++++++++++++ plugins/gui/src/module_model/module_model.cpp | 30 +--- .../gui/src/netlist_relay/netlist_relay.cpp | 20 ++- .../module_details_tab_widget.cpp | 3 +- .../selection_details_icon_provider.cpp | 3 +- .../src/user_action/action_delete_object.cpp | 3 +- .../user_action/action_set_object_color.cpp | 4 +- 14 files changed, 315 insertions(+), 212 deletions(-) create mode 100644 plugins/gui/include/gui/module_model/module_color_manager.h create mode 100644 plugins/gui/src/module_model/module_color_manager.cpp diff --git a/plugins/gui/include/gui/grouping/grouping_color_serializer.h b/plugins/gui/include/gui/grouping/grouping_color_serializer.h index fd292865fab..ab5f7937c08 100644 --- a/plugins/gui/include/gui/grouping/grouping_color_serializer.h +++ b/plugins/gui/include/gui/grouping/grouping_color_serializer.h @@ -30,7 +30,6 @@ namespace hal { class GroupingTableModel; - class ModuleModel; class GroupingColorSerializer : public ProjectSerializer { @@ -44,18 +43,4 @@ namespace hal { void restore(GroupingTableModel *gtm); }; - - class ModuleColorSerializer : public ProjectSerializer - { - void restoreModuleColor(const std::filesystem::path& loaddir, const std::string& jsonfile, ModuleModel *mm = nullptr); - void serializeColorRecursion(QJsonArray& mcArr, const ModuleModel* mm, QModelIndex parent=QModelIndex()); - public: - ModuleColorSerializer(); - - std::string serialize(Netlist* netlist, const std::filesystem::path& savedir, bool isAutosave) override; - - void deserialize(Netlist* netlist, const std::filesystem::path& loaddir) override; - - void restore(ModuleModel *mm); - }; } diff --git a/plugins/gui/include/gui/gui_utils/graphics.h b/plugins/gui/include/gui/gui_utils/graphics.h index 329cd68037b..c04cc0a4acf 100644 --- a/plugins/gui/include/gui/gui_utils/graphics.h +++ b/plugins/gui/include/gui/gui_utils/graphics.h @@ -80,14 +80,5 @@ namespace hal * @return The (perhabs styled) icon. */ extern QIcon getStyledSvgIcon(const QString& from_to_colors, const QString& svg_path); - - /** - * Returns a somewhat random color through a funny method (should be the same order - * of colors each time the program starts). This brilliant piece of code MUST NEVER - * BE REMOVED, PURE COMEDY! - * - * @return The "random" color. - */ - extern QColor getRandomColor(); } } diff --git a/plugins/gui/include/gui/module_model/module_color_manager.h b/plugins/gui/include/gui/module_model/module_color_manager.h new file mode 100644 index 00000000000..692a4db18d5 --- /dev/null +++ b/plugins/gui/include/gui/module_model/module_color_manager.h @@ -0,0 +1,125 @@ +// MIT License +// +// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved. +// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved. +// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved. +// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include "hal_core/defines.h" +#include "hal_core/netlist/project_serializer.h" +#include +#include +#include + +namespace hal +{ + /** + * Manages the module colors which will be assigned either by an "random" algorithm or manually by user. + * Quotes around "random" indicate it is not random at all, it is some homemade spinning around in HSV color circle. + */ + class ModuleColorManager : public QObject + { + Q_OBJECT + + Q_SIGNALS: + /** + * Q_SIGNAL to notify that the color of a module has been changed. + * + * @param id - Id of the module with the changed color + */ + void moduleColorChanged(u32 id) const; + + public: + ModuleColorManager(QObject* parent = nullptr); + + /** + * Gets the module color of a module of a specific id. + * + * @param id - The module id of the module to get the color for + * @returns the color of the module + */ + QColor moduleColor(u32 id) const; + + /** + * Changes the color of a module. + * + * @param id - The id of the module + * @param col - The new color + * @returns the old color of the module (used to create an undo action easier) + */ + QColor setModuleColor(u32 id, const QColor& col); + + /** + * Changes the color of a module to a random color. + * + * @param id - The id of the module + * @returns the old color of the module (used to create an undo action easier) + */ + QColor setRandomColor(u32 id); + + /** + * Removes the color that belongs to the given id. + * + * @param id - The module id for which to remove the color. + */ + void removeColor(u32 id); + + /** + * Getter for map of all module colores + * + * @returns The map of all module colores + */ + QMap getColorMap() const; + + void clear(); + private: + + + /** + * Returns a somewhat random color through a funny method (should be the same order + * of colors each time the program starts). + * + * @return The "random" color. + */ + QColor getRandomColor(); + + QMap mModuleColors; + }; + + /** + * Persist module color settings to file and restore module color assignment from previous session + */ + class ModuleColorSerializer : public ProjectSerializer + { + void restoreModuleColor(const std::filesystem::path& loaddir, const std::string& jsonfile, ModuleColorManager *mcm = nullptr); + void serializeColorMap(QJsonArray& mcArr, const ModuleColorManager* mcm); + public: + ModuleColorSerializer(); + + std::string serialize(Netlist* netlist, const std::filesystem::path& savedir, bool isAutosave) override; + + void deserialize(Netlist* netlist, const std::filesystem::path& loaddir) override; + + void restore(ModuleColorManager *mcm); + }; +} diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index d691e7702da..4be14239434 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -51,14 +50,6 @@ namespace hal { Q_OBJECT - Q_SIGNALS: - /** - * Q_SIGNAL to notify that the color of a module has been changed. - * - * @param id - Id of the module with the changed color - */ - void moduleColorChanged(u32 id) const; - public: /** * Constructor.
@@ -258,38 +249,6 @@ namespace hal */ bool isModifying(); - /** - * Gets the module color of a module of a specific id. - * - * @param id - The module id of the module to get the color for - * @returns the color of the module - */ - QColor moduleColor(u32 id) const; - - /** - * Changes the color of a module. - * - * @param id - The id of the module - * @param col - The new color - * @returns the old color of the module (used to create an undo action easier) - */ - QColor setModuleColor(u32 id, const QColor& col); - - /** - * Changes the color of a module to a random color. - * - * @param id - The id of the module - * @returns the old color of the module (used to create an undo action easier) - */ - QColor setRandomColor(u32 id); - - /** - * Removes the color that belongs to the given id. - * - * @param id - The module id for which to remove the color. - */ - void removeColor(u32 id); - private: ModuleItem* mTopModuleItem; @@ -297,7 +256,6 @@ namespace hal QMap mGateMap; QMap mNetMap; std::array*, 3> mModuleItemMaps = {&mModuleMap, &mGateMap, &mNetMap};; - QMap mModuleColors; bool mIsModifying; }; diff --git a/plugins/gui/include/gui/netlist_relay/netlist_relay.h b/plugins/gui/include/gui/netlist_relay/netlist_relay.h index 2915e88f782..83085c6b8ae 100644 --- a/plugins/gui/include/gui/netlist_relay/netlist_relay.h +++ b/plugins/gui/include/gui/netlist_relay/netlist_relay.h @@ -27,6 +27,7 @@ #include "hal_core/netlist/event_system/event_handler.h" #include "gui/grouping/grouping_color_serializer.h" +#include "gui/module_model/module_color_manager.h" #include #include @@ -34,6 +35,8 @@ namespace hal { class ModuleItem; class ModuleModel; + class ModuleColorManager; + class ModuleColorSerializer; class Module; /** @@ -88,7 +91,14 @@ namespace hal * * @returns the module model */ - ModuleModel* getModuleModel(); + ModuleModel* getModuleModel() const; + + /** + * Accesses the module color manager + * + * @returns the module color manager + */ + ModuleColorManager* getModuleColorManager() const; /** * Changes the name of a specific module by asking the user for a new name in a 'Rename'-dialogue. @@ -610,6 +620,7 @@ namespace hal QMap mModuleColors; ModuleModel* mModuleModel; + ModuleColorManager* mModuleColorManager; ModuleColorSerializer mColorSerializer; enum ThreadEventType { TetNetlist, TetModule, TetGate, TetNet, TetGrouping }; }; diff --git a/plugins/gui/src/grouping/grouping_color_serializer.cpp b/plugins/gui/src/grouping/grouping_color_serializer.cpp index ac0c29f08e9..cc54efd319f 100644 --- a/plugins/gui/src/grouping/grouping_color_serializer.cpp +++ b/plugins/gui/src/grouping/grouping_color_serializer.cpp @@ -6,6 +6,7 @@ #include "gui/grouping/grouping_table_model.h" #include "gui/module_model/module_model.h" #include "gui/module_model/module_item.h" +#include "gui/module_model/module_color_manager.h" #include #include @@ -104,94 +105,4 @@ namespace hal { gtm->setData(gtm->index(irow,2), color, Qt::EditRole); } } - - //--------------------------------------- - ModuleColorSerializer::ModuleColorSerializer() - : ProjectSerializer("modulecolor") - {;} - - void ModuleColorSerializer::restore(ModuleModel* mm) - { - ProjectManager* pm = ProjectManager::instance(); - std::string relname = pm->get_filename(m_name); - if (!relname.empty()) - restoreModuleColor(pm->get_project_directory(), relname, mm); - } - - void ModuleColorSerializer::serializeColorRecursion(QJsonArray& mcArr, const ModuleModel* mm, QModelIndex parent) - { - int nrows = mm->rowCount(parent); - for (int irow=0; irowindex(irow,0,parent); - const ModuleItem* mItem = mm->getItem(inx); - if (!mItem) continue; - if(mItem->getType() != ModuleItem::TreeItemType::Module) continue; - - QJsonObject mcEntry; - mcEntry["id"] = (int) mItem->id(); - mcEntry["color"] = mm->moduleColor(mItem->id()).name(QColor::HexArgb); - mcArr.append(mcEntry); - serializeColorRecursion(mcArr,mm,inx); - } - } - - std::string ModuleColorSerializer::serialize(Netlist* netlist, const std::filesystem::path& savedir, bool isAutosave) - { - Q_UNUSED(netlist); - Q_UNUSED(isAutosave); - QString mcFilename("modulecolor.json"); - QFile mcFile(QDir(QString::fromStdString(savedir.string())).absoluteFilePath(mcFilename)); - if (!mcFile.open(QIODevice::WriteOnly)) return std::string(); - - QJsonObject mcObj; - QJsonArray mcArr; - - const ModuleModel* mm = gNetlistRelay->getModuleModel(); - if (!mm) return std::string(); - - serializeColorRecursion(mcArr,mm); - - mcObj["modcolors"] = mcArr; - - mcFile.write(QJsonDocument(mcObj).toJson(QJsonDocument::Compact)); - - return mcFilename.toStdString(); - } - - - void ModuleColorSerializer::deserialize(Netlist* netlist, const std::filesystem::path& loaddir) - { - Q_UNUSED(netlist); - std::string relname = ProjectManager::instance()->get_filename(m_name); - if (!relname.empty()) - restoreModuleColor(loaddir, relname); - } - - void ModuleColorSerializer::restoreModuleColor(const std::filesystem::path& loaddir, const std::string& jsonfile, ModuleModel* mm) - { - if (!mm) - { - mm = gNetlistRelay->getModuleModel(); - if (!mm) return; - } - - QFile mcFile(QDir(QString::fromStdString(loaddir.string())).absoluteFilePath(QString::fromStdString(jsonfile))); - if (!mcFile.open(QIODevice::ReadOnly)) - return; - QJsonDocument jsonDoc = QJsonDocument::fromJson(mcFile.readAll()); - const QJsonObject& json = jsonDoc.object(); - - if (json.contains("modcolors") && json["modcolors"].isArray()) - { - QJsonArray mcArr = json["modcolors"].toArray(); - int nmc = mcArr.size(); - for (int imc = 0; imc < nmc; imc++) - { - QJsonObject mcEntry = mcArr.at(imc).toObject(); - u32 moduleId = mcEntry["id"].toInt(); - mm->setModuleColor(moduleId,QColor(mcEntry["color"].toString())); - } - } - } } diff --git a/plugins/gui/src/gui_utils/graphics.cpp b/plugins/gui/src/gui_utils/graphics.cpp index 8ae8e9bf831..0e3ed8bac04 100644 --- a/plugins/gui/src/gui_utils/graphics.cpp +++ b/plugins/gui/src/gui_utils/graphics.cpp @@ -80,19 +80,5 @@ namespace hal return getIconFromSvgData(svg_data); } - - QColor getRandomColor() - { - static qreal h = 0.5; - - h += 0.6180339887498948; - - if (h > 1) - --h; - - QColor c; - c.setHsvF(h, 0.8, 0.95); // (MAYBE) GET S AND V FROM STYLESHEET OR CYCLE 3 DIMENSIONAL - return c; - } } // namespace gui_utility } diff --git a/plugins/gui/src/module_model/module_color_manager.cpp b/plugins/gui/src/module_model/module_color_manager.cpp new file mode 100644 index 00000000000..12a84020847 --- /dev/null +++ b/plugins/gui/src/module_model/module_color_manager.cpp @@ -0,0 +1,155 @@ +#include "gui/module_model/module_color_manager.h" + +#include "hal_core/netlist/project_manager.h" +#include "gui/gui_globals.h" +#include "gui/gui_utils/graphics.h" + +#include +#include +#include +#include +#include + +namespace hal +{ + + ModuleColorManager::ModuleColorManager(QObject *parent) + : QObject(parent) + { + setModuleColor(1, QColor(96, 110, 112)); + } + + void ModuleColorManager::clear() + { + mModuleColors.clear(); + } + + QColor ModuleColorManager::moduleColor(u32 id) const + { + return mModuleColors.value(id); + } + + QColor ModuleColorManager::setModuleColor(u32 id, const QColor& col) + { + QColor retval = mModuleColors.value(id); + mModuleColors[id] = col; + Q_EMIT moduleColorChanged(id); + return retval; + } + + QColor ModuleColorManager::getRandomColor() + { + static qreal h = 0.5; + + h += 0.6180339887498948; + + if (h > 1) + --h; + + QColor c; + c.setHsvF(h, 0.8, 0.95); // (MAYBE) GET S AND V FROM STYLESHEET OR CYCLE 3 DIMENSIONAL + return c; + } + + QColor ModuleColorManager::setRandomColor(u32 id) + { + QColor retval = mModuleColors.value(id); + mModuleColors.insert(id,getRandomColor()); + return retval; + } + + QMap ModuleColorManager::getColorMap() const + { + return mModuleColors; + } + + void ModuleColorManager::removeColor(u32 id) + { + mModuleColors.remove(id); + } + + //--------------------------------------- + ModuleColorSerializer::ModuleColorSerializer() + : ProjectSerializer("modulecolor") + {;} + + void ModuleColorSerializer::restore(ModuleColorManager *mcm) + { + ProjectManager* pm = ProjectManager::instance(); + std::string relname = pm->get_filename(m_name); + if (!relname.empty()) + restoreModuleColor(pm->get_project_directory(), relname, mcm); + } + + void ModuleColorSerializer::serializeColorMap(QJsonArray& mcArr, const ModuleColorManager *mcm) + { + QMap cmap = mcm->getColorMap(); + + for (auto it = cmap.constBegin(); it != cmap.constEnd(); ++it) + { + QJsonObject mcEntry; + mcEntry["id"] = (int) it.key(); + mcEntry["color"] = it.value().name(QColor::HexArgb); + mcArr.append(mcEntry); + } + } + + std::string ModuleColorSerializer::serialize(Netlist* netlist, const std::filesystem::path& savedir, bool isAutosave) + { + Q_UNUSED(netlist); + Q_UNUSED(isAutosave); + QString mcFilename("modulecolor.json"); + QFile mcFile(QDir(QString::fromStdString(savedir.string())).absoluteFilePath(mcFilename)); + if (!mcFile.open(QIODevice::WriteOnly)) return std::string(); + + QJsonObject mcObj; + QJsonArray mcArr; + + const ModuleColorManager* mcm = gNetlistRelay->getModuleColorManager(); + if (!mcm) return std::string(); + + serializeColorMap(mcArr,mcm); + + mcObj["modcolors"] = mcArr; + + mcFile.write(QJsonDocument(mcObj).toJson(QJsonDocument::Compact)); + + return mcFilename.toStdString(); + } + + + void ModuleColorSerializer::deserialize(Netlist* netlist, const std::filesystem::path& loaddir) + { + Q_UNUSED(netlist); + std::string relname = ProjectManager::instance()->get_filename(m_name); + if (!relname.empty()) + restoreModuleColor(loaddir, relname); + } + + void ModuleColorSerializer::restoreModuleColor(const std::filesystem::path& loaddir, const std::string& jsonfile, ModuleColorManager *mcm) + { + if (!mcm) + { + mcm = gNetlistRelay->getModuleColorManager(); + if (!mcm) return; + } + + QFile mcFile(QDir(QString::fromStdString(loaddir.string())).absoluteFilePath(QString::fromStdString(jsonfile))); + if (!mcFile.open(QIODevice::ReadOnly)) + return; + QJsonDocument jsonDoc = QJsonDocument::fromJson(mcFile.readAll()); + const QJsonObject& json = jsonDoc.object(); + + if (json.contains("modcolors") && json["modcolors"].isArray()) + { + QJsonArray mcArr = json["modcolors"].toArray(); + int nmc = mcArr.size(); + for (int imc = 0; imc < nmc; imc++) + { + QJsonObject mcEntry = mcArr.at(imc).toObject(); + u32 moduleId = mcEntry["id"].toInt(); + gNetlistRelay->getModuleColorManager()->setModuleColor(moduleId,QColor(mcEntry["color"].toString())); + } + } + } +} diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 9e87c10bb34..42d7e107ee6 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -1,7 +1,6 @@ #include "gui/module_model/module_model.h" #include "gui/gui_globals.h" -#include "gui/gui_utils/graphics.h" #include "gui/selection_details_widget/selection_details_icon_provider.h" @@ -198,7 +197,6 @@ namespace hal void ModuleModel::init() { - setModuleColor(1, QColor(96, 110, 112)); ModuleItem* item = new ModuleItem(1); mModuleMap.insert(1, item); @@ -238,8 +236,7 @@ namespace hal mModuleMap.clear(); mGateMap.clear(); mNetMap.clear(); - mModuleColors.clear(); - + //TODO : clear colors endResetModel(); } @@ -452,31 +449,6 @@ namespace hal return mModuleItemMaps[(int)type]->value(id); } - QColor ModuleModel::moduleColor(u32 id) const - { - return mModuleColors.value(id); - } - - QColor ModuleModel::setModuleColor(u32 id, const QColor& col) - { - QColor retval = mModuleColors.value(id); - mModuleColors[id] = col; - Q_EMIT moduleColorChanged(id); - return retval; - } - - QColor ModuleModel::setRandomColor(u32 id) - { - QColor retval = mModuleColors.value(id); - mModuleColors.insert(id,gui_utility::getRandomColor()); - return retval; - } - - void ModuleModel::removeColor(u32 id) - { - mModuleColors.remove(id); - } - bool ModuleModel::isModifying() { return mIsModifying; diff --git a/plugins/gui/src/netlist_relay/netlist_relay.cpp b/plugins/gui/src/netlist_relay/netlist_relay.cpp index cd622124d8d..37c77bb3868 100644 --- a/plugins/gui/src/netlist_relay/netlist_relay.cpp +++ b/plugins/gui/src/netlist_relay/netlist_relay.cpp @@ -27,7 +27,8 @@ namespace hal { - NetlistRelay::NetlistRelay(QObject* parent) : QObject(parent), mModuleModel(new ModuleModel(this)) + NetlistRelay::NetlistRelay(QObject* parent) + : QObject(parent), mModuleModel(new ModuleModel(this)), mModuleColorManager(new ModuleColorManager(this)) { connect(FileManager::get_instance(), &FileManager::fileOpened, this, &NetlistRelay::debugHandleFileOpened); // DEBUG LINE connect(this, &NetlistRelay::signalThreadEvent, this, &NetlistRelay::handleThreadEvent, Qt::BlockingQueuedConnection); @@ -81,14 +82,19 @@ namespace hal QColor NetlistRelay::getModuleColor(const u32 id) { - return mModuleModel->moduleColor(id); + return mModuleColorManager->moduleColor(id); } - ModuleModel* NetlistRelay::getModuleModel() + ModuleModel* NetlistRelay::getModuleModel() const { return mModuleModel; } + ModuleColorManager* NetlistRelay::getModuleColorManager() const + { + return mModuleColorManager; + } + void NetlistRelay::changeModuleName(const u32 id) { // NOT THREADSAFE @@ -375,7 +381,7 @@ namespace hal if (mod->get_parent_module() != nullptr) { mModuleModel->addModule(mod->get_id(), mod->get_parent_module()->get_id()); - mModuleModel->setRandomColor(mod->get_id()); + mModuleColorManager->setRandomColor(mod->get_id()); } gGraphContextManager->handleModuleCreated(mod); @@ -386,7 +392,7 @@ namespace hal case ModuleEvent::event::removed: { //< no associated_data - mModuleModel->removeColor(mod->get_id()); + mModuleColorManager->removeColor(mod->get_id()); mModuleModel->remove_module(mod->get_id()); gGraphContextManager->handleModuleRemoved(mod); @@ -672,9 +678,9 @@ namespace hal void NetlistRelay::debugHandleFileOpened() { for (Module* m : gNetlist->get_modules()) - mModuleModel->setRandomColor(m->get_id()); + mModuleColorManager->setRandomColor(m->get_id()); mModuleModel->init(); - mColorSerializer.restore(mModuleModel); + mColorSerializer.restore(mModuleColorManager); } void NetlistRelay::debugHandleFileClosed() diff --git a/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp b/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp index b64065bc2ff..d97e986f8aa 100644 --- a/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp @@ -9,6 +9,7 @@ #include "hal_core/netlist/module.h" #include "gui/gui_globals.h" #include "gui/module_model/module_model.h" +#include "gui/module_model/module_color_manager.h" namespace hal { @@ -51,7 +52,7 @@ namespace hal mCommentWidget = new CommentWidget(this); QTabWidget::addTab(mCommentWidget, "Comments"); - connect(gNetlistRelay->getModuleModel(),&ModuleModel::moduleColorChanged,this,&ModuleDetailsTabWidget::handleModuleColorChanged); + connect(gNetlistRelay->getModuleColorManager(),&ModuleColorManager::moduleColorChanged,this,&ModuleDetailsTabWidget::handleModuleColorChanged); } void ModuleDetailsTabWidget::handleModuleColorChanged(u32 id) diff --git a/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp b/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp index 78e1da8352f..f6748dd9c44 100644 --- a/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp +++ b/plugins/gui/src/selection_details_widget/selection_details_icon_provider.cpp @@ -4,6 +4,7 @@ #include "gui/main_window/main_window.h" #include "gui/settings/settings_items/settings_item_dropdown.h" #include "gui/module_model/module_model.h" +#include "gui/module_model/module_color_manager.h" #include #include @@ -40,7 +41,7 @@ namespace hal : QObject(parent) { connect(MainWindow::sSettingStyle, &SettingsItemDropdown::intChanged,this,&SelectionDetailsIconProvider::loadIcons); - connect(gNetlistRelay->getModuleModel(),&ModuleModel::moduleColorChanged,this,&SelectionDetailsIconProvider::handleModuleColorChanged); + connect(gNetlistRelay->getModuleColorManager(),&ModuleColorManager::moduleColorChanged,this,&SelectionDetailsIconProvider::handleModuleColorChanged); loadIcons(MainWindow::sSettingStyle->value().toInt()); } diff --git a/plugins/gui/src/user_action/action_delete_object.cpp b/plugins/gui/src/user_action/action_delete_object.cpp index b26e214e8d5..c1ddee64cb1 100644 --- a/plugins/gui/src/user_action/action_delete_object.cpp +++ b/plugins/gui/src/user_action/action_delete_object.cpp @@ -5,6 +5,7 @@ #include "gui/grouping/grouping_table_model.h" #include "gui/gui_globals.h" #include "gui/module_model/module_model.h" +#include "gui/module_model/module_color_manager.h" #include "gui/user_action/action_add_items_to_object.h" #include "gui/user_action/action_create_object.h" #include "gui/user_action/action_set_object_color.h" @@ -74,7 +75,7 @@ namespace hal actCreate->setParentId(mod->get_parent_module()->get_id()); act->addAction(actCreate); act->addAction(new ActionSetObjectType(QString::fromStdString(mod->get_type()))); - act->addAction(new ActionSetObjectColor(gNetlistRelay->getModuleModel()->moduleColor(mod->get_id()))); + act->addAction(new ActionSetObjectColor(gNetlistRelay->getModuleColorManager()->moduleColor(mod->get_id()))); QSet mods, gats; for (Gate* g : mod->get_gates()) gats.insert(g->get_id()); diff --git a/plugins/gui/src/user_action/action_set_object_color.cpp b/plugins/gui/src/user_action/action_set_object_color.cpp index b0efee35d90..20b173a4ba3 100644 --- a/plugins/gui/src/user_action/action_set_object_color.cpp +++ b/plugins/gui/src/user_action/action_set_object_color.cpp @@ -1,7 +1,7 @@ #include "gui/user_action/action_set_object_color.h" #include "gui/grouping/grouping_manager_widget.h" #include "gui/grouping/grouping_table_model.h" -#include "gui/module_model/module_model.h" +#include "gui/module_model/module_color_manager.h" #include "gui/gui_globals.h" namespace hal @@ -47,7 +47,7 @@ namespace hal switch (mObject.type()) { case UserActionObjectType::Module: - oldColor = gNetlistRelay->getModuleModel()->setModuleColor(mObject.id(),mColor); + oldColor = gNetlistRelay->getModuleColorManager()->setModuleColor(mObject.id(),mColor); // Set module color will fire moduleColorChanged event. // However, gGraphContextManager is not in the receiver list and has to be updated manually From a4e1b5411ba5ca5ab4c69c2e9f4c352ce083cfab Mon Sep 17 00:00:00 2001 From: joern274 Date: Tue, 7 Nov 2023 15:43:46 +0100 Subject: [PATCH 24/36] Update selection details tree view upon module color change --- .../tree_navigation/selection_tree_view.h | 6 ++++++ .../tree_navigation/selection_tree_view.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_view.h b/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_view.h index c677f114f54..8dd7c85eae8 100644 --- a/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_view.h +++ b/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_view.h @@ -79,6 +79,12 @@ namespace hal * @param filter_text -The text to filter the model. */ void handleFilterTextChanged(const QString& filter_text); + + /** + * Might have to change icon color if module selected, thus updating view upon this event + * @param id - unused + */ + void handleModuleColorChanged(u32 id); protected: /** diff --git a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_view.cpp b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_view.cpp index cfc1959ca84..4eeeaec0afe 100644 --- a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_view.cpp +++ b/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_view.cpp @@ -33,6 +33,7 @@ namespace hal connect(this, &SelectionTreeView::itemDoubleClicked, this, &SelectionTreeView::handleTreeViewItemFocusClicked); connect(this, &SelectionTreeView::focusItemClicked, this, &SelectionTreeView::handleTreeViewItemFocusClicked); + connect(gNetlistRelay->getModuleColorManager(),&ModuleColorManager::moduleColorChanged,this,&SelectionTreeView::handleModuleColorChanged); } void SelectionTreeView::setDefaultColumnWidth() @@ -78,6 +79,12 @@ namespace hal return static_cast(modelIndex.internalPointer()); } + void SelectionTreeView::handleModuleColorChanged(u32 id) + { + Q_UNUSED(id); + update(); + } + void SelectionTreeView::handleCustomContextMenuRequested(const QPoint& point) { QModelIndex index = indexAt(point); From 0fe5db3a8ac6163017b85ff423850c43a5d4daf0 Mon Sep 17 00:00:00 2001 From: Skaleee <78816681+Skaleee@users.noreply.github.com> Date: Fri, 10 Nov 2023 18:12:45 +0100 Subject: [PATCH 25/36] Added functions for net placement in ModuleModel --- .../include/gui/module_model/module_model.h | 32 ++++-- plugins/gui/src/module_model/module_model.cpp | 105 +++++++++++++----- .../gui/src/netlist_relay/netlist_relay.cpp | 4 + 3 files changed, 105 insertions(+), 36 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index 4be14239434..4c677a9d941 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -189,14 +189,12 @@ namespace hal /** * Recursively adds the given module with all of its submodules (and their submodules and so on...) - * and the gates and nets of those modules to the item model. + * and the gates those modules to the item model. * * @param module - The module which should be added to the item model together with all its * submodules, gates and nets. - * @param added_nets - A set of ids of nets. It's used to keep track of the nets that have already been added - * to the item model during the recursion. You can pass an empty set to add all nets. */ - void addRecursively(const Module* module, QSet& added_nets); + void addRecursively(const Module* module); /** * Updates the parent of the ModuleItem corresponding to the specified module. @@ -227,6 +225,15 @@ namespace hal */ void remove_net(const u32 id); + /** + * Updates the position of a net in the ModuleTree. + * The net will be placed under the deepest module, that contains all sources and destinations of the net. + * If no suitable parent could be found, then the net will instead be placed under the top module. + * + * @param net The net whose source or destination changed. + */ + void handleNetSourceOrDestinationChanged(const Net* net); + /** * Updates the ModuleItem for the specified module. The specified module MUST be contained in the item model. * @@ -234,12 +241,6 @@ namespace hal */ void updateModule(const u32 id); -// void addModule(u32 id, u32 parent_module); -// void addRecursively(const std::vector& modules); -// void remove_module(u32 id); -// void updateModule(u32 id); - - /** * Returns true if the item model is currently changed/updated. This is the case while adding and * removing modules to/from the item model. It can be used to ignore certain signals sent by the item model @@ -250,6 +251,17 @@ namespace hal bool isModifying(); private: + /** + * Searches for a new parent module, such that it is the deepest module in the hierarchy, that contains all + * sources and destinations of the net. + * + * @param net The net for which a new parent should be searched. + * + * @return The new parent module, that contains all sources and destinations of net. If no such parent could be found + * (e.g. net has no sources or destinations), nullptr is returned instead. + */ + Module* FindNetParent(const Net* net); + ModuleItem* mTopModuleItem; QMap mModuleMap; diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 42d7e107ee6..9619ecbe1c6 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -204,20 +204,13 @@ namespace hal mTopModuleItem = item; endInsertRows(); - // This is broken because it can attempt to insert a child before its parent - // which will cause an assertion failure and then crash - - // std::set s = gNetlist->get_modules(); - // s.erase(gNetlist->get_top_module()); - // for (Module* m : s) - // addModule(m->get_id(), m->get_parent_module()->get_id()); - - // This works - - // recursively insert modules Module* m = gNetlist->get_top_module(); - QSet added_nets; - addRecursively(m, added_nets); + addRecursively(m); + for(auto net : gNetlist->get_top_module()->get_internal_nets()) + { + addNet(net->get_id(), m->get_id()); + handleNetSourceOrDestinationChanged(net); + } } void ModuleModel::clear() @@ -310,22 +303,15 @@ namespace hal endInsertRows(); } - void ModuleModel::addRecursively(const Module* module, QSet& added_nets) + void ModuleModel::addRecursively(const Module* module) { if(!module->is_top_module()) addModule(module->get_id(), module->get_parent_module()->get_id()); for(auto &m : module->get_submodules()) - addRecursively(m, added_nets); + addRecursively(m); for(auto &g : module->get_gates()) addGate(g->get_id(), module->get_id()); - for(auto &n : module->get_internal_nets()) - { - int size = added_nets.size(); - added_nets.insert(n->get_id()); - if(added_nets.size() > size) - addNet(n->get_id(), module->get_id()); - } } void ModuleModel::changeParentModule(const Module* module){ @@ -360,7 +346,7 @@ namespace hal void ModuleModel::remove_module(const u32 id) { assert(id != 1); -// module was most likely already purged from netlist + // module was most likely already purged from netlist assert(mModuleMap.contains(id)); ModuleItem* item = mModuleMap.value(id); @@ -384,7 +370,7 @@ namespace hal void ModuleModel::remove_gate(const u32 id) { - assert(gNetlist->get_gate_by_id(id)); + //assert(gNetlist->get_gate_by_id(id)); assert(mGateMap.contains(id)); ModuleItem* item = mGateMap.value(id); @@ -408,8 +394,8 @@ namespace hal void ModuleModel::remove_net(const u32 id) { - assert(gNetlist->get_net_by_id(id)); - assert(mModuleMap.contains(id)); + //assert(gNetlist->get_net_by_id(id)); + assert(mNetMap.contains(id)); ModuleItem* item = mNetMap.value(id); ModuleItem* parent = item->parent(); @@ -430,6 +416,36 @@ namespace hal delete item; } + void ModuleModel::handleNetSourceOrDestinationChanged(const Net* net) + { + assert(net); + u32 id = net->get_id(); + assert(mNetMap.contains(id)); + ModuleItem* item = mNetMap.value(id); + ModuleItem* oldParentItem = item->parent(); + assert(oldParentItem); + + Module* newParentModule = FindNetParent(net); + if(newParentModule == nullptr) + newParentModule = gNetlist->get_top_module(); + if(newParentModule->get_id() == oldParentItem->id()) + return; + + assert(mModuleMap.contains(newParentModule->get_id())); + ModuleItem* newParentItem = mModuleMap[newParentModule->get_id()]; + QModelIndex newIndex = getIndex(newParentItem); + QModelIndex oldIndex = getIndex(oldParentItem); + int row = item->row(); + + mIsModifying = true; + beginMoveRows(oldIndex, row, row, newIndex, newParentItem->childCount()); + oldParentItem->removeChild(item); + newParentItem->appendChild(item); + item->setParent(newParentItem); + mIsModifying = false; + endMoveRows(); + } + void ModuleModel::updateModule(u32 id) // SPLIT ??? { assert(gNetlist->get_module_by_id(id)); @@ -453,4 +469,41 @@ namespace hal { return mIsModifying; } + + Module* ModuleModel::FindNetParent(const Net* net){ + // cannot use Module::get_internal_nets(), because currently that function is implemented so, + // that a net can be "internal" to multiple modules at the same depth. + // => instead manually search for deepest module, that contains all sources and destinations of net. + assert(net); + if(net->get_num_of_sources() == 0 && net->get_num_of_destinations() == 0) + return nullptr; + + std::vector endpoints = net->get_sources(); + + { + std::vector destinations = net->get_destinations(); + endpoints.insert(endpoints.end(), destinations.begin(), destinations.end()); + } + + Module* parent = endpoints[0]->get_gate()->get_module(); + endpoints.erase(endpoints.begin()); + + // might want to split up endpoints, if sources and destinations should be handled differently + while(endpoints.size() > 0) + { + std::vector::iterator it = endpoints.begin(); + while(it != endpoints.end()) + { + if(parent->contains_gate((*it)->get_gate(), true)) + it = endpoints.erase(it); + else + ++it; + } + + if(endpoints.size() > 0) + parent = parent->get_parent_module(); + } + + return parent; + } } diff --git a/plugins/gui/src/netlist_relay/netlist_relay.cpp b/plugins/gui/src/netlist_relay/netlist_relay.cpp index 37c77bb3868..600d89e8ac7 100644 --- a/plugins/gui/src/netlist_relay/netlist_relay.cpp +++ b/plugins/gui/src/netlist_relay/netlist_relay.cpp @@ -616,6 +616,7 @@ namespace hal case NetEvent::event::src_added: { //< associated_data = id of src gate + mModuleModel->handleNetSourceOrDestinationChanged(net); gGraphContextManager->handleNetSourceAdded(net, associated_data); Q_EMIT netSourceAdded(net, associated_data); @@ -624,6 +625,7 @@ namespace hal case NetEvent::event::src_removed: { //< associated_data = id of src gate + mModuleModel->handleNetSourceOrDestinationChanged(net); gGraphContextManager->handleNetSourceRemoved(net, associated_data); Q_EMIT netSourceRemoved(net, associated_data); @@ -632,6 +634,7 @@ namespace hal case NetEvent::event::dst_added: { //< associated_data = id of dst gate + mModuleModel->handleNetSourceOrDestinationChanged(net); gGraphContextManager->handleNetDestinationAdded(net, associated_data); Q_EMIT netDestinationAdded(net, associated_data); @@ -640,6 +643,7 @@ namespace hal case NetEvent::event::dst_removed: { //< associated_data = id of dst gate + mModuleModel->handleNetSourceOrDestinationChanged(net); gGraphContextManager->handleNetDestinationRemoved(net, associated_data); Q_EMIT netDestinationRemoved(net, associated_data); From 6091df0af84d9506f079bb6f58f34e24cb65d9ab Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 7 Nov 2023 01:05:54 +0100 Subject: [PATCH 26/36] Make ModuleModel inherit from BaseTreeModel --- .../include/gui/module_model/module_item.h | 39 +---- .../include/gui/module_model/module_model.h | 62 +------- .../src/basic_tree_model/base_tree_model.cpp | 2 +- plugins/gui/src/module_model/module_item.cpp | 35 +---- plugins/gui/src/module_model/module_model.cpp | 133 ++---------------- .../gui/src/module_widget/module_widget.cpp | 2 +- 6 files changed, 28 insertions(+), 245 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_item.h b/plugins/gui/include/gui/module_model/module_item.h index 0443d17f5cd..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. @@ -100,13 +78,6 @@ namespace hal */ void prependChild(ModuleItem* child); - /** - * Gets the parent ModuleItem of this ModuleItem. - * - * @returns the parent ModuleItem - */ - ModuleItem* parent(); - /** * Get the child ModuleItem at a certain position in the children list of this ModuleItem. * @@ -120,7 +91,7 @@ namespace hal * * @returns the parent ModuleItem. Returns a constant ModuleItem pointer */ - const ModuleItem* constParent() const; + const BaseTreeItem* constParent() const; /** * Get the child ModuleItem at a certain position in the children list of this ModuleItem. @@ -181,13 +152,6 @@ namespace hal */ TreeItemType getType() const; - /** - * Sets the parent ModuleItem of this ModuleItem. - * - * @param parent - The new parent - */ - void setParent(ModuleItem* parent); - /** * Sets the name of this ModuleItem (not the underlying module). * @@ -204,7 +168,6 @@ namespace hal void setHighlighted(const bool highlighted); private: - ModuleItem* mParent; QList mChildItems; u32 mId; diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index 4c677a9d941..21f76674d6a 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -1,20 +1,20 @@ // MIT License -// +// // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved. // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved. // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved. // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved. -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -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. @@ -115,17 +80,6 @@ namespace hal */ Qt::ItemFlags flags(const QModelIndex& index) const override; - /** - * Returns the data for the given role and section in the header with the specified orientation. - * //Since the model has not headers, an empty QVariant is always returned. // REMOVE THIS LINE? - * - * @param section - The section - * @param orientation - The orientation - * @param role - The role - * @returns the header data. Always empty. - */ - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - // === Others === /** @@ -191,15 +145,15 @@ namespace hal * Recursively adds the given module with all of its submodules (and their submodules and so on...) * and the gates those modules to the item model. * - * @param module - The module which should be added to the item model together with all its + * @param module - The module which should be added to the item model together with all its * submodules, gates and nets. */ void addRecursively(const Module* module); /** - * Updates the parent of the ModuleItem corresponding to the specified module. + * Updates the parent of the ModuleItem corresponding to the specified module. * The new parent must already be set in the Module object. - * + * * @param module - The module whose ModuleItem will be reattached to a new parent in the item model. */ void changeParentModule(const Module* module); @@ -262,8 +216,6 @@ namespace hal */ Module* FindNetParent(const Net* net); - ModuleItem* mTopModuleItem; - QMap mModuleMap; QMap mGateMap; QMap mNetMap; diff --git a/plugins/gui/src/basic_tree_model/base_tree_model.cpp b/plugins/gui/src/basic_tree_model/base_tree_model.cpp index 60f5ddb83cf..764a46ace37 100644 --- a/plugins/gui/src/basic_tree_model/base_tree_model.cpp +++ b/plugins/gui/src/basic_tree_model/base_tree_model.cpp @@ -27,7 +27,7 @@ namespace hal QVariant BaseTreeModel::headerData(int section, Qt::Orientation orientation, int role) const { - if(role == Qt::DisplayRole && orientation == Qt::Horizontal && section < mRootItem->getColumnCount()) + if(role == Qt::DisplayRole && orientation == Qt::Horizontal && section < mRootItem->getColumnCount() && section >= 0) return mRootItem->getData(section); else return QVariant(); diff --git a/plugins/gui/src/module_model/module_item.cpp b/plugins/gui/src/module_model/module_item.cpp index 3719efad404..cbf82f07c87 100644 --- a/plugins/gui/src/module_model/module_item.cpp +++ b/plugins/gui/src/module_model/module_item.cpp @@ -9,7 +9,7 @@ namespace hal { ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : - mParent(nullptr), + BaseTreeItem(), mId(id), mType(type), mHighlighted(false) @@ -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 @@ -68,19 +53,14 @@ ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : mChildItems.prepend(child); } - ModuleItem* ModuleItem::parent() - { - return mParent; - } - ModuleItem* ModuleItem::child(int row) { return mChildItems.value(row); } - const ModuleItem* ModuleItem::constParent() const + const BaseTreeItem* ModuleItem::constParent() const { - return mParent; + return getParent(); } const ModuleItem* ModuleItem::constChild(int row) const @@ -95,8 +75,8 @@ ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : int ModuleItem::row() const { - if (mParent) - return mParent->mChildItems.indexOf(const_cast(this)); + if (getParent()) + return static_cast(getParent())->mChildItems.indexOf(const_cast(this)); else return 0; } @@ -190,11 +170,6 @@ ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : return mType; } - void ModuleItem::setParent(ModuleItem* parent) - { - mParent = parent; - } - void ModuleItem::setName(const QString& name) { mName = name; diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 9619ecbe1c6..c09508e4fe8 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -9,95 +9,10 @@ namespace hal { - ModuleModel::ModuleModel(QObject* parent) : BaseTreeModel(parent), mTopModuleItem(nullptr) + ModuleModel::ModuleModel(QObject* parent) : BaseTreeModel(parent) { - } - - 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); - - // NECESSARY ??? - // if (column != 0) - // return QModelIndex(); - - // // PROBABLY REDUNDANT - // if (parent.isValid() && parent.column() != 0) - // return QModelIndex(); - - // ModuleItem* parent_item = getItem(parent); - // ModuleItem* child_item = parent_item->child(row); - - // if (child_item) - // return createIndex(row, column, child_item); - // else - // return QModelIndex(); - } - - QModelIndex ModuleModel::parent(const QModelIndex& index) const - { - if (!index.isValid()) - return QModelIndex(); - - ModuleItem* item = getItem(index); - - if (item == mTopModuleItem) - return QModelIndex(); - - ModuleItem* parent_item = item->parent(); - return createIndex(parent_item->row(), 0, parent_item); - - // if (!index.isValid()) - // return QModelIndex(); - - // ModuleItem* child_item = getItem(index); - // ModuleItem* parent_item = child_item->parent(); - - // if (parent_item == m_root_item) - // return QModelIndex(); - - // 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; + // use root item to store header information + setHeaderLabels(QStringList() << "Name" << "ID" << "Type"); } QVariant ModuleModel::data(const QModelIndex& index, int role) const @@ -152,20 +67,6 @@ namespace hal return QAbstractItemModel::flags(index); } - QVariant ModuleModel::headerData(int section, Qt::Orientation orientation, int role) const - { - /*Q_UNUSED(section) - Q_UNUSED(orientation) - Q_UNUSED(role) - - return QVariant();*/ - const char* horizontalHeader[] = { "Name", "ID", "Type"}; - if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section < columnCount()) - return QString(horizontalHeader[section]); - - return QVariant(); - } - ModuleItem* ModuleModel::getItem(const QModelIndex& index) const { if (index.isValid()) @@ -181,10 +82,10 @@ 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 = current_item->constParent(); + current_item = static_cast(current_item->constParent()); } QModelIndex model_index = index(0, 0, QModelIndex()); @@ -201,7 +102,7 @@ namespace hal mModuleMap.insert(1, item); beginInsertRows(index(0, 0, QModelIndex()), 0, 0); - mTopModuleItem = item; + mRootItem->appendChild(item); endInsertRows(); Module* m = gNetlist->get_top_module(); @@ -217,15 +118,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(); @@ -247,7 +140,7 @@ namespace hal mModuleMap.insert(id, item); QModelIndex index = getIndex(parent); - + int row = parent->childCount(); mIsModifying = true; beginInsertRows(index, row, row); @@ -320,7 +213,7 @@ namespace hal assert(id != 1); assert(mModuleMap.contains(id)); ModuleItem* item = mModuleMap.value(id); - ModuleItem* oldParent = item->parent(); + ModuleItem* oldParent = static_cast(item->getParent()); assert(oldParent); assert(module->get_parent_module()); @@ -350,7 +243,7 @@ namespace hal assert(mModuleMap.contains(id)); ModuleItem* item = mModuleMap.value(id); - ModuleItem* parent = item->parent(); + ModuleItem* parent = static_cast(item->getParent()); assert(item); assert(parent); @@ -374,7 +267,7 @@ namespace hal assert(mGateMap.contains(id)); ModuleItem* item = mGateMap.value(id); - ModuleItem* parent = item->parent(); + ModuleItem* parent = static_cast(item->getParent()); assert(item); assert(parent); @@ -398,7 +291,7 @@ namespace hal assert(mNetMap.contains(id)); ModuleItem* item = mNetMap.value(id); - ModuleItem* parent = item->parent(); + ModuleItem* parent = static_cast(item->getParent()); assert(item); assert(parent); @@ -422,7 +315,7 @@ namespace hal u32 id = net->get_id(); assert(mNetMap.contains(id)); ModuleItem* item = mNetMap.value(id); - ModuleItem* oldParentItem = item->parent(); + ModuleItem* oldParentItem = static_cast(item->getParent()); assert(oldParentItem); Module* newParentModule = FindNetParent(net); diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index f8b33546608..29c952092b4 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -611,7 +611,7 @@ namespace hal } ModuleItem* selectedItem = getModuleItemFromIndex(mTreeView->currentIndex()); - if(selectedItem->parent() != nullptr) + if(selectedItem->getParent() != nullptr) { gNetlistRelay->deleteModule(getModuleItemFromIndex(mTreeView->currentIndex())->id()); } From f296835b2999783d68a7e090d0e684396710d379 Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 13 Nov 2023 12:51:19 +0100 Subject: [PATCH 27/36] remove the option to delete a module --- plugins/gui/src/module_widget/module_widget.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index 29c952092b4..251a5b5bdd3 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -276,8 +276,8 @@ namespace hal u32 module_id = getModuleItemFromIndex(index)->id(); auto module = gNetlist->get_module_by_id(module_id); - if(!(module == gNetlist->get_top_module()) && type == ModuleItem::TreeItemType::Module) - context_menu.addAction(&delete_action); + /*if(!(module == gNetlist->get_top_module()) && type == ModuleItem::TreeItemType::Module) + context_menu.addAction(&delete_action);*/ QAction* clicked = context_menu.exec(mTreeView->viewport()->mapToGlobal(point)); @@ -327,7 +327,7 @@ namespace hal gNetlistRelay->changeModuleColor(getModuleItemFromIndex(index)->id()); if (clicked == &delete_action){ - gNetlistRelay->deleteModule(getModuleItemFromIndex(index)->id()); + //gNetlistRelay->deleteModule(getModuleItemFromIndex(index)->id()); } if (clicked == &focus_in_view){ @@ -613,7 +613,16 @@ namespace hal ModuleItem* selectedItem = getModuleItemFromIndex(mTreeView->currentIndex()); if(selectedItem->getParent() != nullptr) { - gNetlistRelay->deleteModule(getModuleItemFromIndex(mTreeView->currentIndex())->id()); + switch(getModuleItemFromIndex(mTreeView->currentIndex())->getType()) + { + case ModuleItem::TreeItemType::Module: { + //gNetlistRelay->deleteModule(getModuleItemFromIndex(mTreeView->currentIndex())->id()); + break; + } + case ModuleItem::TreeItemType::Gate: break; + case ModuleItem::TreeItemType::Net: break; + + } } } From 22c0f977c108be1831a104a99d9cd6cee81e8357 Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 13 Nov 2023 14:03:22 +0100 Subject: [PATCH 28/36] add the delete action in the context menu of ModuleWidget --- plugins/gui/src/module_widget/module_widget.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index 251a5b5bdd3..d8089ed3ba0 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -276,8 +276,8 @@ namespace hal u32 module_id = getModuleItemFromIndex(index)->id(); auto module = gNetlist->get_module_by_id(module_id); - /*if(!(module == gNetlist->get_top_module()) && type == ModuleItem::TreeItemType::Module) - context_menu.addAction(&delete_action);*/ + if(!(module == gNetlist->get_top_module()) && type == ModuleItem::TreeItemType::Module) + context_menu.addAction(&delete_action); QAction* clicked = context_menu.exec(mTreeView->viewport()->mapToGlobal(point)); @@ -327,7 +327,7 @@ namespace hal gNetlistRelay->changeModuleColor(getModuleItemFromIndex(index)->id()); if (clicked == &delete_action){ - //gNetlistRelay->deleteModule(getModuleItemFromIndex(index)->id()); + gNetlistRelay->deleteModule(getModuleItemFromIndex(index)->id()); } if (clicked == &focus_in_view){ @@ -616,7 +616,7 @@ namespace hal switch(getModuleItemFromIndex(mTreeView->currentIndex())->getType()) { case ModuleItem::TreeItemType::Module: { - //gNetlistRelay->deleteModule(getModuleItemFromIndex(mTreeView->currentIndex())->id()); + gNetlistRelay->deleteModule(getModuleItemFromIndex(mTreeView->currentIndex())->id()); break; } case ModuleItem::TreeItemType::Gate: break; From 73afaba2712bfc28adf24d2c0bc2e8874eb66588 Mon Sep 17 00:00:00 2001 From: joern274 Date: Mon, 13 Nov 2023 21:20:35 +0100 Subject: [PATCH 29/36] Removed everything from class ModuleItem which is already coverd in base class --- .../gui/basic_tree_model/base_tree_item.h | 2 +- .../include/gui/module_model/module_item.h | 40 ------------------ .../src/basic_tree_model/base_tree_item.cpp | 2 +- plugins/gui/src/module_model/module_item.cpp | 42 ++++--------------- plugins/gui/src/module_model/module_model.cpp | 12 +++--- .../src/module_model/module_proxy_model.cpp | 4 +- 6 files changed, 18 insertions(+), 84 deletions(-) diff --git a/plugins/gui/include/gui/basic_tree_model/base_tree_item.h b/plugins/gui/include/gui/basic_tree_model/base_tree_item.h index 68f5ea461a9..ae9a9efe332 100644 --- a/plugins/gui/include/gui/basic_tree_model/base_tree_item.h +++ b/plugins/gui/include/gui/basic_tree_model/base_tree_item.h @@ -184,7 +184,7 @@ namespace hal * @param child - The child for which the row is requested. * @return The row if the item is a child, -1 otherwise. */ - virtual int getRowForChild(BaseTreeItem* child) const; + virtual int getRowForChild(const BaseTreeItem* child) const; /** * Convenience method to get the row of this item within diff --git a/plugins/gui/include/gui/module_model/module_item.h b/plugins/gui/include/gui/module_model/module_item.h index 379fa6726d3..49bbdc9288b 100644 --- a/plugins/gui/include/gui/module_model/module_item.h +++ b/plugins/gui/include/gui/module_model/module_item.h @@ -71,44 +71,6 @@ namespace hal */ void appendExistingChildIfAny(const QMap& moduleMap); - /** - * Inserts a child ModuleItem at the beginning of the children list of this ModuleItem. - * - * @param child - The child to be prepended - */ - void prependChild(ModuleItem* child); - - /** - * Get the child ModuleItem at a certain position in the children list of this ModuleItem. - * - * @param row - The position in the children list of this ModuleItem - * @returns then children ModuleItem at the specified position in the children list - */ - ModuleItem* child(int row); - - /** - * Gets the parent ModuleItem of this ModuleItem. - * - * @returns the parent ModuleItem. Returns a constant ModuleItem pointer - */ - const BaseTreeItem* constParent() const; - - /** - * Get the child ModuleItem at a certain position in the children list of this ModuleItem. - * - * @param row - The position in the children list of this ModuleItem - * @returns then children ModuleItem at the specified position in the children list. - * Returns a constant ModuleItem pointer - */ - const ModuleItem* constChild(int row) const; - - /** - * Gets the current amount of children of this ModuleItem. - * - * @returns the amount of children - */ - int childCount() const; - /** * Gets the data of this item model item i.e. the name of this ModuleItem if column=1. * @@ -168,8 +130,6 @@ namespace hal void setHighlighted(const bool highlighted); private: - QList mChildItems; - u32 mId; TreeItemType mType; QString mName; diff --git a/plugins/gui/src/basic_tree_model/base_tree_item.cpp b/plugins/gui/src/basic_tree_model/base_tree_item.cpp index c0d0ce9e539..d0209984816 100644 --- a/plugins/gui/src/basic_tree_model/base_tree_item.cpp +++ b/plugins/gui/src/basic_tree_model/base_tree_item.cpp @@ -77,7 +77,7 @@ namespace hal return mChildren.size(); } - int BaseTreeItem::getRowForChild(BaseTreeItem *child) const + int BaseTreeItem::getRowForChild(const BaseTreeItem *child) const { int index = -1; for(int i = 0; i < mChildren.size(); i++) diff --git a/plugins/gui/src/module_model/module_item.cpp b/plugins/gui/src/module_model/module_item.cpp index cbf82f07c87..cf5a79bcc56 100644 --- a/plugins/gui/src/module_model/module_item.cpp +++ b/plugins/gui/src/module_model/module_item.cpp @@ -28,6 +28,14 @@ ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : } } + int ModuleItem::row() const + { + BaseTreeItem* parent = getParent(); + if (!parent) return 0; + return parent->getRowForChild(this); + } + + void ModuleItem::appendExistingChildIfAny(const QMap& moduleMap) { if(mType != TreeItemType::Module) // only module can have children @@ -47,40 +55,6 @@ ModuleItem::ModuleItem(const u32 id, const TreeItemType type) : } } - void ModuleItem::prependChild(ModuleItem* child) - { - // PROBABLY OBSOLETE - mChildItems.prepend(child); - } - - ModuleItem* ModuleItem::child(int row) - { - return mChildItems.value(row); - } - - const BaseTreeItem* ModuleItem::constParent() const - { - return getParent(); - } - - const ModuleItem* ModuleItem::constChild(int row) const - { - return mChildItems.value(row); - } - - int ModuleItem::childCount() const - { - return mChildItems.count(); - } - - int ModuleItem::row() const - { - if (getParent()) - return static_cast(getParent())->mChildItems.indexOf(const_cast(this)); - else - return 0; - } - QVariant ModuleItem::getData(int column) const { // DEBUG CODE, USE STYLED DELEGATES OR SOMETHING diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index c09508e4fe8..9a9e0285915 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -85,7 +85,7 @@ namespace hal while (current_item != mRootItem->getChild(0)) { row_numbers.append(current_item->row()); - current_item = static_cast(current_item->constParent()); + current_item = static_cast(current_item->getParent()); } QModelIndex model_index = index(0, 0, QModelIndex()); @@ -141,7 +141,7 @@ namespace hal QModelIndex index = getIndex(parent); - int row = parent->childCount(); + int row = parent->getChildCount(); mIsModifying = true; beginInsertRows(index, row, row); parent->appendChild(item); @@ -164,7 +164,7 @@ namespace hal QModelIndex index = getIndex(parent); - int row = parent->childCount(); + int row = parent->getChildCount(); mIsModifying = true; beginInsertRows(index, row, row); parent->appendChild(item); @@ -188,7 +188,7 @@ namespace hal QModelIndex index = getIndex(parent); - int row = parent->childCount(); + int row = parent->getChildCount(); mIsModifying = true; beginInsertRows(index, row, row); parent->appendChild(item); @@ -228,7 +228,7 @@ namespace hal int row = item->row(); mIsModifying = true; - beginMoveRows(oldIndex, row, row, newIndex, newParent->childCount()); + beginMoveRows(oldIndex, row, row, newIndex, newParent->getChildCount()); oldParent->removeChild(item); newParent->appendChild(item); item->setParent(newParent); @@ -331,7 +331,7 @@ namespace hal int row = item->row(); mIsModifying = true; - beginMoveRows(oldIndex, row, row, newIndex, newParentItem->childCount()); + beginMoveRows(oldIndex, row, row, newIndex, newParentItem->getChildCount()); oldParentItem->removeChild(item); newParentItem->appendChild(item); item->setParent(newParentItem); diff --git a/plugins/gui/src/module_model/module_proxy_model.cpp b/plugins/gui/src/module_model/module_proxy_model.cpp index cddf8ae44fa..95ae3f3dff3 100644 --- a/plugins/gui/src/module_model/module_proxy_model.cpp +++ b/plugins/gui/src/module_model/module_proxy_model.cpp @@ -43,12 +43,12 @@ namespace hal if(filterRegularExpression().pattern().isEmpty()) return true; - if(item->childCount() == 0) + if(item->getChildCount() == 0) return sourceModel()->data(sourceIndex, filterRole()).toString().contains(filterRegularExpression()); bool shouldBeDisplayed = sourceModel()->data(sourceIndex, filterRole()).toString().contains(filterRegularExpression());; //go through all children and return the check of itself and the check of the children - for(int i = 0; i < item->childCount(); i++) + for(int i = 0; i < item->getChildCount(); i++) { shouldBeDisplayed = shouldBeDisplayed || filterAcceptsRow(i, sourceIndex); } From 88d3136702edc7ceabc09fb888f32a1e2bd892c6 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 15 Nov 2023 20:41:13 +0100 Subject: [PATCH 30/36] fix wrong deletion of topModule --- plugins/gui/src/module_widget/module_widget.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index d8089ed3ba0..0284d4b2057 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -616,6 +616,9 @@ namespace hal switch(getModuleItemFromIndex(mTreeView->currentIndex())->getType()) { case ModuleItem::TreeItemType::Module: { + auto module = gNetlist->get_module_by_id(selectedItem->id()); + if((module == gNetlist->get_top_module())) + break; gNetlistRelay->deleteModule(getModuleItemFromIndex(mTreeView->currentIndex())->id()); break; } From 73da0749ab23f67638bade846d5a4a09054ad03b Mon Sep 17 00:00:00 2001 From: Skaleee <78816681+Skaleee@users.noreply.github.com> Date: Wed, 15 Nov 2023 21:49:45 +0100 Subject: [PATCH 31/36] Changes to Gate or Module positions now affect connected net. --- .../include/gui/module_model/module_model.h | 49 +++++--- plugins/gui/src/module_model/module_model.cpp | 109 +++++++++++------- .../gui/src/netlist_relay/netlist_relay.cpp | 22 ++-- 3 files changed, 111 insertions(+), 69 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index 21f76674d6a..f64314886d4 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -150,50 +150,67 @@ namespace hal */ void addRecursively(const Module* module); - /** - * Updates the parent of the ModuleItem corresponding to the specified module. - * The new parent must already be set in the Module object. - * - * @param module - The module whose ModuleItem will be reattached to a new parent in the item model. - */ - void changeParentModule(const Module* module); - /** * Removes a module from the item model. The specified module MUST be contained in the item model. * * @param id - The id of the module to remove */ - void remove_module(const u32 id); + void removeModule(const u32 id); /** * Removes a gate from the item model. The specified gate MUST be contained in the item model. * * @param id - The id of the gate to remove */ - void remove_gate(const u32 id); + void removeGate(const u32 id); /** - * Removes a net from the item model. The specified net MUST be contained in the item model. + * Removes a net from the item model. * * @param id - The id of the net to remove */ - void remove_net(const u32 id); + void removeNet(const u32 id); + + /** + * Moves the ModuleItem corresponding to the module under it's new parent ModuleItem. + * The items for all nets, that have at least one source or one destination within the module, + * will be updated afterwards. + * + * @param module The module whose parent has changed. + */ + void handleModuleParentChanged(const Module* module); + + /** + * Handles the assigment of gates to modules. + * If the gate does not yet exist in the item model, a new one is created. + * All nets, that are connected to the gate, will be updated. + */ + void handleModuleGateAssinged(const u32 id, const u32 parent_module); /** * Updates the position of a net in the ModuleTree. * The net will be placed under the deepest module, that contains all sources and destinations of the net. * If no suitable parent could be found, then the net will instead be placed under the top module. + * If the net does not exist in the item model (e.g. it's a global net), then nothing is updated. * - * @param net The net whose source or destination changed. + * @param net The net whose source or destination might have changed. + */ + void updateNet(const Net* net); + + /** + * Reattaches the ModuleItem corresponding to the specified module to a new parent item. + * The new parent must already be set in the Module object. + * + * @param module - The module whose ModuleItem will be reattached to a new parent in the item model. */ - void handleNetSourceOrDestinationChanged(const Net* net); + void updateModuleParent(const Module* module); /** * Updates the ModuleItem for the specified module. The specified module MUST be contained in the item model. * * @param id - The id of the module to update */ - void updateModule(const u32 id); + void updateModuleName(const u32 id); /** * Returns true if the item model is currently changed/updated. This is the case while adding and @@ -214,7 +231,7 @@ namespace hal * @return The new parent module, that contains all sources and destinations of net. If no such parent could be found * (e.g. net has no sources or destinations), nullptr is returned instead. */ - Module* FindNetParent(const Net* net); + Module* findNetParent(const Net* net); QMap mModuleMap; QMap mGateMap; diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 9a9e0285915..8526cdc4bf1 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -110,7 +110,7 @@ namespace hal for(auto net : gNetlist->get_top_module()->get_internal_nets()) { addNet(net->get_id(), m->get_id()); - handleNetSourceOrDestinationChanged(net); + updateNet(net); } } @@ -172,7 +172,6 @@ namespace hal endInsertRows(); } - void ModuleModel::addNet(u32 id, u32 parent_module) { assert(gNetlist->get_net_by_id(id)); @@ -207,36 +206,7 @@ namespace hal addGate(g->get_id(), module->get_id()); } - void ModuleModel::changeParentModule(const Module* module){ - assert(module); - u32 id = module->get_id(); - assert(id != 1); - assert(mModuleMap.contains(id)); - ModuleItem* item = mModuleMap.value(id); - ModuleItem* oldParent = static_cast(item->getParent()); - assert(oldParent); - - assert(module->get_parent_module()); - if(oldParent->id() == module->get_parent_module()->get_id()) - return; - - assert(mModuleMap.contains(module->get_parent_module()->get_id())); - ModuleItem* newParent = mModuleMap.value(module->get_parent_module()->get_id()); - - QModelIndex oldIndex = getIndex(oldParent); - QModelIndex newIndex = getIndex(newParent); - int row = item->row(); - - mIsModifying = true; - beginMoveRows(oldIndex, row, row, newIndex, newParent->getChildCount()); - oldParent->removeChild(item); - newParent->appendChild(item); - item->setParent(newParent); - mIsModifying = false; - endMoveRows(); - } - - void ModuleModel::remove_module(const u32 id) + void ModuleModel::removeModule(const u32 id) { assert(id != 1); // module was most likely already purged from netlist @@ -261,7 +231,7 @@ namespace hal delete item; } - void ModuleModel::remove_gate(const u32 id) + void ModuleModel::removeGate(const u32 id) { //assert(gNetlist->get_gate_by_id(id)); assert(mGateMap.contains(id)); @@ -285,10 +255,11 @@ namespace hal delete item; } - void ModuleModel::remove_net(const u32 id) + void ModuleModel::removeNet(const u32 id) { //assert(gNetlist->get_net_by_id(id)); - assert(mNetMap.contains(id)); + if(!mNetMap.contains(id)) // global nets are not contained in the item model + return; ModuleItem* item = mNetMap.value(id); ModuleItem* parent = static_cast(item->getParent()); @@ -309,16 +280,43 @@ namespace hal delete item; } - void ModuleModel::handleNetSourceOrDestinationChanged(const Net* net) + void ModuleModel::handleModuleParentChanged(const Module* module) + { + assert(module); + updateModuleParent(module); + + for(Net* net : module->get_nets()) + updateNet(net); + } + + void ModuleModel::handleModuleGateAssinged(const u32 id, const u32 parent_module) + { + // Don't need new function handleModuleGateRemoved(), because the GateAssinged event always follows GateRemoved + // or NetlistInternalManager updates Net connections when a gate is deleted. + + if(!mGateMap.contains(id)) + addGate(id, parent_module); + + Gate* gate = gNetlist->get_gate_by_id(id); + for(Net* in_net : gate->get_fan_in_nets()) + updateNet(in_net); + for(Net* in_net : gate->get_fan_out_nets()) + updateNet(in_net); + } + + void ModuleModel::updateNet(const Net* net) { assert(net); u32 id = net->get_id(); - assert(mNetMap.contains(id)); + + if(!mNetMap.contains(id)) + return; + ModuleItem* item = mNetMap.value(id); ModuleItem* oldParentItem = static_cast(item->getParent()); assert(oldParentItem); - - Module* newParentModule = FindNetParent(net); + + Module* newParentModule = findNetParent(net); if(newParentModule == nullptr) newParentModule = gNetlist->get_top_module(); if(newParentModule->get_id() == oldParentItem->id()) @@ -334,12 +332,39 @@ namespace hal beginMoveRows(oldIndex, row, row, newIndex, newParentItem->getChildCount()); oldParentItem->removeChild(item); newParentItem->appendChild(item); - item->setParent(newParentItem); mIsModifying = false; endMoveRows(); } - void ModuleModel::updateModule(u32 id) // SPLIT ??? + void ModuleModel::updateModuleParent(const Module* module){ + assert(module); + u32 id = module->get_id(); + assert(id != 1); + assert(mModuleMap.contains(id)); + ModuleItem* item = mModuleMap.value(id); + ModuleItem* oldParent = static_cast(item->getParent()); + assert(oldParent); + + assert(module->get_parent_module()); + if(oldParent->id() == module->get_parent_module()->get_id()) + return; + + assert(mModuleMap.contains(module->get_parent_module()->get_id())); + ModuleItem* newParent = mModuleMap.value(module->get_parent_module()->get_id()); + + QModelIndex oldIndex = getIndex(oldParent); + QModelIndex newIndex = getIndex(newParent); + int row = item->row(); + + mIsModifying = true; + beginMoveRows(oldIndex, row, row, newIndex, newParent->getChildCount()); + oldParent->removeChild(item); + newParent->appendChild(item); + mIsModifying = false; + endMoveRows(); + } + + void ModuleModel::updateModuleName(u32 id) // SPLIT ??? { assert(gNetlist->get_module_by_id(id)); assert(mModuleMap.contains(id)); @@ -363,7 +388,7 @@ namespace hal return mIsModifying; } - Module* ModuleModel::FindNetParent(const Net* net){ + Module* ModuleModel::findNetParent(const Net* net){ // cannot use Module::get_internal_nets(), because currently that function is implemented so, // that a net can be "internal" to multiple modules at the same depth. // => instead manually search for deepest module, that contains all sources and destinations of net. diff --git a/plugins/gui/src/netlist_relay/netlist_relay.cpp b/plugins/gui/src/netlist_relay/netlist_relay.cpp index 600d89e8ac7..faa6942fdbb 100644 --- a/plugins/gui/src/netlist_relay/netlist_relay.cpp +++ b/plugins/gui/src/netlist_relay/netlist_relay.cpp @@ -393,7 +393,7 @@ namespace hal //< no associated_data mModuleColorManager->removeColor(mod->get_id()); - mModuleModel->remove_module(mod->get_id()); + mModuleModel->removeModule(mod->get_id()); gGraphContextManager->handleModuleRemoved(mod); gSelectionRelay->handleModuleRemoved(mod->get_id()); @@ -404,7 +404,7 @@ namespace hal case ModuleEvent::event::name_changed: { //< no associated_data - mModuleModel->updateModule(mod->get_id()); + mModuleModel->updateModuleName(mod->get_id()); gGraphContextManager->handleModuleNameChanged(mod); @@ -414,7 +414,7 @@ namespace hal case ModuleEvent::event::parent_changed: { //< no associated_data - mModuleModel->changeParentModule(mod); + mModuleModel->handleModuleParentChanged(mod); Q_EMIT moduleParentChanged(mod); break; @@ -438,8 +438,7 @@ namespace hal case ModuleEvent::event::gate_assigned: { //< associated_data = id of inserted gate - mModuleModel->addGate(associated_data, mod->get_id()); - + mModuleModel->handleModuleGateAssinged(associated_data, mod->get_id()); gGraphContextManager->handleModuleGateAssigned(mod, associated_data); Q_EMIT moduleGateAssigned(mod, associated_data); @@ -448,8 +447,7 @@ namespace hal case ModuleEvent::event::gate_removed: { //< associated_data = id of removed gate - mModuleModel->remove_gate(associated_data); - + mModuleModel->removeGate(associated_data); gGraphContextManager->handleModuleGateRemoved(mod, associated_data); Q_EMIT moduleGateRemoved(mod, associated_data); @@ -581,6 +579,7 @@ namespace hal case NetEvent::event::created: { //< no associated_data + mModuleModel->addNet(net->get_id(), gNetlist->get_top_module()->get_id()); gGraphContextManager->handleNetCreated(net); Q_EMIT netCreated(net); @@ -589,6 +588,7 @@ namespace hal case NetEvent::event::removed: { //< no associated_data + mModuleModel->removeNet(net->get_id()); gGraphContextManager->handleNetRemoved(net); gSelectionRelay->handleNetRemoved(net->get_id()); @@ -616,7 +616,7 @@ namespace hal case NetEvent::event::src_added: { //< associated_data = id of src gate - mModuleModel->handleNetSourceOrDestinationChanged(net); + mModuleModel->updateNet(net); gGraphContextManager->handleNetSourceAdded(net, associated_data); Q_EMIT netSourceAdded(net, associated_data); @@ -625,7 +625,7 @@ namespace hal case NetEvent::event::src_removed: { //< associated_data = id of src gate - mModuleModel->handleNetSourceOrDestinationChanged(net); + mModuleModel->updateNet(net); gGraphContextManager->handleNetSourceRemoved(net, associated_data); Q_EMIT netSourceRemoved(net, associated_data); @@ -634,7 +634,7 @@ namespace hal case NetEvent::event::dst_added: { //< associated_data = id of dst gate - mModuleModel->handleNetSourceOrDestinationChanged(net); + mModuleModel->updateNet(net); gGraphContextManager->handleNetDestinationAdded(net, associated_data); Q_EMIT netDestinationAdded(net, associated_data); @@ -643,7 +643,7 @@ namespace hal case NetEvent::event::dst_removed: { //< associated_data = id of dst gate - mModuleModel->handleNetSourceOrDestinationChanged(net); + mModuleModel->updateNet(net); gGraphContextManager->handleNetDestinationRemoved(net, associated_data); Q_EMIT netDestinationRemoved(net, associated_data); From 7810c670de30fc3c93970050ece603f3e0ae1b90 Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 16 Nov 2023 12:53:42 +0100 Subject: [PATCH 32/36] fix the naming of gates in modulemodel --- .../gui/include/gui/module_model/module_model.h | 7 +++++++ plugins/gui/src/module_model/module_model.cpp | 15 +++++++++++++++ plugins/gui/src/netlist_relay/netlist_relay.cpp | 1 + 3 files changed, 23 insertions(+) diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index f64314886d4..5a2b3714ba8 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -212,6 +212,13 @@ namespace hal */ void updateModuleName(const u32 id); + /** + * Updates the ModuleItem for the specified gate. The specified gate MUST be contained in the item model. + * + * @param id - The id of the gate to update + */ + void updateGateName(const u32 id); + /** * Returns true if the item model is currently changed/updated. This is the case while adding and * removing modules to/from the item model. It can be used to ignore certain signals sent by the item model diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 8526cdc4bf1..98821047b6a 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -378,6 +378,21 @@ namespace hal Q_EMIT dataChanged(index, index); } + void ModuleModel::updateGateName(u32 id) // SPLIT ??? + { + assert(gNetlist->get_gate_by_id(id)); + + assert(mGateMap.contains(id)); + + ModuleItem* item = mGateMap.value(id); + assert(item); + + item->setName(QString::fromStdString(gNetlist->get_gate_by_id(id)->get_name())); // REMOVE & ADD AGAIN + + QModelIndex index = getIndex(item); + Q_EMIT dataChanged(index, index); + } + ModuleItem* ModuleModel::getItem(u32 id, ModuleItem::TreeItemType type) const { return mModuleItemMaps[(int)type]->value(id); diff --git a/plugins/gui/src/netlist_relay/netlist_relay.cpp b/plugins/gui/src/netlist_relay/netlist_relay.cpp index faa6942fdbb..060a8af897b 100644 --- a/plugins/gui/src/netlist_relay/netlist_relay.cpp +++ b/plugins/gui/src/netlist_relay/netlist_relay.cpp @@ -535,6 +535,7 @@ namespace hal case GateEvent::event::name_changed: { //< no associated_data + mModuleModel->updateGateName(gat->get_id()); gGraphContextManager->handleGateNameChanged(gat); Q_EMIT gateNameChanged(gat); From 1a28718d657ef34da596e53bc35ff98b029db260 Mon Sep 17 00:00:00 2001 From: Skaleee <78816681+Skaleee@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:41:29 +0100 Subject: [PATCH 33/36] Added Context Action for renaming nets --- .../include/gui/module_model/module_model.h | 7 ++++++ .../include/gui/module_widget/module_widget.h | 1 + plugins/gui/src/module_model/module_model.cpp | 19 +++++++++++++--- .../gui/src/module_widget/module_widget.cpp | 22 ++++++++++++++++++- .../gui/src/netlist_relay/netlist_relay.cpp | 1 + 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index 5a2b3714ba8..7baaf7bb281 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -219,6 +219,13 @@ namespace hal */ void updateGateName(const u32 id); + /** + * Updates the ModuleItem for the specified net. The specified gate MUST be contained in the item model. + * + * @param id - The id of the net to update + */ + void updateNetName(const u32 id); + /** * Returns true if the item model is currently changed/updated. This is the case while adding and * removing modules to/from the item model. It can be used to ignore certain signals sent by the item model diff --git a/plugins/gui/include/gui/module_widget/module_widget.h b/plugins/gui/include/gui/module_widget/module_widget.h index f52387597a9..01b91bd8620 100644 --- a/plugins/gui/include/gui/module_widget/module_widget.h +++ b/plugins/gui/include/gui/module_widget/module_widget.h @@ -248,6 +248,7 @@ namespace hal void changeGateName(const QModelIndex& index); + void changeNetName(const QModelIndex& index); ModuleItem* getModuleItemFromIndex(const QModelIndex& index); diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 98821047b6a..7c645b97364 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -364,7 +364,7 @@ namespace hal endMoveRows(); } - void ModuleModel::updateModuleName(u32 id) // SPLIT ??? + void ModuleModel::updateModuleName(u32 id) { assert(gNetlist->get_module_by_id(id)); assert(mModuleMap.contains(id)); @@ -378,10 +378,9 @@ namespace hal Q_EMIT dataChanged(index, index); } - void ModuleModel::updateGateName(u32 id) // SPLIT ??? + void ModuleModel::updateGateName(u32 id) { assert(gNetlist->get_gate_by_id(id)); - assert(mGateMap.contains(id)); ModuleItem* item = mGateMap.value(id); @@ -393,6 +392,20 @@ namespace hal Q_EMIT dataChanged(index, index); } + void ModuleModel::updateNetName(u32 id) + { + assert(gNetlist->get_net_by_id(id)); + assert(mNetMap.contains(id)); + + ModuleItem* item = mNetMap.value(id); + assert(item); + + item->setName(QString::fromStdString(gNetlist->get_net_by_id(id)->get_name())); // REMOVE & ADD AGAIN + + QModelIndex index = getIndex(item); + Q_EMIT dataChanged(index, index); + } + ModuleItem* ModuleModel::getItem(u32 id, ModuleItem::TreeItemType type) const { return mModuleItemMaps[(int)type]->value(id); diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index 0284d4b2057..22078141a6c 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -243,6 +243,9 @@ namespace hal extractPythonAction.setText("Extract Net as python code (copy to clipboard)"); extractPythonAction.setParent(&context_menu); + change_name_action.setText("Change Net name"); + change_name_action.setParent(&context_menu); + focus_in_view.setText("Focus item in Graph View"); focus_in_view.setParent(&context_menu); break; @@ -270,6 +273,7 @@ namespace hal if (type == ModuleItem::TreeItemType::Net){ context_menu.addAction(&extractPythonAction); + context_menu.addAction(&change_name_action); context_menu.addAction(&focus_in_view); } @@ -317,6 +321,7 @@ namespace hal { case ModuleItem::TreeItemType::Module: gNetlistRelay->changeModuleName(getModuleItemFromIndex(index)->id()); break; case ModuleItem::TreeItemType::Gate: changeGateName(index); break; + case ModuleItem::TreeItemType::Net: changeNetName(index); break; } } @@ -416,7 +421,7 @@ namespace hal QString oldName = getModuleItemFromIndex(index)->name(); bool confirm; - QString newName = QInputDialog::getText(this, "Change gate name", "New name:", QLineEdit::Normal, oldName, &confirm); + QString newName = QInputDialog::getText(this, "Rename Gate", "New name:", QLineEdit::Normal, oldName, &confirm); if (confirm && !newName.isEmpty()) { @@ -426,6 +431,21 @@ namespace hal } } + void ModuleWidget::changeNetName(const QModelIndex &index) + { + QString oldName = getModuleItemFromIndex(index)->name(); + + bool confirm; + QString newName = QInputDialog::getText(this, "Rename Net", "New name:", QLineEdit::Normal, oldName, &confirm); + + if (confirm && !newName.isEmpty()) + { + ActionRenameObject* act = new ActionRenameObject(newName); + act->setObject(UserActionObject(getModuleItemFromIndex(index)->id(), UserActionObjectType::ObjectType::Net)); + act->exec(); + } + } + void ModuleWidget::openModuleInView(u32 moduleId, bool unfold) { const Module* module = gNetlist->get_module_by_id(moduleId); diff --git a/plugins/gui/src/netlist_relay/netlist_relay.cpp b/plugins/gui/src/netlist_relay/netlist_relay.cpp index 060a8af897b..1132ffc8db2 100644 --- a/plugins/gui/src/netlist_relay/netlist_relay.cpp +++ b/plugins/gui/src/netlist_relay/netlist_relay.cpp @@ -599,6 +599,7 @@ namespace hal case NetEvent::event::name_changed: { //< no associated_data + mModuleModel->updateNetName(net->get_id()); gGraphContextManager->handleNetNameChanged(net); Q_EMIT netNameChanged(net); From 2c03bf4545c6a622237eafff6222a5b36f659ce0 Mon Sep 17 00:00:00 2001 From: Skaleee <78816681+Skaleee@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:50:02 +0100 Subject: [PATCH 34/36] gates and nets are now hidden by default in ModuleWidget --- plugins/gui/src/module_model/module_proxy_model.cpp | 2 +- plugins/gui/src/module_widget/module_widget.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/gui/src/module_model/module_proxy_model.cpp b/plugins/gui/src/module_model/module_proxy_model.cpp index 95ae3f3dff3..ec5ca9e7123 100644 --- a/plugins/gui/src/module_model/module_proxy_model.cpp +++ b/plugins/gui/src/module_model/module_proxy_model.cpp @@ -5,7 +5,7 @@ namespace hal { - ModuleProxyModel::ModuleProxyModel(QObject* parent) : QSortFilterProxyModel(parent), mSortMechanism(gui_utility::mSortMechanism::lexical), mFilterNets(false), mFilterGates(false) + ModuleProxyModel::ModuleProxyModel(QObject* parent) : QSortFilterProxyModel(parent), mSortMechanism(gui_utility::mSortMechanism::lexical), mFilterNets(true), mFilterGates(true) { // QTS PROXY MODELS ARE DUMB, IMPLEMENT CUSTOM SOLUTION OR SWITCH TO A DIFFERENT FILTER METHOD diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index 22078141a6c..36d4dc6c915 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -46,8 +46,8 @@ namespace hal connect(mTreeView, &QTreeView::customContextMenuRequested, this, &ModuleWidget::handleTreeViewContextMenuRequested); - mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mShowNetsIconStyle, mShowNetsIconPath)); - mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mShowGatesIconStyle, mShowGatesIconPath)); + mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mHideNetsIconStyle, mHideNetsIconPath)); + mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mHideGatesIconStyle, mHideGatesIconPath)); mSearchAction->setIcon(gui_utility::getStyledSvgIcon(mSearchIconStyle, mSearchIconPath)); mToggleNetsAction->setToolTip("Toggle Net Visibility"); From ebe1a7702cf2b8f64d0e08a535cdbf93009cc674 Mon Sep 17 00:00:00 2001 From: Skaleee <78816681+Skaleee@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:37:54 +0100 Subject: [PATCH 35/36] Adjusted column spacing in ModuleWidget --- plugins/gui/include/gui/module_widget/module_tree_view.h | 5 +++++ plugins/gui/src/module_widget/module_tree_view.cpp | 9 +++++++++ plugins/gui/src/module_widget/module_widget.cpp | 1 + 3 files changed, 15 insertions(+) diff --git a/plugins/gui/include/gui/module_widget/module_tree_view.h b/plugins/gui/include/gui/module_widget/module_tree_view.h index e143a09b7cb..5710163fce7 100644 --- a/plugins/gui/include/gui/module_widget/module_tree_view.h +++ b/plugins/gui/include/gui/module_widget/module_tree_view.h @@ -56,5 +56,10 @@ namespace hal * @param event */ void mousePressEvent(QMouseEvent* event); + + /** + * Sets the default width of each column. MUST be called after setting the model. + */ + void setDefaultColumnWidth(); }; } // namespace hal diff --git a/plugins/gui/src/module_widget/module_tree_view.cpp b/plugins/gui/src/module_widget/module_tree_view.cpp index 65643141fec..cd0a168dcbe 100644 --- a/plugins/gui/src/module_widget/module_tree_view.cpp +++ b/plugins/gui/src/module_widget/module_tree_view.cpp @@ -1,5 +1,6 @@ #include "gui/module_widget/module_tree_view.h" #include +#include namespace hal { @@ -7,6 +8,14 @@ namespace hal { } + void ModuleTreeView::setDefaultColumnWidth() + { + setColumnWidth(0, 240); + setColumnWidth(1, 40); + setColumnWidth(2, 80); + header()->setStretchLastSection(true); + } + void ModuleTreeView::mousePressEvent(QMouseEvent *event) { if(event->button() != Qt::RightButton) diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index 36d4dc6c915..063c36cf559 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -60,6 +60,7 @@ namespace hal //mModuleProxyModel->setRecursiveFilteringEnabled(true); mModuleProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); mTreeView->setModel(mModuleProxyModel); + mTreeView->setDefaultColumnWidth(); mTreeView->setSortingEnabled(true); mTreeView->sortByColumn(0, Qt::AscendingOrder); mTreeView->setContextMenuPolicy(Qt::CustomContextMenu); From cd7d94110875ad13e24fa42c67f436adbb90b7d0 Mon Sep 17 00:00:00 2001 From: joern274 Date: Fri, 17 Nov 2023 20:52:07 +0100 Subject: [PATCH 36/36] Fixed minor layout bug found during module tree branch test --- plugins/gui/src/graph_widget/layouters/graph_layouter.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/gui/src/graph_widget/layouters/graph_layouter.cpp b/plugins/gui/src/graph_widget/layouters/graph_layouter.cpp index e1918230993..dae127f6260 100644 --- a/plugins/gui/src/graph_widget/layouters/graph_layouter.cpp +++ b/plugins/gui/src/graph_widget/layouters/graph_layouter.cpp @@ -945,8 +945,10 @@ namespace hal graphicsNet = san; int yGridPos = mGlobalInputHash.value(dnt->id(), -1); Q_ASSERT(yGridPos >= 0); - const EndpointCoordinate& epc = mEndpointHash.value(QPoint(mNodeBoundingBox.left(), yGridPos * 2)); - san->setInputPosition(QPointF(mCoordArrayX->lanePosition(mNodeBoundingBox.left(),0), epc.lanePosition(0, true))); + QPoint pnt(mNodeBoundingBox.left(), yGridPos * 2); + const EndpointCoordinate& epc = mEndpointHash.value(pnt); + const NetLayoutJunction* nlj = mJunctionHash.value(pnt); + san->setInputPosition(QPointF(mCoordArrayX->lanePosition(mNodeBoundingBox.left(),nlj?nlj->rect().left():0), epc.lanePosition(0, true))); } if (epl.hasOutputArrow()) {