2017-10-02 16:18:40 +00:00
|
|
|
#include "ImportsWidget.h"
|
|
|
|
#include "ui_ImportsWidget.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 <QTreeWidget>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPainter>
|
|
|
|
|
2018-04-12 06:32:31 +00:00
|
|
|
ImportsModel::ImportsModel(QList<ImportDescription> *imports, QObject *parent) :
|
|
|
|
QAbstractTableModel(parent),
|
|
|
|
imports(imports)
|
|
|
|
{}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-04-12 06:32:31 +00:00
|
|
|
int ImportsModel::rowCount(const QModelIndex &parent) const
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2018-04-12 06:32:31 +00:00
|
|
|
return parent.isValid()? 0 : imports->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ImportsModel::columnCount(const QModelIndex&) const
|
|
|
|
{
|
|
|
|
return COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ImportsModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
const ImportDescription &import = imports->at(index.row());
|
|
|
|
switch(role)
|
|
|
|
{
|
|
|
|
case AddressRole:
|
|
|
|
return import.plt;
|
|
|
|
case Qt::ForegroundRole:
|
|
|
|
if(index.column() < COUNT)
|
|
|
|
if(banned.match(import.name).hasMatch())
|
|
|
|
return QColor(255, 129, 123);
|
|
|
|
break;
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch(index.column())
|
|
|
|
{
|
|
|
|
case ADDRESS:
|
|
|
|
return RAddressString(import.plt);
|
|
|
|
case TYPE:
|
|
|
|
return import.type;
|
|
|
|
case SAFETY:
|
|
|
|
return banned.match(import.name).hasMatch()? tr("Unsafe") : QStringLiteral("");
|
|
|
|
case NAME:
|
|
|
|
return import.name;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ImportsModel::headerData(int section, Qt::Orientation, int role) const
|
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
switch(section)
|
|
|
|
{
|
|
|
|
case ADDRESS:
|
|
|
|
return tr("Address");
|
|
|
|
case TYPE:
|
|
|
|
return tr("Type");
|
|
|
|
case SAFETY:
|
|
|
|
return tr("Safety");
|
|
|
|
case NAME:
|
|
|
|
return tr("Name");
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportsModel::beginReload()
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportsModel::endReload()
|
|
|
|
{
|
|
|
|
endResetModel();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Imports Widget
|
|
|
|
*/
|
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
ImportsWidget::ImportsWidget(MainWindow *main, QAction *action) :
|
|
|
|
CutterDockWidget(main, action),
|
2018-04-12 06:32:31 +00:00
|
|
|
ui(new Ui::ImportsWidget),
|
|
|
|
model(new ImportsModel(&imports, this))
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2018-04-12 06:32:31 +00:00
|
|
|
ui->importsTreeView->setModel(model);
|
|
|
|
ui->importsTreeView->sortByColumn(3, Qt::AscendingOrder);
|
2017-04-13 15:14:02 +00:00
|
|
|
|
|
|
|
setScrollMode();
|
|
|
|
|
2018-04-12 06:32:31 +00:00
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshImports()));
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
ImportsWidget::~ImportsWidget() {}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2018-04-12 06:32:31 +00:00
|
|
|
void ImportsWidget::refreshImports()
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2018-04-12 06:32:31 +00:00
|
|
|
model->beginReload();
|
|
|
|
imports = Core()->getAllImports();
|
|
|
|
model->endReload();
|
|
|
|
qhelpers::adjustColumns(ui->importsTreeView, 4, 0);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
void ImportsWidget::setScrollMode()
|
|
|
|
{
|
2018-04-12 06:32:31 +00:00
|
|
|
qhelpers::setVerticalScrollMode(ui->importsTreeView);
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
2017-05-19 07:45:26 +00:00
|
|
|
|
2018-04-12 06:32:31 +00:00
|
|
|
void ImportsWidget::on_importsTreeView_doubleClicked(const QModelIndex &index)
|
2017-05-19 07:45:26 +00:00
|
|
|
{
|
2018-04-12 06:32:31 +00:00
|
|
|
Core()->seek(index.data(ImportsModel::AddressRole).toLongLong());
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|