diff --git a/plugins/gui/include/gui/graph_widget/graphics_scene.h b/plugins/gui/include/gui/graph_widget/graphics_scene.h index a9965e749e8..ba7b852f560 100644 --- a/plugins/gui/include/gui/graph_widget/graphics_scene.h +++ b/plugins/gui/include/gui/graph_widget/graphics_scene.h @@ -28,7 +28,7 @@ #include "gui/graph_widget/items/utility_items/node_drag_shadow.h" #include "gui/graph_widget/shaders/graph_shader.h" #include "gui/gui_globals.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" +#include "gui/module_model/module_item.h" #include "gui/graph_widget/graphics_qss_adapter.h" #include "hal_core/defines.h" #include "hal_core/netlist/gate.h" @@ -234,7 +234,7 @@ namespace hal * * @param highlightItems - The selection tree items to highlight */ - void handleHighlight(const QVector& highlightItems); + void handleHighlight(const QVector& highlightItems); /** * Q_SLOT to call whenever a module was assigned to or removed from a grouping. It is used to update the diff --git a/plugins/gui/include/gui/module_model/module_item.h b/plugins/gui/include/gui/module_model/module_item.h index f34143e088c..b4d377484d9 100644 --- a/plugins/gui/include/gui/module_model/module_item.h +++ b/plugins/gui/include/gui/module_model/module_item.h @@ -61,7 +61,7 @@ namespace hal * @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); + ModuleItem(const u32 id, const TreeItemType type); /** * Given a set of ModuleItems (in a map [id]->[ModuleItem]) this function adds each ModuleItem of this set as diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index fd0e5c01755..3a3ef453df9 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -114,7 +114,7 @@ namespace hal ModuleItem* getItem(const QModelIndex& index) const; /** - * Returns the ModuleItem for a specified id and type. + * Returns the first ModuleItem for a specified id and type. * * @param module_id - The id of the ModuleItem * @param type - The type of the ModuleItem @@ -122,6 +122,15 @@ namespace hal */ ModuleItem* getItem(const u32 id, ModuleItem::TreeItemType type = ModuleItem::TreeItemType::Module) const; + /** + * Returns all ModuleItems for a specified id and type. + * + * @param module_id - The id of the ModuleItems + * @param type - The type of the ModuleItems + * @returns QList of ModuleItems with the specified id and type. + */ + QList getItems(const u32 id, ModuleItem::TreeItemType type = ModuleItem::TreeItemType::Module) const; + /** * Initializes the item model using the global netlist object gNetlist. */ @@ -133,7 +142,7 @@ namespace hal void clear() override; /** - * Add a module to the item model. For the specified module a new ModuleItem is created and stored. + * Add a module to the item model. For the specified module new ModuleItems are created and stored. * * @param id - The id of the module to add. * @param parent_module - The id of the parent module of the module to add. @@ -141,7 +150,7 @@ namespace hal void addModule(const u32 id, const u32 parentId); /** - * Add a gate to the item model. For the specified gate a new ModuleItem is created and stored. + * Add a gate to the item model. For the specified gate new ModuleItems are 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. @@ -149,7 +158,7 @@ namespace hal void addGate(const u32 id, const u32 parentId); /** - * Add a net to the item model. For the specified net a new ModuleItem is created and stored. + * Add a net to the item model. For the specified net new ModuleItems are 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. @@ -158,7 +167,7 @@ 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. + * and the gates of 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. @@ -209,29 +218,29 @@ namespace hal void updateNetParent(const Net* net, const QHash* parentAssignment = nullptr); /** - * Reattaches the ModuleItem corresponding to the specified module to a new parent item. + * Reattaches the ModuleItems corresponding to the specified module to new parent items. * 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. + * @param module - The module whose ModuleItems will be reattached to new parents in the item model. */ void updateModuleParent(const Module* module); /** - * Updates the ModuleItem for the specified module. The specified module MUST be contained in the item model. + * Updates the ModuleItems for the specified module. The specified module MUST be contained in the item model. * * @param id - The id of the module to update */ void updateModuleName(const u32 id); /** - * Updates the ModuleItem for the specified gate. The specified gate MUST be contained in the item model. + * Updates the ModuleItems 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); /** - * Updates the ModuleItem for the specified net. The specified gate MUST be contained in the item model. + * Updates the ModuleItems for the specified net. The specified gate MUST be contained in the item model. * * @param id - The id of the net to update */ @@ -254,7 +263,7 @@ namespace hal void handleModuleCreated(Module* mod); /** - * Moves the ModuleItem corresponding to the module under it's new parent ModuleItem. + * Moves the ModuleItems corresponding to the module under their new parent ModuleItems. * The items for all nets, that have at least one source or one destination within the module, * will be updated afterwards. * @@ -287,6 +296,30 @@ namespace hal void handleNetRemoved(Net* net); void handleNetUpdated(Net* net, u32 data); + + protected: + /** + * Factory method to append new tree items. Insert signals are sent to view. New items are put into hash table. + * @param id - ID of new tree item + * @param itemType - Whether new tree item is module, gate, or net + * @param parentItem - Parent to new tree item. Will create top-level item if parent is nullptr + * @return Point to new tree item + */ + ModuleItem* createChildItem(u32 id, ModuleItem::TreeItemType itemType, BaseTreeItem* parentItem = nullptr); + + /** + * Method to remove and delete tree items. Remove signals are sent to view. + * Hash table will _NOT_ be updated since caller can do it more efficiently. + * @param itemToRemove - Item to be removed from tree + * @param parentItem - Parent item. Must be present. + */ + void removeChildItem(ModuleItem* itemToRemove, BaseTreeItem* parentItem); + + /** + * See isModifying() + */ + void setIsModifying(bool pIsModifying); + private: /** * Searches for a new parent module, such that it is the deepest module in the hierarchy, that contains all @@ -307,23 +340,6 @@ namespace hal */ void findNetParentRecursion(BaseTreeItem* parent, QHash& parentAssignment, std::unordered_set& assignedNets) const; - /** - * Factory method to append new tree items. Insert signals are sent to view. New items are put into hash table. - * @param id - ID of new tree item - * @param itemType - Whether new tree item is module, gate, or net - * @param parentItem - Parent to new tree item. Will create top-level item if parent is nullptr - * @return Point to new tree item - */ - ModuleItem* createChildItem(u32 id, ModuleItem::TreeItemType itemType, BaseTreeItem* parentItem = nullptr); - - /** - * Method to remove and delete tree items. Remove signals are sent to view. - * Hash table will _NOT_ be updated since caller can do it more efficiently. - * @param itemToRemove - Item to be removed from tree - * @param parentItem - Parent item. Must be present. - */ - void removeChildItem(ModuleItem* itemToRemove, BaseTreeItem* parentItem); - QMultiMap mModuleMap; QMultiMap mGateMap; QMultiMap mNetMap; diff --git a/plugins/gui/include/gui/selection_details_widget/selection_details_widget.h b/plugins/gui/include/gui/selection_details_widget/selection_details_widget.h index 42010ac0807..da4ef2491fc 100644 --- a/plugins/gui/include/gui/selection_details_widget/selection_details_widget.h +++ b/plugins/gui/include/gui/selection_details_widget/selection_details_widget.h @@ -26,7 +26,7 @@ #pragma once #include "gui/content_widget/content_widget.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" +#include "gui/module_model/module_item.h" #include "gui/selection_details_widget/tree_navigation/selection_tree_proxy.h" #include "gui/selection_details_widget/tree_navigation/selection_tree_model.h" #include "hal_core/defines.h" @@ -238,7 +238,7 @@ namespace hal * * @param highlight - The items to highlight (that were selected in the view). */ - void triggerHighlight(QVector highlight); + void triggerHighlight(QVector highlight); /** * Q_SIGNAL that is emitted when a gate-type item in the treeview is double clicked @@ -280,7 +280,7 @@ namespace hal * * @param sti - The selected item. */ - void handleTreeSelection(const SelectionTreeItem* sti); + void handleTreeSelection(const ModuleItem* sti); /** * Overriden function of the ContentWidget. Sets up all shortcuts and returns them. @@ -320,7 +320,7 @@ namespace hal * * @param sti - The clicked item in the selection-treeview. */ - void handleTreeViewItemFocusClicked(const SelectionTreeItem* sti); + void handleTreeViewItemFocusClicked(const ModuleItem* sti); private: @@ -330,7 +330,7 @@ namespace hal * * @param sti - The item that is to be displayed. */ - void singleSelectionInternal(const SelectionTreeItem* sti); + void singleSelectionInternal(const ModuleItem* sti); /** * Adds the current selection to a module selected by id (=actionCode if positive). diff --git a/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_item.h b/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_item.h deleted file mode 100644 index 7695b477076..00000000000 --- a/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_item.h +++ /dev/null @@ -1,393 +0,0 @@ -// 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 -#include -#include -#include -#include -#include - -namespace hal -{ - /** - * @ingroup utility_widgets-selection_details - * @brief Basic item for the SelectionTreeModel. - * - * The basic tree item class for the SelectionTreeModel. It is the base class for every other - * subitem (except for SelectionTreeItemRoot) as it provides all commonly shared and necessary - * functions for the model and related events. - */ - class SelectionTreeItem - { - public: - - /** - * An enum that defines all possible types a tree item can take with the exception - * of the NullItem and MaxItem type. These types are convenient type used in the model - * and the graphics scene (NullItem is used for the root item of the model). The type - * be accessed via the itemType() method. - */ - enum TreeItemType - { - ModuleItem, GateItem, NetItem - }; - - /** - * The constructor. - * - * @param t - The type based on the netlist item type it represents. - * @param id_ The id of the item. It usually is the same as the underlying netlist item. - */ - SelectionTreeItem(TreeItemType t = ModuleItem, u32 id_ = 0); - - /** - * The destructor. - */ - virtual ~SelectionTreeItem(); - - //information access - /** - * Get the item's type. - * - * @return The type. - */ - TreeItemType itemType() const; - - /** - * Get the item's id. - * - * @return The id. - */ - u32 id() const; - - /** - * Get the item's parent (the direct ancestor in the tree). - * - * @return The parent. - */ - SelectionTreeItem* parent() const; - - /** - * Sets the parent (direct ancestor in the tree) of the item. - * - * @param p - The parent. - */ - void setParent(SelectionTreeItem* p); - - /** - * Get the number of child item (the items to which this item is the direct ancestor in the tree). - * - * @return The number of children. - */ - virtual int childCount() const; - - /** - * Get the child from the given row. - * - * @param row - The row for which the child is requested. - * @return The child for the given row. If the row is not in the childCount range, a nullptr is returned. - */ - virtual SelectionTreeItem* child(int row) const; - - /** - * Get the data for the specified column. - * - * @param column - The column for which the data is requested. - * @return The data. If the column > 2, an empty QVariant is returned. - */ - virtual QVariant data(int column) const; - - /** - * Get the name of the item. The name is usually the name of the underlying netlist item. - * Must be implemented in the subclasse(s). - * - * @return The item's name. - */ - virtual QVariant name() const = 0; - - /** - * Get the icon for either the module, gate, or net item. Must be implemented by - * the specific subclass. - * - * @return The subclasse's specific icon. - */ - virtual QIcon icon() const = 0; - - - /** - * Returns the appropriate type of either a gate or module (not a net). - * Must be implemented in the subclass. - * - * @return The name of the type. - */ - virtual QVariant boxType() const; - - /** - * Matches the given regex against the name, id, and in case if the the item is a gate type, - * the gate type. If the item is a module type, the children are also matched against. - * - * @param regex - The regex to match against the item. - * @return True if a match in either of the categories was found. False otherwise. - */ - //virtual bool match(const QRegularExpression& regex) const; - - /** - * A function that fills the modIds, gateIds, and netIds lists with the respective ids if the - * called selection-tree-item subclass does not match the given regex (and in thus suppressed, - * meaning should not be displayed). Must be implemented by the specific subclass since a module-type - * item must call this function of its children. A gate- or net-type item simply adds itself to the list - * (or not). - * - * @param modIds - The list that contains the suppresed module-type items at the end. - * @param gatIds - The list that contains the suppressed gate-type items at the end. - * @param netIds - The list that contains the suppressed net-type items at the end. - * @param regex - The regular expression to match the items against. - */ - //virtual void suppressedByFilterRecursion(QList& modIds, QList& gatIds, QList& netIds, - // const QRegularExpression& regex) const = 0; - bool isEqual(const SelectionTreeItem* sti) const; - protected: - TreeItemType mItemType; - u32 mId; - SelectionTreeItem* mParent; - }; - - /** - * @ingroup utility_widgets-selection_details - * @brief Tree item that represents a module. - * - * A subclass of the basic tree item class that represents a module of the netlist. - * It adds new hierarchical functionality since the module type item is the only item that - * can have children (and thus building the tree structure). - */ - class SelectionTreeItemModule : public SelectionTreeItem - { - public: - - /** - * The constructor. - * - * @param id_ - The item's id. It is the same id as the module it represents. - */ - SelectionTreeItemModule(u32 id_); - - /** - * The destructor. - */ - ~SelectionTreeItemModule(); - - /** - * Get the number of child item (the items to which this item is the direct ancestor in the tree). - * - * @return The number of children. - */ - virtual int childCount() const; - - /** - * Get the child from the given row. - * - * @param row - The row for which the child is requested. - * @return The child for the given row. If the row is not in the childCount range, a nullptr is returned. - */ - virtual SelectionTreeItem* child(int row) const; - - /** - * Get the name of the item. The name is usually the name of the underlying netlist item. - * - * @return The item's name. - */ - virtual QVariant name() const; - - /** - * Get the icon for a module type item. - * - * @return The module specific icon. - */ - virtual QIcon icon() const; - - /** - * Returns the name of the module's type. - * - * @return The name of the module's type. - */ - virtual QVariant boxType() const; - - /** - * Calls the match() function of its children and matches the regex against its id and name. - * - * @param regex - The regex to match against. - * @return True if a match in either of the categories was found or if a child item returns True. False otherwise. - */ - //virtual bool match(const QRegularExpression& regex) const; - - /** - * Matches itself against the given regex. If no mbrief boxTypeatch was found or the module item is the root of - * the model, the item inserts itself in the modIds list. This function is then invoked on all of its - * children. - * - * @param modIds - The list that contains the suppresed module-type items at the end. - * @param gatIds - The list that contains the suppressed gate-type items at the end. - * @param netIds - The list that contains the suppressed net-type items at the end. - * @param regex - The regular expression to match the items against. - */ - //virtual void suppressedByFilterRecursion(QList& modIds, QList& gatIds, QList& netIds, - // const QRegularExpression& regex) const; - - /** - * Appends the given tree item to its children. - * - * @param cld - The item to append. - */ - void addChild(SelectionTreeItem* cld); - - /** - * Checks if the module is the root item of the model. - * - * @return True if the item is the root item. False otherwise. - */ - bool isRoot() const; - protected: - bool mIsRoot; - QList mChildItem; - }; - - /** - * @ingroup utility_widgets-selection_details - * @brief Tree item that represent the root. - * - * A special case of the module type tree item. It has the fixed id 0. - */ - class SelectionTreeItemRoot : public SelectionTreeItemModule - { - public : - /** - * The constructor. The fixed id 0 is set here. - */ - SelectionTreeItemRoot(); - }; - - /** - * @ingroup utility_widgets-selection_details - * @brief Tree item that represents a gate. - * - * A subclass of the basic tree item class that represents a gate of the netlist. - * It implements the necessary commonly shared inherited functions as well as the - * gate specific function gateType(). - */ - class SelectionTreeItemGate : public SelectionTreeItem - { - public: - - /** - * The constructor. - * - * @param id_ - The item's id. It is the same id as the gate it represents. - */ - SelectionTreeItemGate(u32 id_); - - /** - * Get the name of the item. The name is usually the name of the underlying netlist item. - * - * @return The item's name. - */ - virtual QVariant name() const; - - /** - * Get the icon for a gate type item. - * - * @return The gate specific icon. - */ - virtual QIcon icon() const; - - /** - * Matches itself against the given regex. If no match was found it appends itself (its id) - * to the gatIds list. - * - * @param modIds - The list that contains the suppresed module-type items at the end. - * @param gatIds - The list that contains the suppressed gate-type items at the end. - * @param netIds - The list that contains the suppressed net-type items at the end. - * @param regex - The regular expression to match the items against. - */ - //virtual void suppressedByFilterRecursion(QList& modIds, QList& gatIds, QList& netIds, - // const QRegularExpression& regex) const; - - /** - * Get the name of the gate's type (e.g. LUT5 or FF). - * - * @return The gate type (QString). - */ - virtual QVariant boxType() const; - }; - - /** - * @ingroup utility_widgets-selection_details - * @brief Tree item that represents a net. - * - * A subclass of the basic tree item class that represents a net of the netlist. - * It implements the necessary commonly shared inherited functions. - */ - class SelectionTreeItemNet : public SelectionTreeItem - { - public: - - /** - * The constructor. - * - * @param id_ - The item's id. It is the same id as the net it represents. - */ - SelectionTreeItemNet(u32 id_); - - /** - * Get the name of the item. The name is usually the name of the underlying netlist item. - * - * @return The item's name. - */ - virtual QVariant name() const; - - /** - * Get the icon for a net type item. - * - * @return The net net icon. - */ - virtual QIcon icon() const; - - /** - * Matches itself against the given regex. If no match was found it appends itself (its id) - * to the netIds list. - * - * @param modIds - The list that contains the suppresed module-type items at the end. - * @param gatIds - The list that contains the suppressed gate-type items at the end. - * @param netIds - The list that contains the suppressed net-type items at the end. - * @param regex - The regular expression to match the items against. - */ - //virtual void suppressedByFilterRecursion(QList& modIds, QList& gatIds, QList& netIds, - // const QRegularExpression& regex) const; - }; - -} diff --git a/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_model.h b/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_model.h index e1099af084b..172ceb23076 100644 --- a/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_model.h @@ -28,6 +28,7 @@ #include "hal_core/defines.h" #include "hal_core/netlist/event_system/event_handler.h" #include "gui/gui_utils/sort.h" +#include "gui/module_model/module_model.h" #include #include @@ -37,10 +38,6 @@ namespace hal { - class SelectionTreeItem; - class SelectionTreeItemModule; - class SelectionTreeItemRoot; - /** * @ingroup utility_widgets-selection_details * @brief A model that contains the current selection. @@ -49,7 +46,7 @@ namespace hal * Its most important function is fetchSelection that automatically updates * the model's internal data. */ - class SelectionTreeModel : public QAbstractItemModel + class SelectionTreeModel : public ModuleModel { Q_OBJECT @@ -63,159 +60,13 @@ namespace hal SelectionTreeModel(QObject* parent = nullptr); /** - * The destructor. - */ - ~SelectionTreeModel(); - - /** @name Overwritten model functions. - */ - ///@{ - - //information access - /** - * Overwritten Qt function that is necessary for the model. For further information pleaser - * refer to the Qt documentation. - */ - QVariant data(const QModelIndex& index, int role) const override; - - /** - * Overwritten Qt function that is necessary for the model. For further information pleaser - * refer to the Qt documentation. - */ - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - - /** - * Overwritten Qt function that is necessary for the model. For further information pleaser - * refer to the Qt documentation. - */ - QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; - - /** - * Overwritten Qt function that is necessary for the model. For further information pleaser - * refer to the Qt documentation. - */ - QModelIndex parent(const QModelIndex& index) const override; - - /** - * Overwritten Qt function that is necessary for the model. For further information pleaser - * refer to the Qt documentation. - */ - Qt::ItemFlags flags(const QModelIndex& index) const override; - - /** - * Overwritten Qt function that is necessary for the model. For further information pleaser - * refer to the Qt documentation. - */ - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - - /** - * Overwritten Qt function that is necessary for the model. For further information pleaser - * refer to the Qt documentation. - */ - int columnCount(const QModelIndex& parent = QModelIndex()) const override; - ///@} - - /** - * Updates its internal data. If hasEntries is set to True, the current selection is fetched - * from the selectionRelay. Otherwise the model is simply cleared. + * Updates its internal data. If a groupingId is given, then the items of this grouping are fetched. + * Otherwise, if hasEntries is set to True, the current selection is fetched from the selectionRelay. + * Elsewise the model is simply cleared. * - * @param hasEntries - Decides wether the current selection is fetched. + * @param hasEntries - Decides whether the current selection is fetched. + * @param groupingId - if not 0, the id of the grouping to fetch. Otherwise ignored. */ void fetchSelection(bool hasEntries, u32 groupingId); - - /** - * Helper functions to convert between an item and its corresponding index. - * - * @param item - The item from which to get the index. - * @return The index that holds the item. - */ - QModelIndex indexFromItem(SelectionTreeItem* item) const; - - /** - * A recursive function to get the suppressed items that are not matched by the given regular - * expression (and therefore should not be displayed). The ids of theese items are then stored - * in the appropriate lists. - * - * @param modIds - The list that holds the ids of the suppressed modules. - * @param gatIds - The list that holds the ids of the suppressed gates. - * @param netIds - The list that holds the ids of the suppressed nets. - * @param regex - The regex to match the items against. - */ - //void suppressedByFilter(QList& modIds, QList& gatIds, QList& netIds, - // const QRegularExpression& regex) const; - - - static const int sNameColumn = 0; - static const int sIdColumn = 1; - static const int sTypeColumn = 2; - static const int sMaxColumn = 3; - - public Q_SLOTS: - /** - * Q_SLOT to handle the change of a gate and emits the dataChanged signal. This - * function is connected to the gateNameChanged signal. - * - * @param gate - The gate whose information changed. - */ - void handleGateItemChanged(Gate* gate); - - /** - * Q_SLOT to handle the change of a module and emits the dataChanged signal. This - * function is connected to the moduleNameChanged and moduleTypeChanged signal. - * - * @param module - The module whose information changed. - */ - void handleModuleItemChanged(Module* module); - - /** - * Retrieves the SelectionTreeItem associated with a given QModelIndex which holds information about the type, id and name of the given Item. - * @param index The QModelIndex for which to retrieve the associated SelectionTreeItem. - * @return A pointer to the associated SelectionTreeItem if the index is valid; otherwise, nullptr. - */ - SelectionTreeItem* itemFromIndex(const QModelIndex& index) const; - private: - - void moduleRecursion(SelectionTreeItemModule* modItem); - bool doNotDisturb(const QModelIndex& inx = QModelIndex()) const; - SelectionTreeItem* getItem(SelectionTreeItem *parentItem, - const SelectionTreeItem& needle) const; - - SelectionTreeItemRoot* mRootItem; - - /// avoid calls while model is under reconstruction - int mDoNotDisturb; }; - - /** - * @ingroup utility_widgets-selection_details - * @brief Deletes the current SelectionTreeModel. - * - * A utility class to delete the current model. The current root item of the - * model is given to the disposer and deleted when dispose is called. - */ - class SelectionTreeModelDisposer : public QObject - { - Q_OBJECT - public: - - /** - * The constructor. - * - * @param stim - The root item to "wrap". - * @param parent - The disposer's parent. - */ - SelectionTreeModelDisposer(SelectionTreeItemRoot* stim, QObject* parent=nullptr); - - public Q_SLOTS: - - /** - * Deletes its root item. - */ - void dispose(); - - private: - SelectionTreeItemRoot* mRootItem; - }; - - } 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 43113a8e655..6a83b6d246c 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 @@ -26,7 +26,7 @@ #pragma once #include "gui/gui_def.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" +#include "gui/module_model/module_item.h" #include "gui/selection_details_widget/tree_navigation/selection_tree_model.h" #include "gui/selection_details_widget/tree_navigation/selection_tree_proxy.h" @@ -54,14 +54,14 @@ namespace hal * * @param sti - The new "selected" item, can be a nullptr if the index was not valid. */ - void triggerSelection(const SelectionTreeItem* sti); + void triggerSelection(const ModuleItem* sti); /** * Q_SIGNAL that is emitted when an item is double clicked. * * @param sti - The double clicked item. */ - void itemDoubleClicked(const SelectionTreeItem* sti); + void itemDoubleClicked(const ModuleItem* sti); /** * Q_SIGNAL that is emitted when the action "Focus item in Graph View" in the context @@ -69,7 +69,7 @@ namespace hal * * @param sti - The item that thas right-clicked. */ - void focusItemClicked(const SelectionTreeItem* sti); + void focusItemClicked(const ModuleItem* sti); public Q_SLOTS: /** @@ -133,7 +133,7 @@ namespace hal * @param index - The index to convert. * @return The item that is represented. Returns a nullptr if the index is invalid or the conversion fails. */ - SelectionTreeItem* itemFromIndex(const QModelIndex& index = QModelIndex()) const; + ModuleItem* itemFromIndex(const QModelIndex& index = QModelIndex()) const; /** * Get the view's proxy model for the SelectionTreeModel. @@ -149,8 +149,8 @@ namespace hal static void isolateInNewViewAction(Node nd); private Q_SLOTS: void handleCustomContextMenuRequested(const QPoint& point); - void handleIsolationViewAction(const SelectionTreeItem* sti); - void handleAddToSelection(const SelectionTreeItem* sti); + void handleIsolationViewAction(const ModuleItem* sti); + void handleAddToSelection(const ModuleItem* sti); /** * Emits either the focusGateClicked, focusNetClicked or focusModuleClicked signal based on the @@ -158,7 +158,7 @@ namespace hal * * @param sti - The clicked item in the selection-treeview. */ - void handleTreeViewItemFocusClicked(const SelectionTreeItem* sti); + void handleTreeViewItemFocusClicked(const ModuleItem* sti); private: diff --git a/plugins/gui/src/graph_widget/graphics_scene.cpp b/plugins/gui/src/graph_widget/graphics_scene.cpp index 09b516e2cdb..00f8671ba9b 100644 --- a/plugins/gui/src/graph_widget/graphics_scene.cpp +++ b/plugins/gui/src/graph_widget/graphics_scene.cpp @@ -492,20 +492,20 @@ namespace hal gn->update(); } - void GraphicsScene::handleHighlight(const QVector& highlightItems) + void GraphicsScene::handleHighlight(const QVector& highlightItems) { QSet highlightSet[3]; - for (const SelectionTreeItem* sti : highlightItems) + for (const ModuleItem* sti : highlightItems) { - if (sti) highlightSet[sti->itemType()].insert(sti->id()); + if (sti) highlightSet[(int)sti->getType()].insert(sti->id()); } for (GraphicsModule* gm : mModuleItems) - gm->setHightlight(highlightSet[SelectionTreeItem::ModuleItem].contains(gm->id())); + gm->setHightlight(highlightSet[(int)ModuleItem::TreeItemType::Module].contains(gm->id())); for (GraphicsGate* gg : mGateItems) - gg->setHightlight(highlightSet[SelectionTreeItem::GateItem].contains(gg->id())); + gg->setHightlight(highlightSet[(int)ModuleItem::TreeItemType::Gate].contains(gg->id())); for (GraphicsNet* gn : mNetItems) - gn->setHightlight(highlightSet[SelectionTreeItem::NetItem].contains(gn->id())); + gn->setHightlight(highlightSet[(int)ModuleItem::TreeItemType::Net].contains(gn->id())); } void GraphicsScene::handleExternSelectionChanged(void* sender) diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 28e9de94035..8cf94a635a4 100644 --- a/plugins/gui/src/module_model/module_model.cpp +++ b/plugins/gui/src/module_model/module_model.cpp @@ -71,6 +71,10 @@ namespace hal else return QColor(QColor(255, 255, 255)); // USE STYLESHEETS } + case Qt::TextAlignmentRole: + return index.column() == 1 + ? Qt::AlignRight + : Qt::AlignLeft; default: return QVariant(); } @@ -708,6 +712,11 @@ namespace hal return mModuleItemMaps[(int)type]->value(id); } + QList ModuleModel::getItems(u32 id, ModuleItem::TreeItemType type) const + { + return mModuleItemMaps[(int)type]->values(id); + } + ModuleItem* ModuleModel::createChildItem(u32 id, ModuleItem::TreeItemType itemType, BaseTreeItem *parentItem) { ModuleItem* retval = new ModuleItem(id, itemType); @@ -725,10 +734,13 @@ namespace hal return retval; } - bool ModuleModel::isModifying() { return mIsModifying; } - + + void ModuleModel::setIsModifying(bool pIsModifying) + { + mIsModifying = pIsModifying; + } } diff --git a/plugins/gui/src/selection_details_widget/selection_details_widget.cpp b/plugins/gui/src/selection_details_widget/selection_details_widget.cpp index c0deeeca4f5..ee896b802f5 100644 --- a/plugins/gui/src/selection_details_widget/selection_details_widget.cpp +++ b/plugins/gui/src/selection_details_widget/selection_details_widget.cpp @@ -301,19 +301,18 @@ namespace hal for(int i = 0; i < mSelectionTreeProxyModel->rowCount(); i++){ QModelIndex sourceModelIndex = mSelectionTreeProxyModel->mapToSource(mSelectionTreeProxyModel->index(i,0)); - SelectionTreeItem* item = sourceModel->itemFromIndex(sourceModelIndex); - SelectionTreeItem::TreeItemType type = item->itemType(); - switch (type) + ModuleItem* item = dynamic_cast(sourceModel->getItemFromIndex(sourceModelIndex)); + switch (item->getType()) { - case SelectionTreeItem::TreeItemType::ModuleItem: + case ModuleItem::TreeItemType::Module: mods.insert(item->id()); break; - case SelectionTreeItem::TreeItemType::GateItem: + case ModuleItem::TreeItemType::Gate: gates.insert(item->id()); break; - case SelectionTreeItem::TreeItemType::NetItem: + case ModuleItem::TreeItemType::Net: nets.insert(item->id()); break; default: @@ -372,7 +371,7 @@ namespace hal } mNumberSelectedItems = gSelectionRelay->numberSelectedItems(); - QVector defaultHighlight; + QVector defaultHighlight; if (mNumberSelectedItems) { @@ -411,27 +410,27 @@ namespace hal if (gSelectionRelay->numberSelectedModules()) { - SelectionTreeItemModule sti(gSelectionRelay->selectedModulesList().at(0)); + ModuleItem sti(gSelectionRelay->selectedModulesList().at(0), ModuleItem::TreeItemType::Module); singleSelectionInternal(&sti); } else if (gSelectionRelay->numberSelectedGates()) { - SelectionTreeItemGate sti(gSelectionRelay->selectedGatesList().at(0)); + ModuleItem sti(gSelectionRelay->selectedGatesList().at(0), ModuleItem::TreeItemType::Gate); singleSelectionInternal(&sti); } else if (gSelectionRelay->numberSelectedNets()) { - SelectionTreeItemNet sti(gSelectionRelay->selectedNetsList().at(0)); + ModuleItem sti(gSelectionRelay->selectedNetsList().at(0), ModuleItem::TreeItemType::Net); singleSelectionInternal(&sti); } Q_EMIT triggerHighlight(defaultHighlight); } - void SelectionDetailsWidget::handleTreeSelection(const SelectionTreeItem *sti) + void SelectionDetailsWidget::handleTreeSelection(const ModuleItem *sti) { singleSelectionInternal(sti); - QVector highlight; + QVector highlight; if (sti) highlight.append(sti); Q_EMIT triggerHighlight(highlight); } @@ -443,15 +442,15 @@ namespace hal mStackedWidget->setCurrentWidget(mNoSelectionLabel); } - void SelectionDetailsWidget::singleSelectionInternal(const SelectionTreeItem *sti) + void SelectionDetailsWidget::singleSelectionInternal(const ModuleItem *sti) { if(!sti){ showNoSelection(); return; } - switch (sti->itemType()) { - case SelectionTreeItem::ModuleItem: + switch (sti->getType()) { + case ModuleItem::TreeItemType::Module: if (Module* m = gNetlist->get_module_by_id(sti->id()); m) { mModuleDetailsTabs->setModule(m); @@ -463,7 +462,7 @@ namespace hal break; - case SelectionTreeItem::GateItem: + case ModuleItem::TreeItemType::Gate: showNoSelection(); if (Gate* g = gNetlist->get_gate_by_id(sti->id()); g) { @@ -472,7 +471,7 @@ namespace hal // if (mNumberSelectedItems==1) set_name("Gate Details"); } break; - case SelectionTreeItem::NetItem: + case ModuleItem::TreeItemType::Net: showNoSelection(); if (Net* n = gNetlist->get_net_by_id(sti->id()); n) { @@ -522,15 +521,15 @@ namespace hal mSearchAction->setIcon(gui_utility::getStyledSvgIcon(mSearchIconStyle, mSearchIconPath)); } - void SelectionDetailsWidget::handleTreeViewItemFocusClicked(const SelectionTreeItem* sti) + void SelectionDetailsWidget::handleTreeViewItemFocusClicked(const ModuleItem* sti) { u32 itemId = sti->id(); - switch (sti->itemType()) + switch (sti->getType()) { - case SelectionTreeItem::TreeItemType::GateItem: Q_EMIT focusGateClicked(itemId); break; - case SelectionTreeItem::TreeItemType::NetItem: Q_EMIT focusNetClicked(itemId); break; - case SelectionTreeItem::TreeItemType::ModuleItem: Q_EMIT focusModuleClicked(itemId); break; + case ModuleItem::TreeItemType::Module: Q_EMIT focusModuleClicked(itemId); break; + case ModuleItem::TreeItemType::Gate: Q_EMIT focusGateClicked(itemId); break; + case ModuleItem::TreeItemType::Net: Q_EMIT focusNetClicked(itemId); break; default: break; } } 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 deleted file mode 100644 index d786d934dce..00000000000 --- a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_item.cpp +++ /dev/null @@ -1,205 +0,0 @@ -#include "gui/gui_globals.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" -#include "gui/selection_details_widget/selection_details_icon_provider.h" - -namespace hal -{ - SelectionTreeItem::SelectionTreeItem(SelectionTreeItem::TreeItemType t, u32 id_) - : mItemType(t), mId(id_), mParent(0) - {;} - - SelectionTreeItem::~SelectionTreeItem() - {;} - - SelectionTreeItem::TreeItemType SelectionTreeItem::itemType() const - { - return mItemType; - } - - u32 SelectionTreeItem::id() const - { - return mId; - } - - SelectionTreeItem* SelectionTreeItem::parent() const - { - return mParent; - } - - void SelectionTreeItem::setParent(SelectionTreeItem* p) - { - mParent = p; - } - - int SelectionTreeItem::childCount() const - { - return 0; - } - - SelectionTreeItem* SelectionTreeItem::child(int row) const - { - Q_UNUSED(row); - return nullptr; - } - - QVariant SelectionTreeItem::data(int column) const - { - switch (column) { - case 0: return name(); - case 1: return mId; - case 2: return boxType(); - } - return QVariant(); - } - - QVariant SelectionTreeItem::boxType() const - { - return QVariant(); - } - - /*bool SelectionTreeItem::match(const QRegularExpression& regex) const - { - if (!regex.isValid()) return true; - return regex.match(name().toString()).hasMatch() || - regex.match(QString::number(mId)).hasMatch() || - regex.match(boxType().toString()).hasMatch(); - }*/ - - bool SelectionTreeItem::isEqual(const SelectionTreeItem* sti) const - { - return mItemType == sti->mItemType && mId == sti->mId; - } - - //------- Module ---- - SelectionTreeItemModule::SelectionTreeItemModule(u32 id_) - : SelectionTreeItem(SelectionTreeItem::ModuleItem, id_), mIsRoot(false) - {;} - - SelectionTreeItemModule::~SelectionTreeItemModule() - { - for (SelectionTreeItem* sti : mChildItem) - delete sti; - } - - SelectionTreeItemRoot::SelectionTreeItemRoot() - : SelectionTreeItemModule(0) - { - mIsRoot = true; - } - - bool SelectionTreeItemModule::isRoot() const - { - return mIsRoot; - } - - int SelectionTreeItemModule::childCount() const - { - return mChildItem.size(); - } - - - SelectionTreeItem* SelectionTreeItemModule::child(int row) const - { - if (row<0 || row >= mChildItem.size()) return nullptr; - return mChildItem.at(row); - } - - QVariant SelectionTreeItemModule::name() const - { - Module* module = gNetlist->get_module_by_id(mId); - if(!module) return QVariant(); - return QString::fromStdString(module->get_name()); - } - - QIcon SelectionTreeItemModule::icon() const - { - return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::ModuleIcon,mId)); - } - - void SelectionTreeItemModule::addChild(SelectionTreeItem* cld) - { - cld->setParent(this); - mChildItem.append(cld); - } - - QVariant SelectionTreeItemModule::boxType() const - { - Module* module = gNetlist->get_module_by_id(mId); - if(!module) return QVariant(); - return QString::fromStdString(module->get_type()); - } -/* - bool SelectionTreeItemModule::match(const QRegularExpression& regex) const - { - for (SelectionTreeItem* sti : mChildItem) - if (sti->match(regex)) return true; - - return SelectionTreeItem::match(regex); - }*/ -/* - void SelectionTreeItemModule::suppressedByFilterRecursion(QList& modIds, QList& gatIds, QList& netIds, - const QRegularExpression& regex) const - { - if (!isRoot() && !match(regex)) modIds.append(mId); - for (SelectionTreeItem* sti : mChildItem) - sti->suppressedByFilterRecursion(modIds, gatIds, netIds, regex); - }*/ - - //------- Gate ------ - SelectionTreeItemGate::SelectionTreeItemGate(u32 id_) - : SelectionTreeItem(SelectionTreeItem::GateItem, id_) - {;} - - QVariant SelectionTreeItemGate::name() const - { - Gate* gate = gNetlist->get_gate_by_id(mId); - if(!gate) return QVariant(); - return QString::fromStdString(gate->get_name()); - } - - QIcon SelectionTreeItemGate::icon() const - { - return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::GateIcon,mId)); - } - - QVariant SelectionTreeItemGate::boxType() const - { - Gate* gate = gNetlist->get_gate_by_id(mId); - if(!gate) return QVariant(); - return QString::fromStdString(gate->get_type()->get_name()); - } -/* - void SelectionTreeItemGate::suppressedByFilterRecursion(QList& modIds, QList& gatIds, QList& netIds, - const QRegularExpression& regex) const - { - Q_UNUSED(modIds) - Q_UNUSED(netIds) - if (!match(regex)) gatIds.append(mId); - }*/ - - //------- Net ------- - SelectionTreeItemNet::SelectionTreeItemNet(u32 id_) - : SelectionTreeItem(SelectionTreeItem::NetItem, id_) - {;} - - QVariant SelectionTreeItemNet::name() const - { - Net* net = gNetlist->get_net_by_id(mId); - if(!net) return QVariant(); - return QString::fromStdString(net->get_name()); - } - - QIcon SelectionTreeItemNet::icon() const - { - return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::NetIcon,mId)); - } -/* - void SelectionTreeItemNet::suppressedByFilterRecursion(QList& modIds, QList& gatIds, QList& netIds, - const QRegularExpression& regex) const - { - Q_UNUSED(modIds) - Q_UNUSED(gatIds) - if (!match(regex)) netIds.append(mId); - }*/ - -} 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 a6f1565aff4..e15f58adb44 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/module_model/module_item.h" #include "gui/gui_globals.h" #include "hal_core/netlist/gate.h" #include "hal_core/netlist/net.h" @@ -11,161 +11,30 @@ namespace hal { SelectionTreeModel::SelectionTreeModel(QObject* parent) - : QAbstractItemModel(parent), mDoNotDisturb(0) + : ModuleModel(parent) { - mRootItem = new SelectionTreeItemRoot; - // root item has no parent - - connect(gNetlistRelay,&NetlistRelay::moduleNameChanged,this,&SelectionTreeModel::handleModuleItemChanged); - connect(gNetlistRelay,&NetlistRelay::moduleTypeChanged,this,&SelectionTreeModel::handleModuleItemChanged); - connect(gNetlistRelay,&NetlistRelay::gateNameChanged,this,&SelectionTreeModel::handleGateItemChanged); - } - - SelectionTreeModel::~SelectionTreeModel() - { - delete mRootItem; - } - - bool SelectionTreeModel::doNotDisturb(const QModelIndex& inx) const - { - Q_UNUSED(inx); // could do some tests for debugging - return (mDoNotDisturb != 0); - } - - QVariant SelectionTreeModel::data(const QModelIndex& index, int role) const - { - if (doNotDisturb(index)) - return QVariant(); - - // UserRole is mapped to "is a structure element?" - // if (role == Qt::UserRole) - // return getItem(index)->get_type() == SelectionTreeItem::itemType::structure; - - // if (getItem(index)->get_type() == SelectionTreeItem::itemType::structure && index.column() == 0) - // { - // if (role == Qt::FontRole) - // return m_structured_font; - - // if(getItem(index) == m_gates_item && role == Qt::DecorationRole) - // return m_design_icon; } - SelectionTreeItem* item = itemFromIndex(index); - if (!item) return QVariant(); - - switch (role) { - case Qt::DecorationRole: - return index.column() == sNameColumn - ? QVariant(item->icon()) - : QVariant(); - case Qt::DisplayRole: - return item->data(index.column()); - case Qt::TextAlignmentRole: - return index.column() == sIdColumn - ? Qt::AlignRight - : Qt::AlignLeft; - default: - break; - } - - return QVariant(); - - } - - QVariant SelectionTreeModel::headerData(int section, Qt::Orientation orientation, int role) const - { - const char* horizontalHeader[] = { "Name", "ID", "Type"}; - if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section < columnCount()) - return QString(horizontalHeader[section]); - - return QVariant(); - } - - /* - QModelIndex SelectionTreeModel::defaultIndex() const - { - if (doNotDisturb()) return QModelIndex(); - - if (!mRootItem->childCount()) return QModelIndex(); - SelectionTreeItem* sti = mRootItem->child(0); - return createIndex(0,0,sti); - } -*/ - - QModelIndex SelectionTreeModel::index(int row, int column, const QModelIndex& parent) const - { - if (doNotDisturb(parent)) return QModelIndex(); - - if (!hasIndex(row,column,parent)) return QModelIndex(); - - SelectionTreeItem* parentItem = parent.isValid() - ? itemFromIndex(parent) - : mRootItem; - - SelectionTreeItem* childItem = parentItem->child(row); - if (childItem) - return createIndex(row, column, childItem); - else - return QModelIndex(); - } - - QModelIndex SelectionTreeModel::parent(const QModelIndex& index) const - { - if (doNotDisturb(index)) return QModelIndex(); - - if (!index.isValid()) return QModelIndex(); - - SelectionTreeItem* currentItem = itemFromIndex(index); - if (!currentItem) return QModelIndex(); - - SelectionTreeItem* parentItem = currentItem->parent(); - - // toplevel entries dont reveal their parent - if (parentItem == mRootItem) return QModelIndex(); - - return indexFromItem(parentItem); - } - - Qt::ItemFlags SelectionTreeModel::flags(const QModelIndex& index) const - { - return QAbstractItemModel::flags(index); - } - - int SelectionTreeModel::rowCount(const QModelIndex& parent) const - { - if (doNotDisturb(parent)) return 0; - - SelectionTreeItem* item = parent.isValid() - ? itemFromIndex(parent) - : mRootItem; - - return item->childCount(); - } - - int SelectionTreeModel::columnCount(const QModelIndex& parent) const - { - Q_UNUSED(parent) - return sMaxColumn; + // Initialise as empty + fetchSelection(false, 0); } void SelectionTreeModel::fetchSelection(bool hasEntries, u32 groupingId) { - SelectionTreeItemRoot* nextRootItem - = new SelectionTreeItemRoot(); + while(mRootItem->getChildCount() > 0) + removeChildItem(dynamic_cast(mRootItem->getChild(0)), mRootItem); + + QList newRootList; if (!groupingId) { if (hasEntries) { for(u32 id : gSelectionRelay->selectedModulesList()) - { - SelectionTreeItemModule* stim = new SelectionTreeItemModule(id); - moduleRecursion(stim); - nextRootItem->addChild(stim); - } + addRecursively(gNetlist->get_module_by_id(id)); for(u32 id : gSelectionRelay->selectedGatesList()) - nextRootItem->addChild(new SelectionTreeItemGate(id)); - + newRootList.append(new ModuleItem(id, ModuleItem::TreeItemType::Gate)); + for(u32 id : gSelectionRelay->selectedNetsList()) - nextRootItem->addChild(new SelectionTreeItemNet(id)); + newRootList.append(new ModuleItem(id, ModuleItem::TreeItemType::Net)); } } else @@ -174,158 +43,21 @@ namespace hal if (grouping) { for (u32 id : grouping->get_module_ids()) - { - SelectionTreeItemModule* stim = new SelectionTreeItemModule(id); - moduleRecursion(stim); - nextRootItem->addChild(stim); - } + addRecursively(gNetlist->get_module_by_id(id)); for (u32 id : grouping->get_gate_ids()) - { - nextRootItem->addChild(new SelectionTreeItemGate(id)); - } + newRootList.append(new ModuleItem(id, ModuleItem::TreeItemType::Gate)); for (u32 id : grouping->get_net_ids()) - { - nextRootItem->addChild(new SelectionTreeItemNet(id)); - } + newRootList.append(new ModuleItem(id, ModuleItem::TreeItemType::Net)); } } - beginResetModel(); - - ++mDoNotDisturb; - // delay disposal of old entries - // until all clients are notified that indexes are not valid any more - SelectionTreeModelDisposer* disposer = new SelectionTreeModelDisposer(mRootItem,this); - mRootItem = nextRootItem; - QTimer::singleShot(50,disposer,&SelectionTreeModelDisposer::dispose); - --mDoNotDisturb; + setIsModifying(true); + beginResetModel(); + for(auto item : newRootList) + mRootItem->appendChild(item); + setIsModifying(false); endResetModel(); } - - void SelectionTreeModel::moduleRecursion(SelectionTreeItemModule* modItem) - { - if (modItem->isRoot()) return; - Module* mod = gNetlist->get_module_by_id(modItem->id()); - if (!mod) return; - for (Module* m : mod->get_submodules() ) - { - SelectionTreeItemModule* subItem = new SelectionTreeItemModule(m->get_id()); - moduleRecursion(subItem); - modItem->addChild(subItem); - } - for (Gate* g : mod->get_gates() ) - { - modItem->addChild(new SelectionTreeItemGate(g->get_id())); - } - std::unordered_set internNets = mod->get_internal_nets(); - std::unordered_set outputNets = mod->get_output_nets(); - std::unordered_set inputNets = mod->get_input_nets(); - for (Net* n : mod->get_nets() ) - { - bool netIsChild = false; - if (internNets.find(n) != internNets.end()) - { - netIsChild = true; - } - else if (outputNets.find(n) != outputNets.end()) - { - if (!n->is_global_output_net() && n->get_destinations().empty()) - netIsChild = true; - } - else if (inputNets.find(n) != inputNets.end()) - { - if (!n->is_global_input_net() && n->get_sources().empty()) - netIsChild = true; - } - else - netIsChild = true; - - if (netIsChild) - modItem->addChild(new SelectionTreeItemNet(n->get_id())); - } - } - - SelectionTreeItem* SelectionTreeModel::itemFromIndex(const QModelIndex& index) const - { - if (index.isValid()) - return static_cast(index.internalPointer()); - return nullptr; - } - - void SelectionTreeModel::handleGateItemChanged(Gate* gate) - { - SelectionTreeItem* item = getItem(mRootItem, - SelectionTreeItemGate(gate->get_id())); - if (item) - { - QModelIndex inx0 = indexFromItem(item); - QModelIndex inx1 = createIndex(inx0.row(),2,inx0.internalPointer()); - Q_EMIT dataChanged(inx0,inx1); - } - } - - void SelectionTreeModel::handleModuleItemChanged(Module* module) - { - SelectionTreeItem* item = getItem(mRootItem, - SelectionTreeItemModule(module->get_id())); - if (item) - { - QModelIndex inx0 = indexFromItem(item); - QModelIndex inx1 = createIndex(inx0.row(),2,inx0.internalPointer()); - Q_EMIT dataChanged(inx0,inx1); - } - } - - SelectionTreeItem* SelectionTreeModel::getItem(SelectionTreeItem* parentItem, - const SelectionTreeItem& needle) const - { - if (needle.isEqual(parentItem)) return parentItem; - SelectionTreeItem* retval = nullptr; - - int n = parentItem->childCount(); - for (int irow=0; irowchild(irow),needle); - if (retval) return retval; - } - return retval; - } - - QModelIndex SelectionTreeModel::indexFromItem(SelectionTreeItem* item) const - { - if (!item) return QModelIndex(); - SelectionTreeItem* parentItem = item->parent(); - - if (!parentItem) // must be root - return createIndex(0,0,mRootItem); - - int n = parentItem->childCount(); - for (int irow=0; irowchild(irow) == item) - return createIndex(irow,0,item); - } - - // not found in parent - return QModelIndex(); - } -/* - void SelectionTreeModel::suppressedByFilter(QList& modIds, QList& gatIds, QList& netIds, - const QRegularExpression& regex) const - { - if (!mRootItem) return; - mRootItem->suppressedByFilterRecursion(modIds, gatIds, netIds, regex); - }*/ - - SelectionTreeModelDisposer::SelectionTreeModelDisposer(SelectionTreeItemRoot *stim, QObject* parent) - : QObject(parent), mRootItem(stim) - {;} - - void SelectionTreeModelDisposer::dispose() - { - delete mRootItem; - deleteLater(); - } } 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 380614edf4d..5c43e9a623f 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/module_model/module_item.h" #include "gui/gui_globals.h" 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 0210a4f6cbd..c452d5b325b 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 @@ -34,9 +34,9 @@ namespace hal void SelectionTreeView::setDefaultColumnWidth() { - setColumnWidth(SelectionTreeModel::sNameColumn, 160); - setColumnWidth(SelectionTreeModel::sIdColumn, 40); - setColumnWidth(SelectionTreeModel::sTypeColumn, 80); + setColumnWidth(0, 160); + setColumnWidth(1, 40); + setColumnWidth(2, 80); header()->setStretchLastSection(true); } @@ -44,7 +44,7 @@ namespace hal { Q_UNUSED(previous); - const SelectionTreeItem* sti = current.isValid() ? itemFromIndex(current) : nullptr; + const ModuleItem* sti = current.isValid() ? itemFromIndex(current) : nullptr; Q_EMIT triggerSelection(sti); } @@ -58,12 +58,12 @@ namespace hal if (index.isValid()) { - SelectionTreeItem* item = itemFromIndex(index); + ModuleItem* item = itemFromIndex(index); Q_EMIT itemDoubleClicked(item); } } - SelectionTreeItem* SelectionTreeView::itemFromIndex(const QModelIndex& index) const + ModuleItem* SelectionTreeView::itemFromIndex(const QModelIndex& index) const { SelectionTreeProxyModel* treeProxy = dynamic_cast(model()); if (!treeProxy) return nullptr; @@ -75,7 +75,7 @@ namespace hal return nullptr; QModelIndex modelIndex = treeProxy->mapToSource(proxyIndex); - return static_cast(modelIndex.internalPointer()); + return static_cast(modelIndex.internalPointer()); } void SelectionTreeView::handleModuleColorChanged(u32 id) @@ -92,13 +92,13 @@ namespace hal { QMenu menu; - SelectionTreeItem* item = itemFromIndex(index); + ModuleItem* item = itemFromIndex(index); if (item) { - switch (item->itemType()) + switch (item->getType()) { - case SelectionTreeItem::TreeItemType::ModuleItem: + case ModuleItem::TreeItemType::Module: menu.addAction(QIcon(":/icons/python"), "Extract Module as python code (copy to clipboard)", [item]() { QApplication::clipboard()->setText("netlist.get_module_by_id(" + QString::number(item->id()) + ")"); @@ -109,7 +109,7 @@ namespace hal menu.addAction("Add to Selection", [this, item]() { Q_EMIT handleAddToSelection(item); }); break; - case SelectionTreeItem::TreeItemType::GateItem: + case ModuleItem::TreeItemType::Gate: menu.addAction(QIcon(":/icons/python"), "Extract Gate as python code (copy to clipboard)", [item]() { QApplication::clipboard()->setText("netlist.get_gate_by_id(" + QString::number(item->id()) + ")"); @@ -120,7 +120,7 @@ namespace hal menu.addAction("Add to Selection", [this, item]() { Q_EMIT handleAddToSelection(item); }); break; - case SelectionTreeItem::TreeItemType::NetItem: + case ModuleItem::TreeItemType::Net: menu.addAction(QIcon(":/icons/python"), "Extract Net as python code (copy to clipboard)", [item]() { QApplication::clipboard()->setText("netlist.get_net_by_id(" + QString::number(item->id()) + ")"); @@ -129,7 +129,7 @@ namespace hal menu.addAction("Add to Selection", [this, item]() { Q_EMIT handleAddToSelection(item); }); break; - default: // make compiler happy and handle irrelevant MaxItem, NullItem + default: // make compiler happy break; } } @@ -140,14 +140,14 @@ namespace hal } } - void SelectionTreeView::handleIsolationViewAction(const SelectionTreeItem* sti) + void SelectionTreeView::handleIsolationViewAction(const ModuleItem* sti) { Node nd; - if (sti->itemType() == SelectionTreeItem::TreeItemType::GateItem) + if (sti->getType() == ModuleItem::TreeItemType::Gate) { nd = Node(sti->id(),Node::Gate); } - else if (sti->itemType() == SelectionTreeItem::TreeItemType::ModuleItem) + else if (sti->getType() == ModuleItem::TreeItemType::Module) { nd = Node(sti->id(),Node::Module); } @@ -158,37 +158,30 @@ namespace hal isolateInNewViewAction(nd); } - void SelectionTreeView::handleAddToSelection(const SelectionTreeItem* sti) + void SelectionTreeView::handleAddToSelection(const ModuleItem* sti) { - // Abhängig vom Typ des TreeItems fügen wir unterschiedliche Elemente zur Auswahl hinzu. - switch (sti->itemType()) + switch (sti->getType()) { - case SelectionTreeItem::ModuleItem: + case ModuleItem::TreeItemType::Module: { - // Downcast auf Modul und hinzufügen zur Auswahl. - const SelectionTreeItemModule* moduleItem = static_cast(sti); - gSelectionRelay->addModule(moduleItem->id()); + gSelectionRelay->addModule(sti->id()); break; } - case SelectionTreeItem::GateItem: + case ModuleItem::TreeItemType::Gate: { - // Downcast auf Tor und hinzufügen zur Auswahl. - const SelectionTreeItemGate* gateItem = static_cast(sti); - gSelectionRelay->addGate(gateItem->id()); + gSelectionRelay->addGate(sti->id()); break; } - case SelectionTreeItem::NetItem: + case ModuleItem::TreeItemType::Net: { - // Downcast auf Netz und hinzufügen zur Auswahl. - const SelectionTreeItemNet* netItem = static_cast(sti); - gSelectionRelay->addNet(netItem->id()); + gSelectionRelay->addNet(sti->id()); break; } default: - // Ungültiger oder unbekannter Auswahltyp. + // Unknown or invalid type return; } gSelectionRelay->relaySelectionChanged(this); @@ -279,21 +272,21 @@ namespace hal return dynamic_cast(model()); } - void SelectionTreeView::handleTreeViewItemFocusClicked(const SelectionTreeItem* sti) + void SelectionTreeView::handleTreeViewItemFocusClicked(const ModuleItem* sti) { u32 itemId = sti->id(); - switch (sti->itemType()) + switch (sti->getType()) { - case SelectionTreeItem::TreeItemType::GateItem: + case ModuleItem::TreeItemType::Module: + gContentManager->getGraphTabWidget()->handleModuleFocus(itemId); + break; + case ModuleItem::TreeItemType::Gate: gContentManager->getGraphTabWidget()->handleGateFocus(itemId); break; - case SelectionTreeItem::TreeItemType::NetItem: + case ModuleItem::TreeItemType::Net: gContentManager->getGraphTabWidget()->handleNetFocus(itemId); break; - case SelectionTreeItem::TreeItemType::ModuleItem: - gContentManager->getGraphTabWidget()->handleModuleFocus(itemId); - break; default: break; } } diff --git a/plugins/simulator/waveform_viewer/include/waveform_viewer/wave_widget.h b/plugins/simulator/waveform_viewer/include/waveform_viewer/wave_widget.h index f4e805ac753..550567b7113 100644 --- a/plugins/simulator/waveform_viewer/include/waveform_viewer/wave_widget.h +++ b/plugins/simulator/waveform_viewer/include/waveform_viewer/wave_widget.h @@ -42,7 +42,7 @@ namespace hal { class WaveGraphicsCanvas; class WaveTreeModel; class WaveTreeView; - class SelectionTreeItem; + class ModuleItem; // enum SimulationState { SimulationSelectGates, SimulationClockSet, SimulationInputGenerate, SimulationShowResults }; @@ -76,7 +76,7 @@ namespace hal { private Q_SLOTS: - void handleSelectionHighlight(const QVector& highlight); + void handleSelectionHighlight(const QVector& highlight); void handleNumberWaveformChanged(int count); void handleStateChanged(NetlistSimulatorController::SimulationState state); void visualizeCurrentNetState(double tCursor, int xpos); diff --git a/plugins/simulator/waveform_viewer/src/wave_widget.cpp b/plugins/simulator/waveform_viewer/src/wave_widget.cpp index 34564856e00..d3e807fa6be 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/module_model/module_item.h" #include "gui/gui_globals.h" namespace hal { @@ -163,11 +163,11 @@ namespace hal { qApp->processEvents(); } - void WaveWidget::handleSelectionHighlight(const QVector& highlight) + void WaveWidget::handleSelectionHighlight(const QVector& highlight) { QSet hlIds; - for (const SelectionTreeItem* sti : highlight) - if (sti->itemType() == SelectionTreeItem::NetItem) + for (const ModuleItem* sti : highlight) + if (sti->getType() == ModuleItem::TreeItemType::Net) hlIds.insert(sti->id()); mTreeView->setWaveSelection(hlIds);