Skip to content

Commit

Permalink
Merge pull request #568 from emsec/feature/migrate_selectionmodel_to_…
Browse files Browse the repository at this point in the history
…modulemodel

Feature/migrate selectionmodel to modulemodel
  • Loading branch information
joern274 authored May 30, 2024
2 parents 3164cba + 4e998fd commit 3380829
Show file tree
Hide file tree
Showing 30 changed files with 414 additions and 2,755 deletions.
4 changes: 2 additions & 2 deletions plugins/gui/include/gui/graph_widget/graphics_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -234,7 +234,7 @@ namespace hal
*
* @param highlightItems - The selection tree items to highlight
*/
void handleHighlight(const QVector<const SelectionTreeItem*>& highlightItems);
void handleHighlight(const QVector<const ModuleItem*>& highlightItems);

/**
* Q_SLOT to call whenever a module was assigned to or removed from a grouping. It is used to update the
Expand Down
9 changes: 1 addition & 8 deletions plugins/gui/include/gui/module_model/module_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*
Expand Down
99 changes: 64 additions & 35 deletions plugins/gui/include/gui/module_model/module_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -76,8 +81,7 @@ namespace hal
public:
/**
* Constructor. <br>
* 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.
*/
Expand Down Expand Up @@ -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
Expand All @@ -123,33 +127,50 @@ 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<ModuleItem*> getItems(const u32 id, ModuleItem::TreeItemType type = ModuleItem::TreeItemType::Module) const;

/**
* Clears the item model and deletes all ModuleItems.
*/
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<u32>& modIds = {}, const QVector<u32>& gatIds = {}, const QVector<u32>& 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.
*/
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.
*/
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.
Expand All @@ -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);

Expand Down Expand Up @@ -209,29 +231,29 @@ namespace hal
void updateNetParent(const Net* net, const QHash<const Net*,ModuleItem*>* 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
*/
Expand All @@ -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.
*
Expand Down Expand Up @@ -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
Expand All @@ -307,23 +353,6 @@ namespace hal
*/
void findNetParentRecursion(BaseTreeItem* parent, QHash<const Net*,ModuleItem*>& parentAssignment, std::unordered_set<Net*>& 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<u32, ModuleItem*> mModuleMap;
QMultiMap<u32, ModuleItem*> mGateMap;
QMultiMap<u32, ModuleItem*> mNetMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#pragma once

#include "gui/gui_utils/sort.h"

#include <QSortFilterProxyModel>

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 <b>true</b> if nets are filtered out now. <b>false</b> if not.
* @param filterNets if <b>true</b>, then nets are filtered out.
*/
void setFilterNets(bool filterNets);

/**
* Sets whether or not gates are filtered out by the filter.
* @returns <b>true</b> if gates are filtered out now. <b>false</b> if not.
* @param filterNets if <b>true</b>, 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 <b>true</b> if the row should be included in the model.
*/
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;

private:
bool mFilterNets;
bool mFilterGates;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QTreeView>

namespace hal
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 3380829

Please sign in to comment.