-
Notifications
You must be signed in to change notification settings - Fork 3
/
mainwindow.cpp
98 lines (77 loc) · 3.37 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
87
88
89
90
91
92
93
94
95
96
97
98
#include "mainwindow.h"
#include "tablemodel.h"
#include "mytableview.h"
#include <QCheckBox>
#include <QVBoxLayout>
#include <qmenubar.h>
#include <iostream>
using std::cout;
using std::endl;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Drag and Drop app");
tableView = new MyTableView(this);
model = new TableModel();
tableView->setModel(model);
tableView->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
tableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
tableView->setDragEnabled(true);
tableView->viewport()->setAcceptDrops(true);
tableView->setDropIndicatorShown(true);
// tableView->setDragDropMode(QAbstractItemView::InternalMove);
tableView->setDragDropMode(QAbstractItemView::DragDrop); // same as far as I can tell
tableView->setDragDropOverwriteMode(false);
dragDropOverwriteModeCheckbox = new QCheckBox("DragDropOverwriteMode");
itemsAreDropEnabledCheckbox = new QCheckBox("Items are drop-enabled");
moveActionEnabledCheckbox = new QCheckBox("MoveAction enabled");
copyActionEnabledCheckbox = new QCheckBox("CopyAction enabled");
dragDropOverwriteModeCheckbox->setChecked(tableView->dragDropOverwriteMode());
itemsAreDropEnabledCheckbox->setChecked(model->itemsAreDropEnabled);
moveActionEnabledCheckbox->setChecked(model->moveActionEnabled);
copyActionEnabledCheckbox->setChecked(model->copyActionEnabled);
connect(dragDropOverwriteModeCheckbox, SIGNAL(clicked(bool)), this, SLOT(dragDropOverwriteModeCheckboxClicked()));
connect(itemsAreDropEnabledCheckbox, SIGNAL(clicked(bool)), this, SLOT(itemsAreDropEnabledCheckboxClicked()));
connect(moveActionEnabledCheckbox, SIGNAL(clicked(bool)), this, SLOT(moveActionEnabledCheckboxClicked()));
connect(copyActionEnabledCheckbox, SIGNAL(clicked(bool)), this, SLOT(copyActionEnabledCheckboxClicked()));
layout = new QVBoxLayout();
layout->addWidget(tableView);
layout->addWidget(dragDropOverwriteModeCheckbox);
layout->addWidget(itemsAreDropEnabledCheckbox);
layout->addWidget(moveActionEnabledCheckbox);
layout->addWidget(copyActionEnabledCheckbox);
mainWidget = new QWidget();
mainWidget->setLayout(layout);
setCentralWidget(mainWidget);
}
MainWindow::~MainWindow()
{
delete tableView;
delete model;
delete dragDropOverwriteModeCheckbox;
delete itemsAreDropEnabledCheckbox;
delete moveActionEnabledCheckbox;
delete copyActionEnabledCheckbox;
delete layout;
delete mainWidget;
}
void MainWindow::dragDropOverwriteModeCheckboxClicked()
{
tableView->setDragDropOverwriteMode(dragDropOverwriteModeCheckbox->isChecked());
cout << "tableView->dragDropOverwriteMode: " << tableView->dragDropOverwriteMode() << endl;
}
void MainWindow::itemsAreDropEnabledCheckboxClicked()
{
model->itemsAreDropEnabled = itemsAreDropEnabledCheckbox->isChecked();
cout << "model->itemsAreDropEnabled: " << model->itemsAreDropEnabled << endl;
}
void MainWindow::moveActionEnabledCheckboxClicked()
{
model->moveActionEnabled = moveActionEnabledCheckbox->isChecked();
cout << "model->moveActionEnabled: " << model->moveActionEnabled << endl;
}
void MainWindow::copyActionEnabledCheckboxClicked()
{
model->copyActionEnabled = copyActionEnabledCheckbox->isChecked();
cout << "model->copyActionEnabled: " << model->copyActionEnabled << endl;
}