-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
63 lines (49 loc) · 1.48 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
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
#include <QtGui/QMessageBox>
#include <iostream>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
model=new Model();
ui->treeView->setModel(model);
connect(ui->LoadButton, SIGNAL(clicked()), this, SLOT(Reload()));
connect(ui->DeleteButton, SIGNAL(clicked()), this, SLOT(Delete()));
connect(ui->NewButton, SIGNAL(clicked()), this, SLOT(Add()));
//gdyby mnie pokusiło na modyfikowanie drzewa myszką
ui->treeView->setSelectionBehavior(QTreeView::SelectItems);
}
MainWindow::~MainWindow()
{
delete ui;
delete model;
}
void MainWindow::Reload()
{
model->LoadDatabase();
//HACK, ale odświerza bez zabaw w emitowanie sygnału
ui->treeView->setModel(NULL);
ui->treeView->setModel(model);
}
bool MainWindow::Add()
{
Dialog dialog(this);
if(dialog.exec())
model->AddArtist(dialog.NewArtist);
ui->treeView->setModel(NULL);
ui->treeView->setModel(model);
}
void MainWindow::Delete()
{
QModelIndexList indexList=ui->treeView->selectionModel()->selectedIndexes();
if(indexList.size()==0)
return;
model->Erase(indexList[0]);
//powinien być slot i sygnał, ale mało już mam czasu.
//Trzeba odwierzyć przed końcem metody. inaczj treeview próbuje się dostać do nieisteniejącego elementu
ui->treeView->setModel(NULL);
ui->treeView->setModel(model);
}
void MainWindow::on_centralWidget_customContextMenuRequested(const QPoint &pos)
{
}