Skip to content

Commit

Permalink
Merge pull request #538 from emsec/feature/toggle_nets
Browse files Browse the repository at this point in the history
Feature/toggle nets
  • Loading branch information
joern274 authored Nov 17, 2023
2 parents 4efe0a6 + cd7d941 commit 0cec8c1
Show file tree
Hide file tree
Showing 51 changed files with 2,159 additions and 1,028 deletions.
1 change: 1 addition & 0 deletions include/hal_core/netlist/netlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ namespace hal

/**
* Remove a module from the netlist.
* Submodules, gates and nets under this module will be moved to the parent of this module.
*
* @param[in] module - The module.
* @returns True on success, false otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace hal
* purpose, it uses QVariants as its main type of storage for its columns. (Note: Perhaps add
* additional data in form of a list or map (split it from "normal" displayed column data)
*/
class TreeItem
class BaseTreeItem
{
// maybe add enum type for all possible scenarios? or use additional data with key to access type
// and handle type handling in model...e.g.: item->getAddData("type")(structure, more generalization,...)
Expand All @@ -50,40 +50,40 @@ namespace hal
*
* @param item - The item to copy.
*/
TreeItem(const TreeItem &item);
BaseTreeItem(const BaseTreeItem &item);

public:
/**
* The constructor.
*/
TreeItem();
BaseTreeItem();

/**
* Second constructor to immediately assign column data.
*
* @param columnData - The item's data.
*/
TreeItem(QList<QVariant> columnData);
BaseTreeItem(QList<QVariant> columnData);

/**
* The destructor.
*/
~TreeItem();
virtual ~BaseTreeItem();

/**
* Get the data of a specific column (most in the form of a string).
*
* @param column - The requested column.
* @return The data if within the column count. Empty QVariant otherwise.
*/
QVariant getData(int column);
virtual QVariant getData(int column) const = 0;

/**
* Sets the data for all columns.
*
* @param data - Each entry in the list represents one column.
*/
void setData(QList<QVariant> data);
virtual void setData(QList<QVariant> data) = 0;

/**
* Sets the data for a specified column. The index must be within
Expand All @@ -92,50 +92,50 @@ namespace hal
* @param index - The column to set the new data.
* @param data - The new column data.
*/
void setDataAtIndex(int index, QVariant data);
virtual void setDataAtIndex(int index, QVariant& data) = 0;

/**
* Appends a new column to the item.
*
* @param data - The data of the new column.
*/
void appendData(QVariant data);
virtual void appendData(QVariant data) = 0;

/**
* Get the item's parent.
*
* @return The parent.
*/
TreeItem* getParent();
virtual BaseTreeItem* getParent() const;

/**
* Sets the item's parent.
*
* @param parent - The parent.
*/
void setParent(TreeItem* parent);
virtual void setParent(BaseTreeItem* parent);

/**
* Get the child of a specific row.
*
* @param row - The requested row.
* @return The child if within bounds. Nullptr otherwise.
*/
TreeItem* getChild(int row);
virtual BaseTreeItem* getChild(int row) const;

/**
* Get the list of all children.
*
* @return The list of children.
*/
QList<TreeItem*> getChildren();
virtual QList<BaseTreeItem*> getChildren() const;

/**
* Appends a child.
*
* @param child - The child to append.
*/
void appendChild(TreeItem* child);
virtual void appendChild(BaseTreeItem* child);

/**
* Inserts a child at the given index. If the index exceeds the amount
Expand All @@ -144,15 +144,15 @@ namespace hal
* @param index - The position at which to insert.
* @param child - The child to insert.
*/
void insertChild(int index, TreeItem* child);
virtual void insertChild(int index, BaseTreeItem* child);

/**
* Removes the child at the given row and returns it.
*
* @param row - The row from which to remove the child.
* @return The removed child. Nullptr if row was out of bounds.
*/
TreeItem* removeChildAtPos(int row);
virtual BaseTreeItem* removeChildAtPos(int row);

/**
* Removes the given item and returns True if removing was successful
Expand All @@ -161,21 +161,21 @@ namespace hal
* @param child - The child to remove.
* @return True on success, False otherwise.
*/
bool removeChild(TreeItem* child);
virtual bool removeChild(BaseTreeItem* child);

/**
* Get the number of children.
*
* @return The number of children.
*/
int getChildCount();
virtual int getChildCount() const;

/**
* Get the number of currently stored column data.
*
* @return The column count.
*/
int getColumnCount();
virtual int getColumnCount() const = 0;

/**
* Convenience method to get the row for a given item.
Expand All @@ -184,15 +184,15 @@ namespace hal
* @param child - The child for which the row is requested.
* @return The row if the item is a child, -1 otherwise.
*/
int getRowForChild(TreeItem* child);
virtual int getRowForChild(const BaseTreeItem* child) const;

/**
* Convenience method to get the row of this item within
* the parent's list. If the item has no parent, -1 is returned.
*
* @return The row of this item if it has a parent, -1 otherwise.
*/
int getOwnRow();
virtual int getOwnRow();

/**
* Stores additional data. Can be accessed by getAdditionalData.
Expand All @@ -201,24 +201,72 @@ namespace hal
* @param key - The key to store the data under.
* @param data - The actual data to store.
*/
void setAdditionalData(QString key, QVariant data);
virtual void setAdditionalData(QString key, QVariant data);

/**
* Retrieve the data stored under the given key.
*
* @param key - The key for the requested data.
* @return The data if something was stored under the key, empty QVariant otherwise.
*/
QVariant getAdditionalData(QString key);
virtual QVariant getAdditionalData(QString key) const;

private:
TreeItem* mParent;
QList<TreeItem*> mChildren;
QList<QVariant> mData;
BaseTreeItem* mParent;
QList<BaseTreeItem*> mChildren;

// experimental, additional data (for anything)
QMap<QString, QVariant> mAdditionalData;
//QList<QVariant> mAdditionalData;

};

