-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
76 lines (59 loc) · 2.08 KB
/
MainWindow.cpp
File metadata and controls
76 lines (59 loc) · 2.08 KB
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
#include <iostream>
#include <QTimer>
#include "MainWindow.h"
#include "ui_MainWindow.h"
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
model(new MyDataModel(nullptr, &topData))
{
ui->setupUi(this);
ui->treeView->setModel(model);
auto toolbar = ui->mainToolBar;
removeToolBar(toolbar);
addToolBar(Qt::LeftToolBarArea, toolbar);
toolbar->show();
TopData * td1 = new TopData("Joe", "Awesome");
TopData * td2 = new TopData("MySis", "Sweet"); // My sister
topData.push_back(td1);
topData.push_back(td2);
MiddleData * md1a = td1->createMiddleData("Childhood", "Brooklyn Center");
td1->createMiddleData("High School", "Park Center");
td1->createMiddleData("Current", "Minnesota");
MiddleData * md2a = td2->createMiddleData("Childhood", "Brooklyn Center");
td2->createMiddleData("Somewhere", "She'd Shoot Me");
td2->createMiddleData("Current", "I mean it. She would.");
md1a->createChildData("From", 0);
md1a->createChildData("Until", 22);
md2a->createChildData("From", 14);
md2a->createChildData("Until", 18);
// Columns are allocated evenly, except the last which by default gets the stretch. This lets me make two of them wider.
ui->treeView->setColumnWidth(0, ui->treeView->columnWidth(0) * 2);
ui->treeView->setColumnWidth(2, ui->treeView->columnWidth(2) * 2);
// Set up to automatically force a data change.
QTimer::singleShot(5000, this, SLOT(updateData()));
}
MainWindow::~MainWindow()
{
delete ui;
}
/**
* This does a data update then tells the form.
*/
void MainWindow::on_actionChange_Data_triggered()
{
TopData * td = topData.at(0);
MiddleData * md = td->middleData.at(0);
md->name = md->name + ".";
md->createChildData("Update", 10);
//ui->treeView->dataChanged(QModelIndex(), QModelIndex());
model->layoutChanged();
}
/**
* Timer version of automatically changing the data.
*/
void MainWindow::updateData() {
on_actionChange_Data_triggered();
QTimer::singleShot(5000, this, SLOT(updateData()));
}