Skip to content

Commit

Permalink
fixed uninitalized id in all details widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
not-a-trojan committed Dec 10, 2019
1 parent 1984560 commit 881c006
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 48 deletions.
7 changes: 7 additions & 0 deletions src/gui/selection_details_widget/gate_details_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

gate_details_widget::gate_details_widget(QWidget* parent) : QWidget(parent)
{
m_current_id = 0;

m_last_click_time = 0;

m_content_layout = new QVBoxLayout(this);
Expand Down Expand Up @@ -232,6 +234,7 @@ void gate_details_widget::handle_net_name_changed(std::shared_ptr<net> net)

void gate_details_widget::handle_net_src_changed(std::shared_ptr<net> net)
{
if (m_current_id == 0) return;
if (g_netlist->is_gate_in_netlist(g_netlist->get_gate_by_id(m_current_id)))
update(m_current_id);
}
Expand All @@ -250,6 +253,7 @@ void gate_details_widget::handle_net_dst_removed(std::shared_ptr<net> net, const

void gate_details_widget::handle_module_removed(std::shared_ptr<module> module)
{
if (m_current_id == 0) return;
auto g = g_netlist->get_gate_by_id(m_current_id);

if (module->contains_gate(g))
Expand All @@ -260,6 +264,7 @@ void gate_details_widget::handle_module_removed(std::shared_ptr<module> module)

void gate_details_widget::handle_module_name_changed(std::shared_ptr<module> module)
{
if (m_current_id == 0) return;
auto g = g_netlist->get_gate_by_id(m_current_id);

if (module->contains_gate(g))
Expand Down Expand Up @@ -296,6 +301,8 @@ void gate_details_widget::update(const u32 gate_id)
{
m_current_id = gate_id;

if (m_current_id == 0) return;

auto g = g_netlist->get_gate_by_id(gate_id);

if (!g)
Expand Down
96 changes: 48 additions & 48 deletions src/gui/selection_details_widget/module_details_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
#include "gui_globals.h"
#include "netlist/gate.h"
#include "netlist/module.h"
#include <QDebug>
#include <QHeaderView>
#include <QLabel>
#include <QVBoxLayout>
#include <QShortcut>
#include <QQueue>
#include <QRegExp>
#include <QDebug>
#include <QShortcut>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QHeaderView>
#include <QQueue>
#include <QVBoxLayout>

#include "selection_details_widget/tree_navigation/tree_module_item.h"

module_details_widget::module_details_widget(QWidget* parent) : QWidget(parent), m_treeview(new QTreeView(this)), m_tree_module_model(new tree_module_model(this)),
m_tree_module_proxy_model(new tree_module_proxy_model(this)), m_ignore_selection_change(false)
module_details_widget::module_details_widget(QWidget* parent)
: QWidget(parent), m_treeview(new QTreeView(this)), m_tree_module_model(new tree_module_model(this)), m_tree_module_proxy_model(new tree_module_proxy_model(this)), m_ignore_selection_change(false)
{
m_current_id = 0;

m_content_layout = new QVBoxLayout(this);
m_content_layout->setContentsMargins(0, 0, 0, 0);
m_content_layout->setSpacing(20);
Expand All @@ -29,7 +31,7 @@ module_details_widget::module_details_widget(QWidget* parent) : QWidget(parent),
m_treeview->setExpanded(m_tree_module_proxy_model->index(0, 0, m_treeview->rootIndex()), true);
m_treeview->setExpanded(m_tree_module_proxy_model->index(1, 0, m_treeview->rootIndex()), true);

m_general_table = new QTableWidget(3,2, this);
m_general_table = new QTableWidget(3, 2, this);
m_general_table->horizontalHeader()->setStretchLastSection(true);
m_general_table->horizontalHeader()->hide();
m_general_table->verticalHeader()->hide();
Expand All @@ -41,7 +43,7 @@ module_details_widget::module_details_widget(QWidget* parent) : QWidget(parent),
QTableWidgetItem* name_item = new QTableWidgetItem("Name: ");
name_item->setFont(font);
name_item->setFlags(Qt::ItemIsEnabled);
m_general_table->setItem(0,0, name_item);
m_general_table->setItem(0, 0, name_item);

m_name_item = new QTableWidgetItem();
m_name_item->setFlags(Qt::ItemIsEnabled);
Expand All @@ -59,11 +61,11 @@ module_details_widget::module_details_widget(QWidget* parent) : QWidget(parent),
QTableWidgetItem* gates_count_item = new QTableWidgetItem("Total Number of Gates:");
gates_count_item->setFont(font);
gates_count_item->setFlags(Qt::ItemIsEnabled);
m_general_table->setItem(2,0, gates_count_item);
m_general_table->setItem(2, 0, gates_count_item);

m_gates_count_item = new QTableWidgetItem();
m_gates_count_item->setFlags(Qt::ItemIsEnabled);
m_general_table->setItem(2,1, m_gates_count_item);
m_general_table->setItem(2, 1, m_gates_count_item);

m_general_table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
m_general_table->verticalHeader()->setDefaultSectionSize(16);
Expand All @@ -77,12 +79,11 @@ module_details_widget::module_details_widget(QWidget* parent) : QWidget(parent),
m_content_layout->addWidget(m_general_table);
m_content_layout->addWidget(m_treeview);

// QShortcut* search_shortcut = new QShortcut(QKeySequence("Ctrl+f"), this);
// connect(search_shortcut, &QShortcut::activated, this, &module_details_widget::toggle_searchbar);

// QShortcut* resize_shortcut = new QShortcut(QKeySequence("Ctrl+b"), this);
// connect(resize_shortcut, &QShortcut::activated, this, &module_details_widget::toggle_resize_columns);
// QShortcut* search_shortcut = new QShortcut(QKeySequence("Ctrl+f"), this);
// connect(search_shortcut, &QShortcut::activated, this, &module_details_widget::toggle_searchbar);

// QShortcut* resize_shortcut = new QShortcut(QKeySequence("Ctrl+b"), this);
// connect(resize_shortcut, &QShortcut::activated, this, &module_details_widget::toggle_resize_columns);

connect(&g_netlist_relay, &netlist_relay::module_name_changed, this, &module_details_widget::handle_module_name_changed);
connect(&g_netlist_relay, &netlist_relay::module_gate_assigned, this, &module_details_widget::handle_module_gate_assigned);
Expand All @@ -102,15 +103,15 @@ module_details_widget::module_details_widget(QWidget* parent) : QWidget(parent),
connect(&g_selection_relay, &selection_relay::selection_changed, this, &module_details_widget::handle_selection_changed);
}

void module_details_widget::handle_selection_changed(void *sender)
void module_details_widget::handle_selection_changed(void* sender)
{
if (sender == this)
{
return;
}

//neccessary to elimante a bug where this widget erases the module_selection
if(!g_selection_relay.m_selected_modules.isEmpty())
if (!g_selection_relay.m_selected_modules.isEmpty())
return;

QList<u32> gate_ids, net_ids;
Expand All @@ -129,14 +130,13 @@ void module_details_widget::handle_selection_changed(void *sender)
for (const auto& index : selected_indexes)
selection.select(m_tree_module_proxy_model->mapFromSource(index), m_tree_module_proxy_model->mapFromSource(index));


if(!selection.isEmpty() || (!m_treeview->selectionModel()->selectedIndexes().isEmpty() && selection.isEmpty()))
if (!selection.isEmpty() || (!m_treeview->selectionModel()->selectedIndexes().isEmpty() && selection.isEmpty()))
m_ignore_selection_change = true;

m_treeview->selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect);
}

void module_details_widget::handle_searchbar_text_edited(const QString &text)
void module_details_widget::handle_searchbar_text_edited(const QString& text)
{
QRegExp* regex = new QRegExp(text);
if (regex->isValid())
Expand All @@ -145,38 +145,36 @@ void module_details_widget::handle_searchbar_text_edited(const QString &text)

void module_details_widget::handle_module_name_changed(const std::shared_ptr<module> m)
{
if(m_current_id == m->get_id())
if (m_current_id == m->get_id())
this->update(m->get_id());

}

void module_details_widget::handle_module_gate_assigned(const std::shared_ptr<module> m, const u32 assigned_gate)
{
Q_UNUSED(assigned_gate)

if(m_current_id == m->get_id())
if (m_current_id == m->get_id())
update(m_current_id);

}

void module_details_widget::handle_module_gate_removed(const std::shared_ptr<module> m, const u32 removed_gate)
{
Q_UNUSED(removed_gate)

if(m_current_id == m->get_id())
if (m_current_id == m->get_id())
update(m_current_id);

}

void module_details_widget::handle_gate_name_changed(const std::shared_ptr<gate> g)
{
if (m_current_id == 0)
return;
auto mod = g_netlist->get_module_by_id(m_current_id);
if(!mod)
if (!mod)
return;

if(mod->contains_gate(g))
if (mod->contains_gate(g))
update(m_current_id);

}

void module_details_widget::handle_gate_removed(const std::shared_ptr<gate> g)
Expand All @@ -196,15 +194,15 @@ void module_details_widget::handle_net_removed(const std::shared_ptr<net> n)

void module_details_widget::handle_net_name_changed(const std::shared_ptr<net> n)
{
if (m_current_id == 0)
return;
auto mod = g_netlist->get_module_by_id(m_current_id);
if(!mod)
if (!mod)
return;

if(mod->get_input_nets().find(n) != mod->get_input_nets().end() ||
mod->get_internal_nets().find(n) != mod->get_internal_nets().end() ||
mod->get_output_nets().find(n) != mod->get_output_nets().end())
if (mod->get_input_nets().find(n) != mod->get_input_nets().end() || mod->get_internal_nets().find(n) != mod->get_internal_nets().end()
|| mod->get_output_nets().find(n) != mod->get_output_nets().end())
update(m_current_id);

}

void module_details_widget::handle_net_src_changed(const std::shared_ptr<net> n)
Expand All @@ -220,26 +218,28 @@ void module_details_widget::handle_net_dst_added(const std::shared_ptr<net> n, c

void module_details_widget::handle_net_dst_removed(const std::shared_ptr<net> n, const u32 dst_gate_id)
{
if (m_current_id == 0)
return;
auto g = g_netlist->get_gate_by_id(dst_gate_id);
if(g_netlist->get_module_by_id(m_current_id)->contains_gate(g))
if (g_netlist->get_module_by_id(m_current_id)->contains_gate(g))
update(m_current_id);
}

void module_details_widget::handle_tree_double_clicked(const QModelIndex &index)
void module_details_widget::handle_tree_double_clicked(const QModelIndex& index)
{
if(!index.isValid())
if (!index.isValid())
return;

auto item = static_cast<tree_module_item*>(m_tree_module_proxy_model->mapToSource(index).internalPointer());

//this line neccessary to call g_selection_relay.clear() without problems
if(item->get_type() == tree_module_item::item_type::structure)
if (item->get_type() == tree_module_item::item_type::structure)
return;

g_selection_relay.clear();
auto id = item->data(tree_module_model::ID_COLUMN).toInt();

switch(item->get_type())
switch (item->get_type())
{
case tree_module_item::item_type::gate:
g_selection_relay.m_selected_gates.insert(id);
Expand All @@ -252,47 +252,47 @@ void module_details_widget::handle_tree_double_clicked(const QModelIndex &index)
default:
break;
}

}

void module_details_widget::toggle_resize_columns()
{
for(int i = 0; i < m_tree_module_model->columnCount(); i++)
for (int i = 0; i < m_tree_module_model->columnCount(); i++)
m_treeview->resizeColumnToContents(i);
}

int module_details_widget::compute_overall_number_of_gates()
{
auto curr_mod = g_netlist->get_module_by_id(m_current_id);
auto curr_mod = g_netlist->get_module_by_id(m_current_id);
int overall_gates = 0;

QQueue<std::shared_ptr<module>> queue;
queue.enqueue(curr_mod);

//standard BFS
while(!queue.isEmpty())
while (!queue.isEmpty())
{
auto mod = queue.dequeue();
overall_gates += mod->get_gates().size();

for(const auto &modu : mod->get_submodules())
for (const auto& modu : mod->get_submodules())
queue.enqueue(modu);
}

return overall_gates;

}

void module_details_widget::update(u32 module_id)
{
if(!(g_netlist->get_module_by_id(module_id)))
if (m_current_id == 0)
return;
if (!(g_netlist->get_module_by_id(module_id)))
return;

m_current_id = module_id;
m_tree_module_model->update(module_id);
toggle_resize_columns();

if(!m_treeview->selectionModel()->selectedIndexes().isEmpty())
if (!m_treeview->selectionModel()->selectedIndexes().isEmpty())
m_ignore_selection_change = true;
m_treeview->clearSelection();

Expand Down
8 changes: 8 additions & 0 deletions src/gui/selection_details_widget/net_details_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

net_details_widget::net_details_widget(QWidget* parent) : QWidget(parent)
{
m_current_id = 0;

m_content_layout = new QVBoxLayout(this);
m_content_layout->setContentsMargins(0, 0, 0, 0);
m_content_layout->setSpacing(0);
Expand Down Expand Up @@ -157,6 +159,9 @@ void net_details_widget::update(u32 net_id)
{
m_current_id = net_id;

if (m_current_id == 0)
return;

auto n = g_netlist->get_net_by_id(net_id);

if(!n)
Expand Down Expand Up @@ -344,6 +349,9 @@ void net_details_widget::handle_gate_name_changed(const std::shared_ptr<gate> g)
{
Q_UNUSED(g)

if (m_current_id == 0)
return;

bool update_needed = false;

//current net
Expand Down

0 comments on commit 881c006

Please sign in to comment.