2017-10-02 16:18:40 +00:00
|
|
|
#include "widgets/SectionsWidget.h"
|
|
|
|
#include "widgets/PieView.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "utils/Helpers.h"
|
2017-04-13 15:14:02 +00:00
|
|
|
|
|
|
|
#include <QtWidgets>
|
|
|
|
#include <QTreeWidget>
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
SectionsWidget::SectionsWidget(MainWindow *main, QWidget *parent) :
|
2017-04-13 15:14:02 +00:00
|
|
|
QSplitter(main),
|
|
|
|
main(main)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-10-01 18:08:12 +00:00
|
|
|
Q_UNUSED(parent);
|
2017-04-09 17:09:35 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
setupViews();
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2017-11-19 12:56:10 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
connect(this->tree, SIGNAL(doubleClicked(const QModelIndex &)), this,
|
|
|
|
SLOT(onSectionsDoubleClicked(const QModelIndex &)));
|
2018-02-02 15:56:39 +00:00
|
|
|
|
2017-11-26 21:31:27 +00:00
|
|
|
tree->sortByColumn(0, Qt::AscendingOrder);
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshSections()));
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
void SectionsWidget::refreshSections()
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-04-13 15:14:02 +00:00
|
|
|
tree->clear();
|
|
|
|
|
|
|
|
int row = 0;
|
2018-04-12 06:33:30 +00:00
|
|
|
for (auto section : Core()->getAllSections()) {
|
2017-05-03 09:09:57 +00:00
|
|
|
fillSections(row++, section);
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
2017-05-03 09:09:57 +00:00
|
|
|
|
2017-12-23 16:42:42 +00:00
|
|
|
qhelpers::adjustColumns(tree, 0);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
2017-04-13 15:14:02 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
void SectionsWidget::setupViews()
|
|
|
|
{
|
|
|
|
// Table view
|
|
|
|
this->tree = new QTreeWidget;
|
2017-04-12 10:16:43 +00:00
|
|
|
this->tree->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2017-03-29 10:18:37 +00:00
|
|
|
this->tree->setIndentation(10);
|
|
|
|
|
|
|
|
// Setup TreeWidget
|
|
|
|
this->tree->setColumnCount(4);
|
|
|
|
QList<QString> headers;
|
2017-12-02 19:15:12 +00:00
|
|
|
headers << tr("Name") << tr("Size") << tr("Address") << tr("End Address");
|
2017-03-29 10:18:37 +00:00
|
|
|
this->tree->setHeaderLabels(headers);
|
|
|
|
|
|
|
|
this->tree->setFrameShape(QFrame::NoFrame);
|
|
|
|
this->tree->setSortingEnabled(true);
|
|
|
|
|
|
|
|
pieChart = new PieView;
|
|
|
|
pieChart->setFrameShape(QFrame::NoFrame);
|
2017-04-12 10:16:43 +00:00
|
|
|
pieChart->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2017-03-29 10:18:37 +00:00
|
|
|
this->addWidget(this->tree);
|
|
|
|
this->addWidget(pieChart);
|
|
|
|
this->setStretchFactor(0, 4);
|
|
|
|
|
|
|
|
//this->tree->setModel(model);
|
|
|
|
pieChart->setModel(this->tree->model());
|
|
|
|
|
|
|
|
QItemSelectionModel *selectionModel = new QItemSelectionModel(this->tree->model());
|
|
|
|
this->tree->setSelectionModel(selectionModel);
|
|
|
|
pieChart->setSelectionModel(selectionModel);
|
|
|
|
}
|
|
|
|
|
2017-05-03 09:09:57 +00:00
|
|
|
void SectionsWidget::fillSections(int row, const SectionDescription §ion)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-04-13 15:14:02 +00:00
|
|
|
// TODO: create unique colors, e. g. use HSV color space and rotate in H for 360/size
|
|
|
|
static const QList<QColor> colors = { QColor("#1ABC9C"), //TURQUOISE
|
|
|
|
QColor("#2ECC71"), //EMERALD
|
|
|
|
QColor("#3498DB"), //PETER RIVER
|
|
|
|
QColor("#9B59B6"), //AMETHYST
|
|
|
|
QColor("#34495E"), //WET ASPHALT
|
|
|
|
QColor("#F1C40F"), //SUN FLOWER
|
|
|
|
QColor("#E67E22"), //CARROT
|
|
|
|
QColor("#E74C3C"), //ALIZARIN
|
|
|
|
QColor("#ECF0F1"), //CLOUDS
|
|
|
|
QColor("#BDC3C7"), //SILVER
|
2017-04-13 15:51:58 +00:00
|
|
|
QColor("#95A5A6") //COBCRETE
|
|
|
|
};
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
|
2017-05-03 09:09:57 +00:00
|
|
|
tempItem->setText(0, section.name);
|
2018-02-28 20:12:51 +00:00
|
|
|
tempItem->setData(1, Qt::DisplayRole, section.size);
|
|
|
|
tempItem->setTextAlignment(1, Qt::AlignRight | Qt::AlignVCenter);
|
2017-05-03 09:09:57 +00:00
|
|
|
tempItem->setText(2, RAddressString(section.vaddr));
|
|
|
|
tempItem->setText(3, RAddressString(section.vaddr + section.vsize));
|
2017-04-13 15:14:02 +00:00
|
|
|
tempItem->setData(0, Qt::DecorationRole, colors[row % colors.size()]);
|
2017-03-29 10:18:37 +00:00
|
|
|
this->tree->insertTopLevelItem(0, tempItem);
|
|
|
|
}
|
2018-02-02 15:56:39 +00:00
|
|
|
|
|
|
|
void SectionsWidget::onSectionsDoubleClicked(const QModelIndex &index)
|
|
|
|
{
|
2018-04-23 07:54:06 +00:00
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
QTreeWidgetItem *section = tree->topLevelItem(index.row());
|
2018-02-02 15:56:39 +00:00
|
|
|
auto addr = section->text(2);
|
|
|
|
Core()->seek(addr);
|
|
|
|
}
|