/**
* Since the BaseTreeItem class is pure virtual it cannot be instanciated for
* root tree item.
*
* RootTreeItem class also provides the header labels.
*/
class RootTreeItem : public BaseTreeItem
{
QStringList mHeaderLabels;
public:
RootTreeItem(const QStringList& labels) : mHeaderLabels(labels) {;}

/**
* Get header label for section.
* @param column The section of the header.
* @return The label for the header.
*/
QVariant getData(int column) const override;

/**
* Set header label to new value. If element in list does not exist it gets created.
* @param column The section of the header.
* @param data The string value.
*/
void setData(QList<QVariant> data) override;

/**
* Sets the data for a specified column. The index must be within
* already existing boundaries (for example, add dummy data beforehand).
*
* @param index - The column to set the new data.
* @param data - The new column data.
*/
void setDataAtIndex(int index, QVariant& data) override;

/**
* Appends a new column to the item.
*
* @param data - The data of the new column.
*/
void appendData(QVariant data) override;

/**
* Get number of sections for which header label exist.
* @return The number of sections.
*/
int getColumnCount() const override { return mHeaderLabels.size(); }
};
}
14 changes: 7 additions & 7 deletions plugins/gui/include/gui/basic_tree_model/base_tree_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#pragma once

#include <QAbstractItemModel>
#include "tree_item.h"
#include "base_tree_item.h"

namespace hal
{
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace hal
*
* @param firstLevelItems - All items that will be appended to this model's root item.
*/
void setContent(QList<TreeItem*> firstLevelItems);
void setContent(QList<BaseTreeItem*> firstLevelItems);

/**
* Resets the model (deletes the tree).
Expand All @@ -113,7 +113,7 @@ namespace hal
* classed to initialize
* @param labels
*/
void setHeaderLabels(QList<QVariant> labels);
void setHeaderLabels(const QStringList& label);

// important converter methods
/**
Expand All @@ -122,26 +122,26 @@ namespace hal
* @param item - The item from which to get the index.
* @return The index.
*/
QModelIndex getIndexFromItem(TreeItem* item) const;
QModelIndex getIndexFromItem(BaseTreeItem* item) const;

/**
* Helper method to convert between the index and its item.
*
* @param index - The index to convert.
* @return The internal item.
*/
TreeItem* getItemFromIndex(QModelIndex index) const;
BaseTreeItem* getItemFromIndex(QModelIndex index) const;

/**
* Convenient function to get the root item to which the tree is appended
* (the root item is not shown/displayed).
*
* @return The root item.
*/
TreeItem* getRootItem() const;
BaseTreeItem* getRootItem() const;

protected:
TreeItem* mRootItem;
RootTreeItem* mRootItem;
};

}
15 changes: 0 additions & 15 deletions plugins/gui/include/gui/grouping/grouping_color_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

namespace hal {
class GroupingTableModel;
class ModuleModel;

class GroupingColorSerializer : public ProjectSerializer
{
Expand All @@ -44,18 +43,4 @@ namespace hal {

void restore(GroupingTableModel *gtm);
};

class ModuleColorSerializer : public ProjectSerializer
{
void restoreModuleColor(const std::filesystem::path& loaddir, const std::string& jsonfile, ModuleModel *mm = nullptr);
void serializeColorRecursion(QJsonArray& mcArr, const ModuleModel* mm, QModelIndex parent=QModelIndex());
public:
ModuleColorSerializer();

std::string serialize(Netlist* netlist, const std::filesystem::path& savedir, bool isAutosave) override;

void deserialize(Netlist* netlist, const std::filesystem::path& loaddir) override;

void restore(ModuleModel *mm);
};
}
9 changes: 0 additions & 9 deletions plugins/gui/include/gui/gui_utils/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,5 @@ namespace hal
* @return The (perhabs styled) icon.
*/
extern QIcon getStyledSvgIcon(const QString& from_to_colors, const QString& svg_path);

/**
* Returns a somewhat random color through a funny method (should be the same order
* of colors each time the program starts). This brilliant piece of code MUST NEVER
* BE REMOVED, PURE COMEDY!
*
* @return The "random" color.
*/
extern QColor getRandomColor();
}
}
Loading

0 comments on commit 0cec8c1

Please sign in to comment.