-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
87 lines (79 loc) · 1.99 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QMessageBox>
#include <QDir>
#include <QDebug>
#include "hivemodel.h"
#include "hiveview.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_hiveModel(nullptr), m_hiveValuesModel(nullptr)
{
ui->setupUi(this);
ui->valueView->setModel(&m_hiveValuesModel);
initConnections();
initIcons();
initShortcuts();
}
void MainWindow::initConnections()
{
connect(ui->nodeView, &HiveView::activeHiveItemChanged,
this, &MainWindow::onNodeActivated);
connect(ui->nodeView, &HiveView::activeHiveItemChanged,
&m_hiveValuesModel, &HiveValuesModel::loadNode);
}
void MainWindow::initIcons()
{
ui->actionOpen_Hive->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
}
void MainWindow::initShortcuts()
{
ui->actionOpen_Hive->setShortcut(QKeySequence::Open);
}
MainWindow::~MainWindow()
{
delete ui;
if (m_hiveModel)
delete m_hiveModel;
}
void MainWindow::on_actionOpen_Hive_triggered()
{
auto fileName = QFileDialog::getOpenFileName(this, tr("Open Hive"), QDir::homePath());
if (!fileName.isEmpty())
{
HiveModel *model = HiveModel::loadHive(fileName.toUtf8().data());
if (!model)
{
QMessageBox::critical(this, tr("Hive load error"), tr("Could not load hive file"));
}
else
{
if (m_hiveModel)
{
ui->nodeView->setModel(nullptr);
m_hiveValuesModel.loadNode(nullptr);
delete m_hiveModel;
}
m_hiveModel = model;
ui->nodeView->setModel(m_hiveModel);
}
}
}
void MainWindow::onNodeActivated(HiveItem *item)
{
QString name;
if (!item)
{
name = "<null>";
}
else
{
name = item->name();
}
// TODO: Connect to value model
qDebug() << "Selected Item:" << name;
}