forked from GLDsuh-a/qt-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
86 lines (68 loc) · 1.83 KB
/
mainwindow.cpp
File metadata and controls
86 lines (68 loc) · 1.83 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
77
78
79
80
81
82
83
84
85
86
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QLayout>
#include <QTableView>
#include <QFormLayout>
#include <QVBoxLayout>
#include <QTableWidget>
#include <QStandardItemModel>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->btnAdd, SIGNAL(clicked()), SLOT(slotOnButtonAddClicked()));
connect(ui->btnRemove, SIGNAL(clicked()), SLOT(slotOnButtonRemoveClicked()));
m_model = new KJModel(0);
m_styledItemDelegate = new KJStyledItemDelegate(0);
m_styledItemDelegate->tableView = ui->tableView;
QList<KJConversationWidget*> widgets = m_styledItemDelegate->widgets;
ui->tableView->viewport()->setLayout(new QVBoxLayout());
for (int i = 0; i < widgets.count(); i++)
{
ui->tableView->viewport()->layout()->addWidget(widgets.at(i));
}
ui->tableView->horizontalHeader()->setStretchLastSection(true);
ui->tableView->setModel(m_model);
ui->tableView->setSelectionMode(QAbstractItemView::NoSelection);
ui->tableView->setItemDelegate(m_styledItemDelegate);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slotOnButtonAddClicked()
{
int rows = ui->ledRows->text().toInt();
if (rows < 1)
{
rows = 1;
}
for (int i = 0; i < rows; i++)
{
m_model->addItem();
}
if (m_model->rowCount() > 0)
{
m_styledItemDelegate->refreshWidgets(false);
}
m_model->reloadData();
}
void MainWindow::slotOnButtonRemoveClicked()
{
int rows = ui->ledRows->text().toInt();
if (rows < 1)
{
rows = 1;
}
for (int i = 0; i < rows; i++)
{
m_model->removeItem();
}
if (m_model->rowCount() == 0)
{
m_styledItemDelegate->refreshWidgets(true);
}
m_model->reloadData();
}