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..537ffc27a10 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 @@ -79,13 +79,6 @@ namespace hal */ QVariant getData(int column) const override; - /** - * Gets the index of this ModuleItem in the list of children ModuleItems of its parent. - * - * @returns the index in the parents ModuleItem children list - */ - int row() const; - /** * Gets the name of the netlist item this ModuleItem represents. * diff --git a/plugins/gui/include/gui/module_model/module_model.h b/plugins/gui/include/gui/module_model/module_model.h index fd0e5c01755..5e22b8a66b0 100644 --- a/plugins/gui/include/gui/module_model/module_model.h +++ b/plugins/gui/include/gui/module_model/module_model.h @@ -43,14 +43,19 @@ namespace hal /** * @ingroup gui - * @brief Represents the netlist module's hierarchy. + * @brief A model for displaying multiple netlist elements. * - * The ModuleModel is the item model that represents the modules and their hierarchy in the netlist. + * An item model that manages a specifiable set of netlist elements in a tree-styled fashion. + * May contain a single netlist element multiple times. + * See populateTree() for more information. */ class ModuleModel : public BaseTreeModel { Q_OBJECT + /** + * Class for compatibility to NetlistRelay::moduleGatesAssignBegin and NetlistRelay::moduleGatesAssignEnd. + */ class TempGateAssignment { int mAccumulate; @@ -76,8 +81,7 @@ namespace hal public: /** * Constructor.
- * Since the netlist is not necessarily loaded when this class is instantiated, the model won't be filled with - * data until the init function is called. The constructor is an empty one. + * Constructs an empty item model and connects relevant slots to the global netlist relay. * * @param parent - The parent object. */ @@ -114,7 +118,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 @@ -123,9 +127,13 @@ namespace hal ModuleItem* getItem(const u32 id, ModuleItem::TreeItemType type = ModuleItem::TreeItemType::Module) const; /** - * Initializes the item model using the global netlist object gNetlist. + * 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. */ - void init(); + QList getItems(const u32 id, ModuleItem::TreeItemType type = ModuleItem::TreeItemType::Module) const; /** * Clears the item model and deletes all ModuleItems. @@ -133,7 +141,20 @@ namespace hal void clear() override; /** - * Add a module to the item model. For the specified module a new ModuleItem is created and stored. + * Clears current tree item model and repopulates it with new ModuleItems for the netlist elements + * specified in the parameters. + * All netlist elements present in the parameters are added to the root of the tree. + * All submodules, gates and nets of given modules will also be added to the tree as children of those modules. + * This way some netlist elements may be present in the item model multiple times. + * + * @param modIds QVector of ids of modules to be added to the item model. + * @param gateIds QVector of ids of gates to be added to the item model. + * @param netIds QVector of ids of nets to be added to the item model. + */ + void populateTree(const QVector& modIds = {}, const QVector& gatIds = {}, const QVector& netIds = {}); + + /** + * 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 +162,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 +170,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,10 +179,11 @@ 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. + * Nets have to be added in another way, like for example using moduleAssignNets(). * * @param module - The module which should be added to the item model together with all its - * submodules, gates and nets. + * submodules and gates. */ void addRecursively(const Module* module, BaseTreeItem* parentItem = nullptr); @@ -209,29 +231,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 +276,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 +309,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 +353,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/module_details_widget/filter_elements_proxy_model.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/filter_elements_proxy_model.h new file mode 100644 index 00000000000..8bf55f9a8ea --- /dev/null +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/filter_elements_proxy_model.h @@ -0,0 +1,64 @@ +#pragma once + +#include "gui/gui_utils/sort.h" + +#include + +namespace hal +{ + /** + * @ingroup gui + * @brief Enables filtering of nets or gates in the ModuleModel. + * + */ + class FilterElementsProxyModel : public QSortFilterProxyModel + { + Q_OBJECT + + public: + /** + * Constructor. + * + * @param parent - The parent widget + */ + FilterElementsProxyModel(QObject* parent = nullptr); + + /** + * Sets whether or not nets are filtered out by the filter. + * @returns true if nets are filtered out now. false if not. + * @param filterNets if true, then nets are filtered out. + */ + void setFilterNets(bool filterNets); + + /** + * Sets whether or not gates are filtered out by the filter. + * @returns true if gates are filtered out now. false if not. + * @param filterNets if true, then gates are filtered out. + */ + void setFilterGates(bool filterGates); + + /** + * Returns whether or not nets are filtered out by the filter. + */ + bool areNetsFiltered(); + + /** + * Returns whether or not gates are filtered out by the filter. + */ + bool areGatesFiltered(); + + protected: + /** + * Overrides QSortFilterProxyModel::filterAcceptsRow to implement the filter logic. + * + * @param sourceRow - The row in the source model + * @param sourceParent - The source parent + * @returns true if the row should be included in the model. + */ + bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override; + + private: + bool mFilterNets; + bool mFilterGates; + }; +} diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_elements_tree.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_elements_tree.h index 888160354f0..9e84b6e1bda 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_elements_tree.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_elements_tree.h @@ -26,6 +26,9 @@ #pragma once #include "hal_core/defines.h" +#include "gui/module_model/module_model.h" +#include "gui/selection_details_widget/module_details_widget/filter_elements_proxy_model.h" + #include namespace hal @@ -85,7 +88,8 @@ namespace hal void updateText(const QString& newHeadline); private: - ModuleTreeModel* mModel; + ModuleModel* mModel; + FilterElementsProxyModel* mProxyModel; int mModuleID; void handleNumberSubmodulesChanged(const int number); 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 deleted file mode 100644 index 81dceaf580a..00000000000 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_tree_model.h +++ /dev/null @@ -1,169 +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 "gui/basic_tree_model/base_tree_model.h" -#include "hal_core/defines.h" -#include -#include -#include - - -namespace hal -{ - class Module; - class Gate; - class Net; - class BaseTreeItem; - - class ModuleTreeitem : public BaseTreeItem - { - public: - enum ItemType { None, Module, Gate}; - - private: - ItemType mItemType; - int mId; - QString mName; - QString mNodeType; - public: - - ModuleTreeitem(ItemType itp, int id, const QString& name, const QString& ntp); - 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; - - /** - * Get the type (enum) of a given item. - * - * @param item - The item for which the type is requested. - * @return The item's type. - */ - ItemType itemType() const { return mItemType; } - }; - - class ModuleTreeModel : public BaseTreeModel - { - Q_OBJECT - public: - - ModuleTreeModel(QObject* parent = nullptr); - - ~ModuleTreeModel(); - - void setModule(Module* m); - - void clear() override; - - /** @name Overwritten model functions - */ - ///@{ - - /** - * 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 = Qt::DisplayRole) const override; - ///@} - - /** - * Disconnects all events from the model. Can be called to increase performance when - * no module is displayed. - */ - void disconnectEvents(); - - /** - * Connects all events to the model. When setting a module, all events will be - * automatically conneceted. - */ - void connectEvents(); - - //Column identifier - static const int sNameColumn = 0; - static const int sIdColumn = 1; - static const int sTypeColumn = 2; - - Q_SIGNALS: - - /** - * Signal that is emitted when the number of direct submodules changed - * in the case the displayed content is displayed by using the method - * setModule(). - * - * @param newNumber - The new number of direct submodules. - */ - void numberOfSubmodulesChanged(const int newNumber); - - - private: - QString mKeyItemType = "type"; - QString mKeyRepId = "id"; - int mThreshold = 1; - //only for "all events", specific events that are disabled by event-guard handlers - //musst be handled there (disconnect specific events at begin, connect them at end) - bool mEventsConnected = false; - - int mModId; - QMap mModuleToTreeitems; - QMap mGateToTreeitems; - - //necessary because setModule uses beginResetModel (should not be called by each recursive iteration) - void moduleRecursive(Module* mod, BaseTreeItem* modItem); - - //perhaps more performance instead of setting the whole displayed module anew - void updateGatesOfModule(Module* mod); - - /** - * Utility function to determine the displayed icon for a given item - * - * @param item - The requested item. - * @return A module, net, or gate icon depending on the item's type. - */ - QIcon getIconFromItem(ModuleTreeitem* item) const; - - void clearOwnStructures(); - - //guards - void handleModuleGatesAssignBegin(Module* m, u32 associated_data); - void handleModuleGatesAssignEnd(Module* m, u32 associated_data); - void handleModuleGatesRemoveBegin(Module* m, u32 associated_data); - void handleModuleGatesRemoveEnd(Module* m, u32 associated_data); - - //actual functions - void handleModuleSubmoduleAdded(Module* m, u32 added_module); - void handleModuleSubmoduleRemoved(Module* m, u32 removed_module); - void handleModuleGateAssigned(Module* m, u32 assigned_gate); - void handleModuleGateRemoved(Module* m, u32 removed_gate); - void handleModuleRemoved(Module* m); - - void handleGateNameChanged(Gate* g); - void handleModuleNameChanged(Module* m); - void handleModuleTypeChanged(Module* m); - }; - -} 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 deleted file mode 100644 index b6540d1855e..00000000000 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h +++ /dev/null @@ -1,221 +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 -#include -//#include "gui/new_selection_details_widget/models/base_tree_item.h" -#include "gui/basic_tree_model/base_tree_model.h" -#include "hal_core/defines.h" - -namespace hal -{ - class Module; - class Gate; - class Net; - class BaseTreeItem; - - class NetlistElementsTreeitem : public BaseTreeItem - { - public: - enum ItemType { None, Module, Gate, Net}; - - private: - ItemType mItemType; - u32 mId; - QString mName; - QString mNodeType; - public: - - NetlistElementsTreeitem(ItemType itp, u32 id_, const QString& name, const QString& ntp = QString()); - 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; - - u32 id() const { return mId; } - /** - * Get the type (enum) of a given item. - * - * @return The item's type. - */ - ItemType itemType() const { return mItemType; } - }; - - /** - * @ingroup utility_widgets-selection_details - * @brief A model to display arbitrary elements of the netlist. - */ - class NetlistElementsTreeModel : public BaseTreeModel - { - Q_OBJECT - public: - - - /** - * The constructor. - * - * @param parent - The model's parent. - */ - NetlistElementsTreeModel(QObject* parent = nullptr); - - /** - * The destructor. - */ - ~NetlistElementsTreeModel(); - - /** @name Overwritten model functions - */ - ///@{ - - /** - * 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 = Qt::DisplayRole) const override; - ///@} - - /** - * Overwritten clear function to reset this model's specific structures. - */ - void clear() override; - - /** - * Sets the module's content to the specified ids. Adds all Elements to the top level of - * the tree. As of now, the model does not check the consistency of the items. For instance, if - * modules that shall explicity be displayed are already within other given modules. This also - * applies to gates. This can result in duplicate items that are displayed at the top level as - * well as within a module hirarchy. - * - * @param modIds - Ids of modules. - * @param gateIds - Ids of gates. - * @param netIds - Ids of nets. - * @param displayModulesRecursive - True to add all submodules of the given module list to the tree. - * @param showGatesInSubmods - True to show the gates in the submodules that were added if displayModulesRecursive = true. - * @param showNetsInSubmods - True to show the net in the submodules that were added if displayModulesRecursive = true. - */ - void setContent(QList modIds, QList gateIds, QList netIds, bool displayModulesRecursive = true, bool showGatesInSubmods = true, bool showNetsInSubmods = true); - - /** - * Updates the model's content to the given module. Convenient functions that can be used - * instead of the more general setContent() function. - * - * @param mod - The module to display. - * @param showGates - True to add gates, False to show only module hierarchy. - * @param showNets - True to add nets, False to show only module hierarchy. - * @param displayModulesRecursive - True to show - */ - void setModule(Module* mod, bool showGates = true, bool showNets = true, bool displayModulesRecursive = true); - - /** - * Get the module/gate/net id that the given item represents. - * To know the type of the item, call getTypeOfItem(). - * - * @param item - The item from which to extract the id. - * @return The corresponding module, gate, or net id. - */ - int getRepresentedIdOfItem(NetlistElementsTreeitem* item) const; - - /** @name Event Handler Functions - */ - ///@{ - void gateNameChanged(Gate* g); - void gateRemoved(Gate* g); - void netNameChanged(Net* n); - void netRemoved(Net* n); - void moduleNameChanged(Module* m); - void moduleTypeChanged(Module* m); - void moduleSubmoduleRemoved(Module* m, int removed_module); - //optional - void moduleGateAssigned(Module* m, int assigned_gate); //const u32 - void moduleGateRemoved(Module* m, int removed_gate); //const u32 //same as assign_gate(top) - void moduleSubmoduleAdded(Module* m, int added_module); - ///@} - - - //Column identifier - static const int sNameColumn = 0; - static const int sIdColumn = 1; - static const int sTypeColumn = 2; - - //additional data keys - const QString keyItemType = "type"; //also save value in enum (if it is possible with QVariant) - const QString keyRepresentedID = "id"; - - - Q_SIGNALS: - - /** - * Signal that is emitted when the number of direct submodules changed - * in the case the displayed content is displayed by using the method - * setModule(). - * - * @param newNumber - The new number of direct submodules. - */ - void numberOfSubmodulesChanged(const int newNumber); - - private: - - bool mGatesDisplayed; - bool mNetsDisplayed; - bool mDisplaySubmodRecursive; - - //boolean needed for a special case when displaying a module that is called with setModule - bool mCurrentlyDisplayingModule; - int mModId; - - //"2" options: //also: use QMultiMap in case multiple "same" items (gates etc) are displayed - //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; - - //necessary because setModule uses beginResetModel (should not be called by each recursive iteration) - void moduleRecursive(Module* mod, NetlistElementsTreeitem* modItem, bool showGates = true, bool showNets = true); - - /** - * Utility function to determine the displayed icon for a given item - * - * @param item - The requested item. - * @return A module, net, or gate icon depending on the item's type. - */ - QIcon getIconFromItem(NetlistElementsTreeitem* item) const; - - /** - * Utility function to remove all net items of the given module item and - * add the (potentionally) updated internal nets. Usually used when a gate is added - * or removed from a gate (internal nets might change as a result). - * - * @param moduleItem - The module item to modify. - */ - void updateInternalNetsOfModule(NetlistElementsTreeitem* moduleItem); - - }; - -} 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..109d19ee811 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,9 +26,8 @@ #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_model.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 +237,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 +279,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 +319,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 +329,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). @@ -377,6 +376,6 @@ namespace hal NetDetailsTabWidget* mNetDetailsTabs; ModuleDetailsTabWidget* mModuleDetailsTabs; SelectionTreeProxyModel* mSelectionTreeProxyModel; - SelectionTreeModel* mSelectionTreeModel; + ModuleModel* mModuleModel; }; } 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 c3691534e4f..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 - { - NullItem, ModuleItem, GateItem, NetItem, MaxItem - }; - - /** - * 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 = NullItem, 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 deleted file mode 100644 index 6c4f7d820be..00000000000 --- a/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_model.h +++ /dev/null @@ -1,221 +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 "hal_core/netlist/event_system/event_handler.h" -#include "gui/gui_utils/sort.h" - -#include -#include -#include -#include -#include - -namespace hal -{ - class SelectionTreeItem; - class SelectionTreeItemModule; - class SelectionTreeItemRoot; - - /** - * @ingroup utility_widgets-selection_details - * @brief A model that contains the current selection. - * - * A model that manages the current selection in a tree-styled fashion. - * Its most important function is fetchSelection that automatically updates - * the model's internal data. - */ - class SelectionTreeModel : public QAbstractItemModel - { - Q_OBJECT - - public: - - /** - * The constructor. - * - * @param parent - The model's parent. - */ - 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. - * - * @param hasEntries - Decides wether the current selection is fetched. - */ - 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_proxy.h b/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_proxy.h index 1bf2949f006..43a7e3cbbdd 100644 --- a/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_proxy.h +++ b/plugins/gui/include/gui/selection_details_widget/tree_navigation/selection_tree_proxy.h @@ -57,7 +57,7 @@ namespace hal * in the view because they do not match the filter-string. Then it tells the selection * relay to update these items. */ - void applyFilterOnGraphics(); + //void applyFilterOnGraphics(); /** * Checks if the model is still busy with applying the changes (in applyFilterOnGraphics()). @@ -102,7 +102,7 @@ namespace hal * * @param filter_text - The text to filter the model by. */ - void handleFilterTextChanged(const QString& filter_text); + //void handleFilterTextChanged(const QString& filter_text); private: gui_utility::mSortMechanism mSortMechanism; 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 10b6d77d4be..d7d4373f10c 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,8 +26,7 @@ #pragma once #include "gui/gui_def.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_item.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_model.h" +#include "gui/module_model/module_model.h" #include "gui/selection_details_widget/tree_navigation/selection_tree_proxy.h" #include @@ -54,14 +53,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 +68,7 @@ namespace hal * * @param sti - The item that thas right-clicked. */ - void focusItemClicked(const SelectionTreeItem* sti); + void focusItemClicked(const ModuleItem* sti); public Q_SLOTS: /** @@ -78,7 +77,7 @@ namespace hal * * @param filter_text -The text to filter the model. */ - void handleFilterTextChanged(const QString& filter_text); + ///void handleFilterTextChanged(const QString& filter_text); /** * Might have to change icon color if module selected, thus updating view upon this event @@ -133,7 +132,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 +148,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 +157,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/include/gui/selection_relay/selection_relay.h b/plugins/gui/include/gui/selection_relay/selection_relay.h index e9d0c6dde63..48e875bb45c 100644 --- a/plugins/gui/include/gui/selection_relay/selection_relay.h +++ b/plugins/gui/include/gui/selection_relay/selection_relay.h @@ -221,7 +221,7 @@ namespace hal * @param gatIds - A list of suppressed gate ids * @param netIds - A list of suppressed net ids */ - void suppressedByFilter(const QList& modIds = QList(), const QList& gatIds = QList(), const QList& netIds = QList()); + //void suppressedByFilter(const QList& modIds = QList(), const QList& gatIds = QList(), const QList& netIds = QList()); /** * Gets a list of ids of all selected gates. diff --git a/plugins/gui/src/graph_widget/graphics_scene.cpp b/plugins/gui/src/graph_widget/graphics_scene.cpp index 1525a2a7fa1..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[SelectionTreeItem::MaxItem]; - for (const SelectionTreeItem* sti : highlightItems) + QSet highlightSet[3]; + 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/grouping/grouping_manager_widget.cpp b/plugins/gui/src/grouping/grouping_manager_widget.cpp index ecd13b1b3ae..eeb0cb71c3d 100644 --- a/plugins/gui/src/grouping/grouping_manager_widget.cpp +++ b/plugins/gui/src/grouping/grouping_manager_widget.cpp @@ -493,33 +493,32 @@ namespace hal QDialog dialog; dialog.setWindowTitle(QString("Content of %1 (ID: %2)").arg(grpName).arg(grpId)); - // Create color rectangle - QLabel* colorRectangle = new QLabel(); - colorRectangle->setText(QString()); // Empty text to visualize grouping color - colorRectangle->setStyleSheet("background-color: " + grpColor.name()); - colorRectangle->setFixedSize(25, 25); // Adapt size of grouping color - colorRectangle->setAutoFillBackground(true); + QLabel colorRectangle(&dialog); + colorRectangle.setText(QString()); // Empty text to visualize grouping color + colorRectangle.setStyleSheet("background-color: " + grpColor.name()); + colorRectangle.setFixedSize(25, 25); // Adapt size of grouping color + colorRectangle.setAutoFillBackground(true); // Replace InputDialog with SelectionTreeView - SelectionTreeView* selectionTreeView = new SelectionTreeView(&dialog, true); - SelectionTreeModel* selectionTreeModel = new SelectionTreeModel(this); // Need to fully initialise SelectionTreeView with a model - SelectionTreeProxyModel* selectionTreeProxyModel = new SelectionTreeProxyModel(this); - selectionTreeProxyModel->setSourceModel(selectionTreeModel); - selectionTreeView->setModel(selectionTreeProxyModel); - - selectionTreeView->populate(true, grpId); - - QPushButton* closeButton = new QPushButton("Close", &dialog); - connect(closeButton, &QPushButton::clicked, [&dialog](){ dialog.close(); }); - - QVBoxLayout* layout = new QVBoxLayout(&dialog); - QHBoxLayout* hlay = new QHBoxLayout; - hlay->addStretch(); - hlay->addWidget(colorRectangle); - layout->addLayout(hlay); - layout->addWidget(selectionTreeView); - layout->addWidget(closeButton); + SelectionTreeView selectionTreeView(&dialog, true); + SelectionTreeProxyModel selectionTreeProxyModel(&dialog); + ModuleModel moduleModel(&dialog); // Need to fully initialise SelectionTreeView with a model + selectionTreeProxyModel.setSourceModel(&moduleModel); + selectionTreeView.setModel(&selectionTreeProxyModel); + + selectionTreeView.populate(true, grpId); + + QPushButton closeButton("Close",&dialog);// = new QPushButton("Close", &dialog); + connect(&closeButton, &QPushButton::clicked, [&dialog](){ dialog.close(); }); + + QVBoxLayout layout(&dialog); + QHBoxLayout hlay(&dialog); + hlay.addStretch(); + hlay.addWidget(&colorRectangle); + layout.addLayout(&hlay); + layout.addWidget(&selectionTreeView); + layout.addWidget(&closeButton); dialog.exec(); } diff --git a/plugins/gui/src/module_model/module_item.cpp b/plugins/gui/src/module_model/module_item.cpp index 8291ac52b80..f3a1e531f79 100644 --- a/plugins/gui/src/module_model/module_item.cpp +++ b/plugins/gui/src/module_model/module_item.cpp @@ -42,14 +42,6 @@ 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(mItemType != TreeItemType::Module) // only module can have children diff --git a/plugins/gui/src/module_model/module_model.cpp b/plugins/gui/src/module_model/module_model.cpp index 28e9de94035..7763e37b833 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(); } @@ -93,10 +97,14 @@ namespace hal return nullptr; } - void ModuleModel::init() + ModuleItem* ModuleModel::getItem(u32 id, ModuleItem::TreeItemType type) const { - addRecursively(gNetlist->get_top_module()); - moduleAssignNets(); + return mModuleItemMaps[(int)type]->value(id); + } + + QList ModuleModel::getItems(u32 id, ModuleItem::TreeItemType type) const + { + return mModuleItemMaps[(int)type]->values(id); } void ModuleModel::clear() @@ -110,6 +118,30 @@ namespace hal endResetModel(); } + void ModuleModel::populateTree(const QVector& modIds, const QVector& gateIds, const QVector& netIds) + { + setIsModifying(true); + beginResetModel(); + // Might want to add parameter for container of moduleIds that don't get recursively inserted. + clear(); + + QList newRootList; + for(u32 id : modIds) + addRecursively(gNetlist->get_module_by_id(id)); + moduleAssignNets(); + + for(u32 id : gateIds) + newRootList.append(new ModuleItem(id, ModuleItem::TreeItemType::Gate)); + + for(u32 id : netIds) + newRootList.append(new ModuleItem(id, ModuleItem::TreeItemType::Net)); + + for(auto item : newRootList) + mRootItem->appendChild(item); + setIsModifying(false); + endResetModel(); + } + void ModuleModel::addModule(u32 id, u32 parentId) { Q_ASSERT(gNetlist->get_module_by_id(id)); @@ -199,6 +231,23 @@ namespace hal } } + ModuleItem* ModuleModel::createChildItem(u32 id, ModuleItem::TreeItemType itemType, BaseTreeItem *parentItem) + { + ModuleItem* retval = new ModuleItem(id, itemType); + mModuleItemMaps[(int)itemType]->insertMulti(id,retval); + + if (!parentItem) parentItem = mRootItem; + QModelIndex index = getIndexFromItem(parentItem); + int row = parentItem->getChildCount(); + mIsModifying = true; + beginInsertRows(index, row, row); + parentItem->appendChild(retval); + endInsertRows(); + mIsModifying = false; + + return retval; + } + void ModuleModel::removeChildItem(ModuleItem *itemToRemove, BaseTreeItem *parentItem) { Q_ASSERT(itemToRemove); @@ -221,7 +270,7 @@ namespace hal QModelIndex index = getIndexFromItem(parentItem); - int row = itemToRemove->row(); + int row = itemToRemove->getOwnRow(); mIsModifying = true; beginRemoveRows(index, row, row); @@ -599,7 +648,7 @@ namespace hal moduleItemToBeMoved = submItem; QModelIndex index = getIndexFromItem(oldParentItem); - int row = submItem->row(); + int row = submItem->getOwnRow(); mIsModifying = true; beginRemoveRows(index, row, row); @@ -703,32 +752,13 @@ namespace hal } } - ModuleItem* ModuleModel::getItem(u32 id, ModuleItem::TreeItemType type) const - { - return mModuleItemMaps[(int)type]->value(id); - } - - ModuleItem* ModuleModel::createChildItem(u32 id, ModuleItem::TreeItemType itemType, BaseTreeItem *parentItem) + bool ModuleModel::isModifying() { - ModuleItem* retval = new ModuleItem(id, itemType); - mModuleItemMaps[(int)itemType]->insertMulti(id,retval); - - if (!parentItem) parentItem = mRootItem; - QModelIndex index = getIndexFromItem(parentItem); - int row = parentItem->getChildCount(); - mIsModifying = true; - beginInsertRows(index, row, row); - parentItem->appendChild(retval); - endInsertRows(); - mIsModifying = false; - - return retval; + return mIsModifying; } - - bool ModuleModel::isModifying() + void ModuleModel::setIsModifying(bool pIsModifying) { - return mIsModifying; + mIsModifying = pIsModifying; } - } diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index 8013912b997..ec6c8151769 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -114,7 +114,7 @@ namespace hal connect(mToggleExpandTreeAction, &QAction::triggered, this, &ModuleWidget::handleToggleExpandTreeClicked); connect(mRenameAction, &QAction::triggered, this, &ModuleWidget::handleRenameClicked); - mModuleModel->init(); + mModuleModel->populateTree({gNetlist->get_top_module()->get_id()}); mTreeView->expandAllModules(); } @@ -611,11 +611,13 @@ namespace hal for (auto module_id : gSelectionRelay->selectedModulesList()) { - ModuleItem* item = mModuleModel->getItem(module_id); - if(item) + for(ModuleItem* item : mModuleModel->getItems(module_id)) { - QModelIndex index = mModuleProxyModel->mapFromSource(mModuleModel->getIndexFromItem(item)); - module_selection.select(index, index); + if(item) + { + QModelIndex index = mModuleProxyModel->mapFromSource(mModuleModel->getIndexFromItem(item)); + module_selection.select(index, index); + } } } diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/filter_elements_proxy_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/filter_elements_proxy_model.cpp new file mode 100644 index 00000000000..67b38b5a2f2 --- /dev/null +++ b/plugins/gui/src/selection_details_widget/module_details_widget/filter_elements_proxy_model.cpp @@ -0,0 +1,41 @@ +#include "gui/selection_details_widget/module_details_widget/filter_elements_proxy_model.h" +#include "gui/module_model/module_item.h" + +#include "gui/gui_globals.h" + +namespace hal +{ + FilterElementsProxyModel::FilterElementsProxyModel(QObject* parent) : mFilterNets(false), mFilterGates(false) + {} + + void FilterElementsProxyModel::setFilterNets(bool filterNets){ + mFilterNets = filterNets; + invalidateFilter(); + } + + void FilterElementsProxyModel::setFilterGates(bool filterGates){ + mFilterGates = filterGates; + invalidateFilter(); + } + + bool FilterElementsProxyModel::areNetsFiltered(){ + return mFilterNets; + } + + bool FilterElementsProxyModel::areGatesFiltered(){ + return mFilterGates; + } + + bool FilterElementsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const + { + QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent); + auto item = static_cast(sourceIndex.internalPointer()); + + if(mFilterNets && item->getType() == ModuleItem::TreeItemType::Net) + return false; + if(mFilterGates && item->getType() == ModuleItem::TreeItemType::Gate) + return false; + + return true; + } +} 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 30e3cf47006..6063d2b560b 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 @@ -1,6 +1,4 @@ #include "gui/selection_details_widget/module_details_widget/module_elements_tree.h" -#include "gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h" -#include "gui/selection_details_widget/module_details_widget/module_tree_model.h" #include "gui/selection_details_widget/tree_navigation/selection_tree_view.h" #include "gui/graph_tab_widget/graph_tab_widget.h" #include "gui/python/py_code_provider.h" @@ -13,8 +11,7 @@ namespace hal { - ModuleElementsTree::ModuleElementsTree(QWidget *parent) : QTreeView(parent), //mNetlistElementsModel(new NetlistElementsTreeModel(this)), - mModel(new ModuleTreeModel(this)), mModuleID(-1) + ModuleElementsTree::ModuleElementsTree(QWidget *parent) : QTreeView(parent), mModuleID(-1) { setContextMenuPolicy(Qt::CustomContextMenu); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -22,12 +19,15 @@ namespace hal setSelectionBehavior(QAbstractItemView::SelectRows); setFocusPolicy(Qt::NoFocus); header()->setStretchLastSection(true); - //setModel(mNetlistElementsModel); - setModel(mModel); + mProxyModel = new FilterElementsProxyModel(this); + mModel = new ModuleModel(mProxyModel); + mProxyModel->setSourceModel(mModel); + mProxyModel->setFilterNets(true); + setModel(mProxyModel); //connections connect(this, &QTreeView::customContextMenuRequested, this, &ModuleElementsTree::handleContextMenuRequested); - connect(mModel, &ModuleTreeModel::numberOfSubmodulesChanged, this, &ModuleElementsTree::handleNumberSubmodulesChanged); + //connect(mModel, &ModuleTreeModel::numberOfSubmodulesChanged, this, &ModuleElementsTree::handleNumberSubmodulesChanged); } void ModuleElementsTree::setModule(u32 moduleID) @@ -40,17 +40,16 @@ namespace hal void ModuleElementsTree::setModule(Module *m) { - //if(!m) return; - - //mNetlistElementsModel->setModule(m, true, false, false); + if(!m) return; - mModel->setModule(m); + mModel->populateTree({m->get_id()}); + setRootIndex(mProxyModel->mapFromSource(mModel->getIndexFromItem(mModel->getItem(m->get_id())))); // hide top-element m in TreeView + mModuleID = m->get_id(); } void ModuleElementsTree::removeContent() { - //mNetlistElementsModel->clear(); mModel->clear(); mModuleID = -1; } @@ -61,9 +60,9 @@ namespace hal if(!clickedIndex.isValid()) return; - ModuleTreeitem* clickedItem = dynamic_cast(mModel->getItemFromIndex(clickedIndex)); - int id = clickedItem->getData(ModuleTreeModel::sIdColumn).toInt(); - ModuleTreeitem::ItemType type = clickedItem->itemType(); + ModuleItem* clickedItem = dynamic_cast(mModel->getItemFromIndex(mProxyModel->mapToSource(clickedIndex))); + int id = clickedItem->id(); + ModuleItem::TreeItemType type = clickedItem->getType(); QMenu menu; //menu.addSection("here comes the plaintext"); @@ -71,7 +70,7 @@ namespace hal menu.addAction("Name to clipboard", [clickedItem]() { - QApplication::clipboard()->setText(clickedItem->getData(NetlistElementsTreeModel::sNameColumn).toString()); + QApplication::clipboard()->setText(clickedItem->getData(0).toString()); } ); @@ -85,7 +84,7 @@ namespace hal menu.addAction("Type to clipboard", [clickedItem]() { - QApplication::clipboard()->setText(clickedItem->getData(NetlistElementsTreeModel::sTypeColumn).toString()); + QApplication::clipboard()->setText(clickedItem->getData(2).toString()); } ); @@ -97,8 +96,8 @@ namespace hal gSelectionRelay->clear(); switch(type) { - case ModuleTreeitem::Module: gSelectionRelay->addModule(id); break; - case ModuleTreeitem::Gate: gSelectionRelay->addGate(id); break; + case ModuleItem::TreeItemType::Module: gSelectionRelay->addModule(id); break; + case ModuleItem::TreeItemType::Gate: gSelectionRelay->addGate(id); break; } gSelectionRelay->relaySelectionChanged(this); } @@ -109,8 +108,8 @@ namespace hal { switch(type) { - case ModuleTreeitem::Module: gSelectionRelay->addModule(id); break; - case ModuleTreeitem::Gate: gSelectionRelay->addGate(id); break; + case ModuleItem::TreeItemType::Module: gSelectionRelay->addModule(id); break; + case ModuleItem::TreeItemType::Gate: gSelectionRelay->addGate(id); break; } gSelectionRelay->relaySelectionChanged(this); } @@ -122,8 +121,8 @@ namespace hal Node nd; switch(type) { - case ModuleTreeitem::Module: nd = Node(id, Node::Module); break; - case ModuleTreeitem::Gate: nd = Node(id, Node::Gate); break; + case ModuleItem::TreeItemType::Module: nd = Node(id, Node::Module); break; + case ModuleItem::TreeItemType::Gate: nd = Node(id, Node::Gate); break; } SelectionTreeView::isolateInNewViewAction(nd); } @@ -134,16 +133,16 @@ namespace hal { switch(type) { - case ModuleTreeitem::Module: gContentManager->getGraphTabWidget()->handleModuleFocus(id); break; - case ModuleTreeitem::Gate: gContentManager->getGraphTabWidget()->handleGateFocus(id); break; + case ModuleItem::TreeItemType::Module: gContentManager->getGraphTabWidget()->handleModuleFocus(id); break; + case ModuleItem::TreeItemType::Gate: gContentManager->getGraphTabWidget()->handleGateFocus(id); break; } } ); menu.addSection("Python Code"); - QString pythonGetObject = (type == ModuleTreeitem::Module) ? PyCodeProvider::pyCodeModule(id) : PyCodeProvider::pyCodeGate(id); - QString pythonDescription = (type == ModuleTreeitem::Module) ? "Get module" : "Get gate"; + QString pythonGetObject = (type == ModuleItem::TreeItemType::Module) ? PyCodeProvider::pyCodeModule(id) : PyCodeProvider::pyCodeGate(id); + QString pythonDescription = (type == ModuleItem::TreeItemType::Module) ? "Get module" : "Get gate"; menu.addAction(QIcon(":/icons/python"), pythonDescription, [pythonGetObject]() { 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 deleted file mode 100644 index 630bed28d37..00000000000 --- a/plugins/gui/src/selection_details_widget/module_details_widget/module_tree_model.cpp +++ /dev/null @@ -1,477 +0,0 @@ -#include "gui/selection_details_widget/module_details_widget/module_tree_model.h" -#include "gui/selection_details_widget/selection_details_icon_provider.h" -#include "hal_core/netlist/module.h" -#include "hal_core/netlist/gate.h" -#include "gui/gui_globals.h" -#include - -namespace hal -{ - - - ModuleTreeitem::ModuleTreeitem(ItemType itp, int id, const QString &name, const QString &ntp) - : mItemType(itp), mId(id), mName(name), mNodeType(ntp) - {;} - - QVariant ModuleTreeitem::getData(int index) const - { - switch (index) - { - case 0: - return mName; - case 1: - return mId; - case 2: - return mNodeType; - } - return QVariant(); - } - - void ModuleTreeitem::setData(QList data) - { - mName = data[0].toString(); - mId = data[1].toInt(); - mNodeType = data[2].toString(); - } - - void ModuleTreeitem::setDataAtIndex(int index, QVariant &data) - { - const char* ctyp[] = { "module", "gate"}; - - 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]) - { - mNodeType = data.toString(); - break; - } - } - } - - void ModuleTreeitem::appendData(QVariant data) - { - - } - - int ModuleTreeitem::getColumnCount() const - { - return 3; - } - - - ModuleTreeModel::ModuleTreeModel(QObject* parent) : BaseTreeModel(parent), mModId(-1) - { - setHeaderLabels(QStringList() << "Name" << "ID" << "Type"); - } - - ModuleTreeModel::~ModuleTreeModel() - { - - } - - void ModuleTreeModel::setModule(Module *m) - { - clearOwnStructures(); - if(!m) - { - clear(); - disconnectEvents(); - return; - //disconnect all events? - } - beginResetModel(); - //delete all children, not the root item (manually for performance reasons) - while(mRootItem->getChildCount() > 0) - { - BaseTreeItem* tmp = mRootItem->removeChildAtPos(0); - delete tmp; - } - - mModId = m->get_id(); - //add modules - for(auto mod : m->get_submodules()) - { - ModuleTreeitem* modItem = new ModuleTreeitem(ModuleTreeitem::Module, - mod->get_id(), - QString::fromStdString(mod->get_name()), - QString::fromStdString(mod->get_type())); - moduleRecursive(mod, modItem); - mRootItem->appendChild(modItem); - mModuleToTreeitems.insert(mod, modItem); - } - //add gates - for(auto gate : m->get_gates()) - { - ModuleTreeitem* gateItem = new ModuleTreeitem(ModuleTreeitem::Gate, - gate->get_id(), - QString::fromStdString(gate->get_name()), - QString::fromStdString(gate->get_type()->get_name())); - mRootItem->appendChild(gateItem); - mGateToTreeitems.insert(gate, gateItem); - } - endResetModel(); - - if(!mEventsConnected) - connectEvents(); - - Q_EMIT numberOfSubmodulesChanged(m->get_submodules().size()); - } - - void ModuleTreeModel::clear() - { - BaseTreeModel::clear(); - clearOwnStructures(); - } - - QVariant ModuleTreeModel::data(const QModelIndex &index, int role) const - { - if(!index.isValid()) - return QVariant(); - - ModuleTreeitem* item = dynamic_cast(getItemFromIndex(index)); - if(!item) - return QVariant(); - - if(role == Qt::DecorationRole && index.column() == 0) - return getIconFromItem(item); - - //yes, it performs the same two checks again, should be okay though (in terms of performance) - return BaseTreeModel::data(index, role); - - } - - void ModuleTreeModel::moduleRecursive(Module *mod, BaseTreeItem *modItem) - { - ModuleTreeitem* subModItem = nullptr; - for(Module* subMod : mod->get_submodules()) - { - subModItem = new ModuleTreeitem(ModuleTreeitem::Module, - subMod->get_id(), - QString::fromStdString(subMod->get_name()), - QString::fromStdString(subMod->get_type())); - moduleRecursive(subMod, subModItem); - modItem->appendChild(subModItem); - mModuleToTreeitems.insert(subMod, subModItem); - } - for(auto gate : mod->get_gates()) - { - ModuleTreeitem* gateItem = new ModuleTreeitem(ModuleTreeitem::Gate, - gate->get_id(), - QString::fromStdString(gate->get_name()), - QString::fromStdString(gate->get_type()->get_name())); - modItem->appendChild(gateItem); - mGateToTreeitems.insert(gate, gateItem); - } - } - - void ModuleTreeModel::updateGatesOfModule(Module* mod) - { - auto modItem = mModuleToTreeitems.value(mod, nullptr); - if((int)mod->get_id() == mModId) - modItem = mRootItem; - if(!modItem) - return; - - //1. Find index of first gate-type item - int startIndex = 0; - for(; startIndex < modItem->getChildCount(); startIndex++) - { - if(static_cast(modItem->getChild(startIndex))->itemType() != ModuleTreeitem::Module) - break; - } - - beginResetModel(); - - //2. Check if removing of gates is necessary, if yes remove them - if(startIndex < modItem->getChildCount()) - { - while(modItem->getChildCount() > startIndex) - { - auto child = modItem->removeChildAtPos(modItem->getChildCount()-1); - auto gate = gNetlist->get_gate_by_id(child->getData(sIdColumn).toInt()); - mGateToTreeitems.remove(gate); - delete child; - } - } - - //3. Check if adding of gates is necessary, if yes add them - if(!mod->get_gates().empty()) - { - beginResetModel(); - for(auto gate : mod->get_gates()) - { - ModuleTreeitem* gateItem = new ModuleTreeitem(ModuleTreeitem::Gate, - gate->get_id(), - QString::fromStdString(gate->get_name()), - QString::fromStdString(gate->get_type()->get_name())); - modItem->appendChild(gateItem); - mGateToTreeitems.insert(gate, gateItem); - } - } - endResetModel(); - } - - QIcon ModuleTreeModel::getIconFromItem(ModuleTreeitem *item) const - { - if(!item) - return QIcon(); - - u32 id = item->getData(1).toInt(); - switch (item->itemType()) - { - case ModuleTreeitem::Module: - return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::ModuleIcon,id)); - case ModuleTreeitem::Gate: - return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::GateIcon,id)); - default: - return QIcon(); - } - } - - void ModuleTreeModel::clearOwnStructures() - { - mGateToTreeitems.clear(); - mModuleToTreeitems.clear(); - mModId = -1; - } - - void ModuleTreeModel::handleModuleGatesAssignBegin(Module *m, u32 associated_data) - { - if((int)associated_data <= mThreshold) - return; - - if(mModuleToTreeitems.value(m, nullptr) || (int)m->get_id() == mModId) - disconnect(gNetlistRelay, &NetlistRelay::moduleGateAssigned, this, &ModuleTreeModel::handleModuleGateAssigned); - } - - void ModuleTreeModel::handleModuleGatesAssignEnd(Module *m, u32 associated_data) - { - Q_UNUSED(associated_data) - if((int)associated_data <= mThreshold) - return; - - if(mModuleToTreeitems.value(m, nullptr) || (mModId == (int)m->get_id() && gNetlist->get_module_by_id(mModId))) - { - connect(gNetlistRelay, &NetlistRelay::moduleGateAssigned, this, &ModuleTreeModel::handleModuleGateAssigned); - updateGatesOfModule(m); - } - } - - void ModuleTreeModel::handleModuleGatesRemoveBegin(Module *m, u32 associated_data) - { - if((int)associated_data <= mThreshold) - return; - - if(mModuleToTreeitems.value(m, nullptr) || (int)m->get_id() == mModId) - disconnect(gNetlistRelay, &NetlistRelay::moduleGateRemoved, this, &ModuleTreeModel::handleModuleGateRemoved); - } - - void ModuleTreeModel::handleModuleGatesRemoveEnd(Module *m, u32 associated_data) - { - if((int)associated_data <= mThreshold) - return; - - if(mModuleToTreeitems.value(m, nullptr) || (mModId == (int)m->get_id() && gNetlist->get_module_by_id(mModId))) - { - connect(gNetlistRelay, &NetlistRelay::moduleGateRemoved, this, &ModuleTreeModel::handleModuleGateRemoved); - updateGatesOfModule(m); - } - } - - void ModuleTreeModel::handleModuleSubmoduleAdded(Module *m, u32 added_module) - { - auto parentModItem = mModuleToTreeitems.value(m, nullptr); - if(parentModItem || (int)m->get_id() == mModId) - { - beginResetModel(); - auto addedMod = gNetlist->get_module_by_id(added_module); - ModuleTreeitem* addedSubmodItem = new ModuleTreeitem(ModuleTreeitem::Module, - addedMod->get_id(), - QString::fromStdString(addedMod->get_name()), - QString::fromStdString(addedMod->get_type())); - moduleRecursive(addedMod, addedSubmodItem); - parentModItem ? parentModItem->insertChild(0, addedSubmodItem) : mRootItem->insertChild(0, addedSubmodItem); - mModuleToTreeitems.insert(addedMod, addedSubmodItem); - endResetModel(); - } - } - - void ModuleTreeModel::handleModuleSubmoduleRemoved(Module *m, u32 removed_module) - { - Q_UNUSED(m) - - auto removedModItem = mModuleToTreeitems.value(gNetlist->get_module_by_id(removed_module), nullptr); - if(!removedModItem) - return; - - //1. Remove all items from maps through BFS (maybe own function?) - QQueue treeItemsQueue; - treeItemsQueue.enqueue(removedModItem); - while(!treeItemsQueue.isEmpty()) - { - ModuleTreeitem* current = static_cast(treeItemsQueue.dequeue()); - switch (current->itemType()) - { - case ModuleTreeitem::Module: mModuleToTreeitems.remove(gNetlist->get_module_by_id(current->getData(ModuleTreeModel::sIdColumn).toInt())); break; - case ModuleTreeitem::Gate: mGateToTreeitems.remove(gNetlist->get_gate_by_id(current->getData(ModuleTreeModel::sIdColumn).toInt()));break; - } - for(auto child : current->getChildren()) - treeItemsQueue.enqueue(child); - } - - //2. Delete item, reset model - //beginRemoveRows(parent(getIndexFromItem(removedModItem)), removedModItem->getOwnRow(), removedModItem->getOwnRow()); - beginResetModel(); - removedModItem->getParent()->removeChild(removedModItem); - delete removedModItem; - endResetModel(); - //endRemoveRows(); - } - - void ModuleTreeModel::handleModuleGateAssigned(Module *m, u32 assigned_gate) - { - BaseTreeItem* modItem = mModuleToTreeitems.value(m, nullptr); - if((int)m->get_id() == mModId) - modItem = mRootItem; - - if(!modItem) - return; - - auto assignedGate = gNetlist->get_gate_by_id(assigned_gate); - int indexToInsert = 0; //first item after the modules - for(; indexToInsert < modItem->getChildCount(); indexToInsert++) - if(static_cast(modItem->getChild(indexToInsert))->itemType() != ModuleTreeitem::Module) - break; - - ModuleTreeitem* gateItem = new ModuleTreeitem(ModuleTreeitem::Gate, - assignedGate->get_id(), - QString::fromStdString(assignedGate->get_name()), - QString::fromStdString(assignedGate->get_type()->get_name())); - mGateToTreeitems.insert(assignedGate, gateItem); - //beginInsertRows(getIndexFromItem(modItem), indexToInsert, indexToInsert); - beginResetModel(); - modItem->insertChild(indexToInsert, gateItem); - endResetModel(); - //endInsertRows(); - } - - void ModuleTreeModel::handleModuleGateRemoved(Module *m, u32 removed_gate) - { - Q_UNUSED(m) - //only works if the gate is first removed from the module, then added to another (otherwise wrong one is removed) - auto gate = gNetlist->get_gate_by_id(removed_gate); - auto gateItem = mGateToTreeitems.value(gate); - if(!gateItem) - return; - - //beginRemoveRows(parent(getIndexFromItem(gateItem)), gateItem->getOwnRow(), gateItem->getOwnRow()); - beginResetModel(); - mGateToTreeitems.remove(gate); - gateItem->getParent()->removeChild(gateItem); - delete gateItem; - endResetModel(); - //endRemoveRows(); - } - - void ModuleTreeModel::handleModuleRemoved(Module *m) - { - if((int)m->get_id() == mModId) - clear(); - } - - void ModuleTreeModel::handleGateNameChanged(Gate *g) - { - auto gateItem = mGateToTreeitems.value(g, nullptr); - if(gateItem) - { - 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); - } - } - - void ModuleTreeModel::handleModuleNameChanged(Module *m) - { - auto moduleItem = mModuleToTreeitems.value(m, nullptr); - if(moduleItem) - { - 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); - } - } - - void ModuleTreeModel::handleModuleTypeChanged(Module *m) - { - auto moduleItem = mModuleToTreeitems.value(m, nullptr); - if(moduleItem) - { - 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); - } - } - - void ModuleTreeModel::disconnectEvents() - { - //guards - disconnect(gNetlistRelay, &NetlistRelay::moduleGatesAssignEnd, this, &ModuleTreeModel::handleModuleGatesAssignEnd); - disconnect(gNetlistRelay, &NetlistRelay::moduleGatesAssignBegin, this, &ModuleTreeModel::handleModuleGatesAssignBegin); - disconnect(gNetlistRelay, &NetlistRelay::moduleGatesRemoveBegin, this, &ModuleTreeModel::handleModuleGatesRemoveBegin); - disconnect(gNetlistRelay, &NetlistRelay::moduleGatesRemoveEnd, this, &ModuleTreeModel::handleModuleGatesRemoveEnd); - - //actual events - disconnect(gNetlistRelay, &NetlistRelay::moduleSubmoduleAdded, this, &ModuleTreeModel::handleModuleSubmoduleAdded); - disconnect(gNetlistRelay, &NetlistRelay::moduleSubmoduleRemoved, this, &ModuleTreeModel::handleModuleSubmoduleRemoved); - - disconnect(gNetlistRelay, &NetlistRelay::moduleGateAssigned, this, &ModuleTreeModel::handleModuleGateAssigned); - disconnect(gNetlistRelay, &NetlistRelay::moduleGateRemoved, this, &ModuleTreeModel::handleModuleGateRemoved); - - disconnect(gNetlistRelay, &NetlistRelay::moduleRemoved, this, &ModuleTreeModel::handleModuleRemoved); - - //information change - disconnect(gNetlistRelay, &NetlistRelay::gateNameChanged, this, &ModuleTreeModel::handleGateNameChanged); - disconnect(gNetlistRelay, &NetlistRelay::moduleNameChanged, this, &ModuleTreeModel::handleModuleNameChanged); - disconnect(gNetlistRelay, &NetlistRelay::moduleTypeChanged, this, &ModuleTreeModel::handleModuleTypeChanged); - - mEventsConnected = false; - } - - void ModuleTreeModel::connectEvents() - { - //guards - connect(gNetlistRelay, &NetlistRelay::moduleGatesAssignEnd, this, &ModuleTreeModel::handleModuleGatesAssignEnd); - connect(gNetlistRelay, &NetlistRelay::moduleGatesAssignBegin, this, &ModuleTreeModel::handleModuleGatesAssignBegin); - connect(gNetlistRelay, &NetlistRelay::moduleGatesRemoveBegin, this, &ModuleTreeModel::handleModuleGatesRemoveBegin); - connect(gNetlistRelay, &NetlistRelay::moduleGatesRemoveEnd, this, &ModuleTreeModel::handleModuleGatesRemoveEnd); - - //actual events - connect(gNetlistRelay, &NetlistRelay::moduleSubmoduleAdded, this, &ModuleTreeModel::handleModuleSubmoduleAdded); - connect(gNetlistRelay, &NetlistRelay::moduleSubmoduleRemoved, this, &ModuleTreeModel::handleModuleSubmoduleRemoved); - - connect(gNetlistRelay, &NetlistRelay::moduleGateAssigned, this, &ModuleTreeModel::handleModuleGateAssigned); - connect(gNetlistRelay, &NetlistRelay::moduleGateRemoved, this, &ModuleTreeModel::handleModuleGateRemoved); - - connect(gNetlistRelay, &NetlistRelay::moduleRemoved, this, &ModuleTreeModel::handleModuleRemoved); - - //information change - connect(gNetlistRelay, &NetlistRelay::gateNameChanged, this, &ModuleTreeModel::handleGateNameChanged); - connect(gNetlistRelay, &NetlistRelay::moduleNameChanged, this, &ModuleTreeModel::handleModuleNameChanged); - connect(gNetlistRelay, &NetlistRelay::moduleTypeChanged, this, &ModuleTreeModel::handleModuleTypeChanged); - - 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 deleted file mode 100644 index bf68a43ff41..00000000000 --- a/plugins/gui/src/selection_details_widget/module_details_widget/netlist_elements_tree_model.cpp +++ /dev/null @@ -1,485 +0,0 @@ -#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/base_tree_item.h" -#include "hal_core/netlist/module.h" -#include "hal_core/netlist/gate.h" -#include "gui/gui_globals.h" -#include -#include - -namespace hal -{ - - NetlistElementsTreeitem::NetlistElementsTreeitem(ItemType itp, u32 id_, const QString &name, const QString &ntp) - : mItemType(itp), mId(id_), mName(name), mNodeType(ntp) - {;} - - QVariant NetlistElementsTreeitem::getData(int index) const - { - switch (index) - { - case 0: - return mName; - case 1: - return mId; - case 2: - return mNodeType; - } - return QVariant(); - } - - void NetlistElementsTreeitem::setData(QList data) - { - mName = data[0].toString(); - mId = data[1].toInt(); - mNodeType = 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]) - { - mNodeType = data.toString(); - break; - } - } - } - - void NetlistElementsTreeitem::appendData(QVariant data) {} - - 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(QStringList() << "Name" << "ID" << "Type"); - - // CONNECTIONS - connect(gNetlistRelay, &NetlistRelay::gateNameChanged, this, &NetlistElementsTreeModel::gateNameChanged); - connect(gNetlistRelay, &NetlistRelay::gateRemoved, this, &NetlistElementsTreeModel::gateRemoved); - connect(gNetlistRelay, &NetlistRelay::netRemoved, this, &NetlistElementsTreeModel::netRemoved); - connect(gNetlistRelay, &NetlistRelay::moduleNameChanged, this, &NetlistElementsTreeModel::moduleNameChanged); - connect(gNetlistRelay, &NetlistRelay::moduleTypeChanged, this, &NetlistElementsTreeModel::moduleTypeChanged); - connect(gNetlistRelay, &NetlistRelay::moduleGateRemoved, this, &NetlistElementsTreeModel::moduleGateRemoved, Qt::QueuedConnection); - connect(gNetlistRelay, &NetlistRelay::moduleGateAssigned, this, &NetlistElementsTreeModel::moduleGateAssigned); - connect(gNetlistRelay, &NetlistRelay::moduleSubmoduleRemoved, this, &NetlistElementsTreeModel::moduleSubmoduleRemoved); - connect(gNetlistRelay, &NetlistRelay::moduleSubmoduleAdded, this, &NetlistElementsTreeModel::moduleSubmoduleAdded); - } - - NetlistElementsTreeModel::~NetlistElementsTreeModel() - { - delete mRootItem; - } - - QVariant NetlistElementsTreeModel::data(const QModelIndex &index, int role) const - { - if(!index.isValid()) - return QVariant(); - - BaseTreeItem* item = getItemFromIndex(index); - if(!item) - return QVariant(); - - 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); - } - - void NetlistElementsTreeModel::clear() - { - BaseTreeModel::clear(); - mModuleToTreeitems.clear(); - mGateToTreeitems.clear(); - mNetToTreeitems.clear(); - mDisplaySubmodRecursive = true; - mGatesDisplayed = true; - mNetsDisplayed = true; - mCurrentlyDisplayingModule = false; - mModId = -1; - } - - void NetlistElementsTreeModel::setContent(QList modIds, QList gateIds, QList netIds, bool displayModulesRecursive, bool showGatesInSubmods, bool showNetsInSubmods) - { - mDisplaySubmodRecursive = displayModulesRecursive; - mGatesDisplayed = showGatesInSubmods; - mNetsDisplayed = showNetsInSubmods; - - //i need to temp. store this because clear() is called.... - bool disPlayedModtmp = mCurrentlyDisplayingModule; - int modIdtmp = mModId; - - clear(); - - mCurrentlyDisplayingModule = disPlayedModtmp; - mModId = modIdtmp; - - beginResetModel(); - for(int id : modIds) - { - Module* mod = gNetlist->get_module_by_id(id); - if(!mod) - continue; - NetlistElementsTreeitem* modItem = new NetlistElementsTreeitem(NetlistElementsTreeitem::Module, - mod->get_id(), - QString::fromStdString(mod->get_name()), - QString::fromStdString(mod->get_type())); - if(displayModulesRecursive) - moduleRecursive(mod, modItem, showGatesInSubmods, showNetsInSubmods); - mRootItem->appendChild(modItem); - mModuleToTreeitems.insert(mod, modItem); - } - //no need to check if gates should be displayed, because if not, just give a empty gateIds list (same for nets) - for(int id : gateIds) - { - Gate* gate = gNetlist->get_gate_by_id(id); - NetlistElementsTreeitem* gateItem = new NetlistElementsTreeitem(NetlistElementsTreeitem::Gate, - gate->get_id(), - QString::fromStdString(gate->get_name()), - QString::fromStdString(gate->get_type()->get_name())); - mRootItem->appendChild(gateItem); - mGateToTreeitems.insert(gate, gateItem); - } - for(int id : netIds) - { - Net* net = gNetlist->get_net_by_id(id); - NetlistElementsTreeitem* netItem = new NetlistElementsTreeitem(NetlistElementsTreeitem::Net, - net->get_id(), - QString::fromStdString(net->get_name())); - mRootItem->appendChild(netItem); - mNetToTreeitems.insert(net, netItem); - } - endResetModel(); - } - - void NetlistElementsTreeModel::setModule(Module* mod, bool showGates, bool showNets, bool displayModulesRecursive) - { - mCurrentlyDisplayingModule = true; - mModId = mod->get_id(); - - QList subModIds, gateIds, netIds; - for(auto subMod : mod->get_submodules()) - subModIds.append(subMod->get_id()); - - if(showGates) - for(auto gate : mod->get_gates()) - gateIds.append(gate->get_id()); - - if(showNets) - for(auto net : mod->get_internal_nets()) - netIds.append(net->get_id()); - - setContent(subModIds, gateIds, netIds, displayModulesRecursive, showGates, showNets); - Q_EMIT numberOfSubmodulesChanged(mod->get_submodules().size()); - } - - void NetlistElementsTreeModel::gateNameChanged(Gate *g) - { - for(BaseTreeItem* gateItem : mGateToTreeitems.values(g)) - { - 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); - } - } - - void NetlistElementsTreeModel::gateRemoved(Gate *g) - { - QList items = mGateToTreeitems.values(g); - for(NetlistElementsTreeitem* gateItem : items) - { - beginRemoveRows(parent(getIndexFromItem(gateItem)), gateItem->getOwnRow(), gateItem->getOwnRow()); - gateItem->getParent()->removeChild(gateItem); - endRemoveRows(); - mGateToTreeitems.remove(g, gateItem); - if(mNetsDisplayed && ( (gateItem->getParent() == mRootItem && mCurrentlyDisplayingModule) || gateItem->getParent() != mRootItem)) - { - beginResetModel(); - NetlistElementsTreeitem* neti = static_cast(gateItem->getParent()); - updateInternalNetsOfModule(neti);//perhaps for all parents? go until the mRootItem node? - endResetModel(); - } - delete gateItem; - } - } - - void NetlistElementsTreeModel::netNameChanged(Net *n) - { - for(NetlistElementsTreeitem* netItem : mNetToTreeitems.values(n)) - { - 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); - } - } - - void NetlistElementsTreeModel::netRemoved(Net *n) - { - QList items = mNetToTreeitems.values(n); - for(NetlistElementsTreeitem* netItem : items) - { - beginRemoveRows(parent(getIndexFromItem(netItem)), netItem->getOwnRow(), netItem->getOwnRow()); - netItem->getParent()->removeChild(netItem); - endRemoveRows(); - mNetToTreeitems.remove(n, netItem); - delete netItem; - } - } - - void NetlistElementsTreeModel::moduleNameChanged(Module *m) - { - for(NetlistElementsTreeitem* modItem : mModuleToTreeitems.values(m)) - { - 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())); - } - } - - void NetlistElementsTreeModel::moduleTypeChanged(Module *m) - { - for(NetlistElementsTreeitem* modItem : mModuleToTreeitems.values(m)) - { - 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())); - } - } - - void NetlistElementsTreeModel::moduleSubmoduleRemoved(Module *m, int removed_module) - { - //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(NetlistElementsTreeitem* removedSubmodItem : mModuleToTreeitems.values(removedMod)) - { - tmpSubmodItems.append(removedSubmodItem); - QQueue treeItemsQueue; - treeItemsQueue.enqueue(removedSubmodItem); - while(!treeItemsQueue.isEmpty()) - { - NetlistElementsTreeitem* currentItem = treeItemsQueue.dequeue(); - int id = currentItem->id(); - - switch (currentItem->itemType()) - { - case NetlistElementsTreeitem::Module : mModuleToTreeitems.remove(gNetlist->get_module_by_id(id),currentItem); break; - case NetlistElementsTreeitem::Gate : mGateToTreeitems.remove(gNetlist->get_gate_by_id(id), currentItem); break; - case NetlistElementsTreeitem::Net : mNetToTreeitems.remove(gNetlist->get_net_by_id(id), currentItem); break; - } - - 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(NetlistElementsTreeitem* removedSubItem : tmpSubmodItems) - { - removedSubItem->getParent()->removeChild(removedSubItem); - if(mNetsDisplayed) { - NetlistElementsTreeitem* neti = static_cast(removedSubItem->getParent()); - updateInternalNetsOfModule(neti); - } - delete removedSubItem; - } - endResetModel(); - - if((int)m->get_id() == mModId) - Q_EMIT numberOfSubmodulesChanged(m->get_submodules().size()); - - if(removed_module == mModId) - clear(); - } - - void NetlistElementsTreeModel::moduleGateAssigned(Module *m, int assigned_gate) - { - if(!mGatesDisplayed || (mModuleToTreeitems.values(m).isEmpty() && !(mCurrentlyDisplayingModule && mModId != (int)m->get_id()))) - return; - - 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](BaseTreeItem* modItem){ - int indexToInsert = 0; - for(; indexToInsert < modItem->getChildCount(); indexToInsert++) { - NetlistElementsTreeitem* neti = static_cast(modItem->getChild(indexToInsert)); - if(neti->itemType() != NetlistElementsTreeitem::Module) - break; - } - - NetlistElementsTreeitem* gateItem = new NetlistElementsTreeitem(NetlistElementsTreeitem::Gate, - assignedGate->get_id(), - QString::fromStdString(assignedGate->get_name()), - QString::fromStdString(assignedGate->get_type()->get_name())); - //beginInsertRows(getIndexFromItem(modItem), indexToInsert, indexToInsert); - beginResetModel(); - modItem->insertChild(indexToInsert, gateItem); - //endInsertRows(); - mGateToTreeitems.insert(assignedGate, gateItem); - if(mNetsDisplayed) { - NetlistElementsTreeitem* neti = static_cast(modItem); - updateInternalNetsOfModule(neti); - } - endResetModel(); - }; - - //special case when we actually displaying the content of a module through setModule - if(mCurrentlyDisplayingModule && mModId == (int)m->get_id()) - appendNewGateToModule(mRootItem); - - //standard case in which you do the same as obove, but just go through each module item - for(BaseTreeItem* modItem : mModuleToTreeitems.values(m)) - appendNewGateToModule(modItem); - } - - void NetlistElementsTreeModel::moduleGateRemoved(Module *m, int removed_gate) - { - Q_UNUSED(m) //does not depend on the module but on the gate, simply removed them.. - gateRemoved(gNetlist->get_gate_by_id(removed_gate)); - } - - void NetlistElementsTreeModel::moduleSubmoduleAdded(Module *m, int added_module) - { - if(mModuleToTreeitems.values(m).isEmpty() && !(mCurrentlyDisplayingModule && (int)m->get_id() == mModId)) - return; - - beginResetModel(); - Module* addedModule = gNetlist->get_module_by_id(added_module); - - auto appendNewSubmodItem = [this, addedModule](BaseTreeItem* parentModItem){ - NetlistElementsTreeitem* addedSubmodItem = new NetlistElementsTreeitem(NetlistElementsTreeitem::Module, - addedModule->get_id(), - QString::fromStdString(addedModule->get_name()), - QString::fromStdString(addedModule->get_type())); - moduleRecursive(addedModule, addedSubmodItem, mGatesDisplayed, mNetsDisplayed); - parentModItem->insertChild(0, addedSubmodItem); - mModuleToTreeitems.insert(addedModule, addedSubmodItem); - if(mNetsDisplayed) { - NetlistElementsTreeitem* neti = static_cast(parentModItem); - updateInternalNetsOfModule(neti); - } - }; - - //special case when a module is represented with setModule - if(mCurrentlyDisplayingModule && (int)m->get_id() == mModId) - { - appendNewSubmodItem(mRootItem); - Q_EMIT numberOfSubmodulesChanged(m->get_submodules().size()); - } - - //standard case for all displayed things - for(NetlistElementsTreeitem* parentModItem : mModuleToTreeitems.values(m)) - appendNewSubmodItem(parentModItem); - - endResetModel(); - } - - void NetlistElementsTreeModel::moduleRecursive(Module* mod, NetlistElementsTreeitem* modItem, bool showGates, bool showNets) - { - NetlistElementsTreeitem* subModItem = nullptr; - for(Module* subMod : mod->get_submodules()) - { - subModItem = new NetlistElementsTreeitem(NetlistElementsTreeitem::Module, - subMod->get_id(), - QString::fromStdString(subMod->get_name()), - QString::fromStdString(subMod->get_type())); - moduleRecursive(subMod, subModItem, showGates); - modItem->appendChild(subModItem); - mModuleToTreeitems.insert(subMod, subModItem); - } - if(showGates) - { - for(auto gate : mod->get_gates()) - { - NetlistElementsTreeitem* gateItem = new NetlistElementsTreeitem(NetlistElementsTreeitem::Gate, - gate->get_id(), - QString::fromStdString(gate->get_name()), - QString::fromStdString(gate->get_type()->get_name())); - modItem->appendChild(gateItem); - mGateToTreeitems.insert(gate, gateItem); - } - } - if(showNets) - { - for(auto net : mod->get_internal_nets()) - { - NetlistElementsTreeitem* netItem = new NetlistElementsTreeitem(NetlistElementsTreeitem::Net, - net->get_id(), - QString::fromStdString(net->get_name()), - ""); - modItem->appendChild(netItem); - mNetToTreeitems.insert(net, netItem); - } - } - } - - QIcon NetlistElementsTreeModel::getIconFromItem(NetlistElementsTreeitem *item) const - { - if(!item) - return QIcon(); - - u32 id = item->getData(1).toInt(); - switch (item->itemType()) - { - case NetlistElementsTreeitem::Module: - return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::ModuleIcon,id)); - case NetlistElementsTreeitem::Gate: - return QIcon(*SelectionDetailsIconProvider::instance()->getIcon(SelectionDetailsIconProvider::GateIcon,id)); - default: - return QIcon(); - } - } - - void NetlistElementsTreeModel::updateInternalNetsOfModule(NetlistElementsTreeitem *moduleItem) - { - BaseTreeItem* moduleItemBase = static_cast(moduleItem); - BaseTreeItem* mRootBase = static_cast(mRootItem); - int moduleId = (moduleItemBase == mRootBase) ? mModId : moduleItem->id(); - 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 && static_cast(moduleItem->getChild(moduleItem->getChildCount()-1))->itemType() == NetlistElementsTreeitem::Net) - { - NetlistElementsTreeitem* lastNetItem = static_cast(moduleItem->removeChildAtPos(moduleItem->getChildCount()-1)); - mNetToTreeitems.remove(gNetlist->get_net_by_id(lastNetItem->id()), lastNetItem); - delete lastNetItem; - } - //append (potentionally) new internal nets - for(Net* n : mod->get_internal_nets()) - { - NetlistElementsTreeitem* netItem = new NetlistElementsTreeitem(NetlistElementsTreeitem::Net, - n->get_id(), - QString::fromStdString(n->get_name()), - ""); - //netItem->setAdditionalData(keyItemType, itemType::net); - mNetToTreeitems.insert(n, netItem); - moduleItem->appendChild(netItem); - } - } -} 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 1a7791ba911..7106b7cb729 100644 --- a/plugins/gui/src/selection_details_widget/selection_details_widget.cpp +++ b/plugins/gui/src/selection_details_widget/selection_details_widget.cpp @@ -80,9 +80,9 @@ namespace hal mSelectionTreeView = new SelectionTreeView(treeViewContainer); - mSelectionTreeModel = new SelectionTreeModel(this); + mModuleModel = new ModuleModel(this); mSelectionTreeProxyModel = new SelectionTreeProxyModel(this); - mSelectionTreeProxyModel->setSourceModel(mSelectionTreeModel); + mSelectionTreeProxyModel->setSourceModel(mModuleModel); mSelectionTreeView->setModel(mSelectionTreeProxyModel); //mSelectionTreeProxyModel->setSourceModel(mSelectionTreeView->model()); @@ -295,25 +295,24 @@ namespace hal QSet mods = {}; QSet gates = {}; QSet nets = {}; - auto* sourceModel = static_cast(mSelectionTreeProxyModel->sourceModel()); + auto* sourceModel = static_cast(mSelectionTreeProxyModel->sourceModel()); //check each row for its Itemtype and append the ID to the corresponding QSet {mods, gates, nets} 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,17 +442,15 @@ namespace hal mStackedWidget->setCurrentWidget(mNoSelectionLabel); } - void SelectionDetailsWidget::singleSelectionInternal(const SelectionTreeItem *sti) + void SelectionDetailsWidget::singleSelectionInternal(const ModuleItem *sti) { - SelectionTreeItem::TreeItemType tp = sti - ? sti->itemType() - : SelectionTreeItem::NullItem; - - switch (tp) { - case SelectionTreeItem::NullItem: + if(!sti){ showNoSelection(); - break; - case SelectionTreeItem::ModuleItem: + return; + } + + switch (sti->getType()) { + case ModuleItem::TreeItemType::Module: if (Module* m = gNetlist->get_module_by_id(sti->id()); m) { mModuleDetailsTabs->setModule(m); @@ -465,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) { @@ -474,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) { @@ -524,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 1fbdd78594e..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 deleted file mode 100644 index 03772c02da5..00000000000 --- a/plugins/gui/src/selection_details_widget/tree_navigation/selection_tree_model.cpp +++ /dev/null @@ -1,331 +0,0 @@ -#include "gui/selection_details_widget/tree_navigation/selection_tree_model.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" -#include "hal_core/netlist/module.h" -#include "gui/gui_utils/graphics.h" -#include "hal_core/netlist/grouping.h" -#include - -namespace hal -{ - SelectionTreeModel::SelectionTreeModel(QObject* parent) - : QAbstractItemModel(parent), mDoNotDisturb(0) - { - 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; - } - - void SelectionTreeModel::fetchSelection(bool hasEntries, u32 groupingId) - { - SelectionTreeItemRoot* nextRootItem - = new SelectionTreeItemRoot(); - if (!groupingId) - { - if (hasEntries) - { - for(u32 id : gSelectionRelay->selectedModulesList()) - { - SelectionTreeItemModule* stim = new SelectionTreeItemModule(id); - moduleRecursion(stim); - nextRootItem->addChild(stim); - } - - for(u32 id : gSelectionRelay->selectedGatesList()) - nextRootItem->addChild(new SelectionTreeItemGate(id)); - - for(u32 id : gSelectionRelay->selectedNetsList()) - nextRootItem->addChild(new SelectionTreeItemNet(id)); - } - } - else - { - Grouping* grouping = gNetlist->get_grouping_by_id(groupingId); - if (grouping) - { - for (u32 id : grouping->get_module_ids()) - { - SelectionTreeItemModule* stim = new SelectionTreeItemModule(id); - moduleRecursion(stim); - nextRootItem->addChild(stim); - } - - for (u32 id : grouping->get_gate_ids()) - { - nextRootItem->addChild(new SelectionTreeItemGate(id)); - } - - for (u32 id : grouping->get_net_ids()) - { - nextRootItem->addChild(new SelectionTreeItemNet(id)); - } - } - } - 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; - - 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 b2b8dbb1273..4492eee9b6c 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,5 @@ #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" @@ -40,7 +39,7 @@ namespace hal return comparison; } - void SelectionTreeProxyModel::applyFilterOnGraphics() + /*void SelectionTreeProxyModel::applyFilterOnGraphics() { if (isGraphicsBusy()) return; ++ mGraphicsBusy; @@ -50,14 +49,14 @@ namespace hal static_cast(sourceModel())->suppressedByFilter(modIds, gatIds, netIds, mFilterExpression); gSelectionRelay->suppressedByFilter(modIds, gatIds, netIds); -- mGraphicsBusy; - } + }*/ - void SelectionTreeProxyModel::handleFilterTextChanged(const QString& filter_text) + /*void SelectionTreeProxyModel::handleFilterTextChanged(const QString& filter_text) { mFilterExpression.setPattern(filter_text); invalidateFilter(); applyFilterOnGraphics(); - } + }*/ gui_utility::mSortMechanism SelectionTreeProxyModel::sortMechanism() { 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 5a6daba7c14..a6b5346de8b 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 @@ -7,6 +7,7 @@ #include "gui/user_action/action_create_object.h" #include "gui/user_action/action_add_items_to_object.h" #include "gui/user_action/user_action_compound.h" +#include "hal_core/netlist/grouping.h" #include #include @@ -34,9 +35,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 +45,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 +59,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 +76,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 +93,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 +110,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 +121,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 +130,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 +141,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 +159,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); @@ -243,14 +237,34 @@ namespace hal { SelectionTreeProxyModel* treeProxy = dynamic_cast(model()); if (!treeProxy) return; - SelectionTreeModel* treeModel = dynamic_cast(treeProxy->sourceModel()); + ModuleModel* treeModel = dynamic_cast(treeProxy->sourceModel()); if (!treeModel) return; if (treeProxy->isGraphicsBusy()) return; setSelectionMode(QAbstractItemView::NoSelection); selectionModel()->clear(); - treeModel->fetchSelection(mVisible, groupingId); + + if (!groupingId) + { + if(mVisible) + { + QVector modIds = QVector::fromList(gSelectionRelay->selectedModulesList()); + QVector gateIds = QVector::fromList(gSelectionRelay->selectedGatesList()); + QVector netIds = QVector::fromList(gSelectionRelay->selectedNetsList()); + treeModel->populateTree(modIds, gateIds, netIds); + } + else treeModel->clear(); + } + else + { + Grouping* grouping = gNetlist->get_grouping_by_id(groupingId); + QVector modIds = QVector::fromStdVector(grouping->get_module_ids()); + QVector gateIds = QVector::fromStdVector(grouping->get_gate_ids()); + QVector netIds = QVector::fromStdVector(grouping->get_net_ids()); + treeModel->populateTree(modIds, gateIds, netIds); + } + if (mVisible) { show(); @@ -262,7 +276,7 @@ namespace hal else hide(); } - +/* void SelectionTreeView::handleFilterTextChanged(const QString& filter_text) { SelectionTreeProxyModel* treeProxy = dynamic_cast(model()); @@ -272,28 +286,28 @@ namespace hal QModelIndex defaultSel = treeProxy->index(0, 0, rootIndex()); if (defaultSel.isValid()) selectionModel()->setCurrentIndex(defaultSel, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); - } + }*/ SelectionTreeProxyModel* SelectionTreeView::proxyModel() { 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/gui/src/selection_relay/selection_relay.cpp b/plugins/gui/src/selection_relay/selection_relay.cpp index 6bec098f018..91a0072bf55 100644 --- a/plugins/gui/src/selection_relay/selection_relay.cpp +++ b/plugins/gui/src/selection_relay/selection_relay.cpp @@ -375,14 +375,14 @@ namespace hal relaySubfocusChanged(nullptr); } - void SelectionRelay::suppressedByFilter(const QList& modIds, const QList& gatIds, const QList& netIds) + /*void SelectionRelay::suppressedByFilter(const QList& modIds, const QList& gatIds, const QList& netIds) { initializeAction(); mModulesSuppressedByFilter = modIds.toSet(); mGatesSuppressedByFilter = gatIds.toSet(); mNetsSuppressedByFilter = netIds.toSet(); executeAction(); - } + }*/ bool SelectionRelay::isModuleSelected(u32 id) const { 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 4b10f402766..0174b716091 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);