-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfrmoperateparentintree.cpp
More file actions
148 lines (133 loc) · 4.27 KB
/
frmoperateparentintree.cpp
File metadata and controls
148 lines (133 loc) · 4.27 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "frmoperateparentintree.h"
#include "ui_frmoperateparentintree.h"
frmOperateParentInTree::frmOperateParentInTree(QWidget *parent) :
QDialog(parent),
ui(new Ui::frmOperateParentInTree)
{
ui->setupUi(this);
changed = false;
tableModel=NULL;
InitStyle();
ui->btnEdit->setVisible(false);
connect(ui->btnDelete,SIGNAL(clicked(bool)),this,SLOT(btnDelete()));
connect(ui->btnAddNew,SIGNAL(clicked(bool)),this,SLOT(btnAddNewParentInTree()));
connect(ui->btnCancel,SIGNAL(clicked(bool)),this,SLOT(btnCancel()));
connect(ui->btnSave,SIGNAL(clicked(bool)),this,SLOT(btnSave()));
connect(ui->btnEdit,SIGNAL(clicked(bool)),this,SLOT(btnEdit()));
}
frmOperateParentInTree::~frmOperateParentInTree()
{
delete ui;
}
void frmOperateParentInTree::InitStyle()
{
//设置窗体标题栏隐藏
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
location = this->geometry();
max = false;
mousePressed = false;
//安装事件监听器,让标题栏识别鼠标双击
ui->lab_Title->installEventFilter(this);
IconHelper::Instance()->SetIcon(ui->btnMenu_Close, QChar(0xf00d), 10);
//IconHelper::Instance()->SetIcon(ui->btnMenu_Max, QChar(0xf096), 10);
IconHelper::Instance()->SetIcon(ui->btnMenu_Min, QChar(0xf068), 10);
//IconHelper::Instance()->SetIcon(ui->btnMenu, QChar(0xf0c9), 10);
IconHelper::Instance()->SetIcon(ui->lab_Ico, QChar(0xf015), 12);
}
bool frmOperateParentInTree::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonDblClick) {
this->on_btnMenu_Max_clicked();
return true;
}
return QObject::eventFilter(obj, event);
}
void frmOperateParentInTree::mouseMoveEvent(QMouseEvent *e)
{
if (mousePressed && (e->buttons() && Qt::LeftButton) && !max) {
this->move(e->globalPos() - mousePoint);
e->accept();
}
}
void frmOperateParentInTree::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
mousePressed = true;
mousePoint = e->globalPos() - this->pos();
e->accept();
}
}
void frmOperateParentInTree::mouseReleaseEvent(QMouseEvent *)
{
mousePressed = false;
}
void frmOperateParentInTree::on_btnMenu_Close_clicked()
{
tableModel->revert();
this->close();
}
void frmOperateParentInTree::on_btnMenu_Max_clicked()
{
if (max) {
this->setGeometry(location);
IconHelper::Instance()->SetIcon(ui->btnMenu_Max, QChar(0xf096), 10);
ui->btnMenu_Max->setToolTip("最大化");
} else {
location = this->geometry();
this->setGeometry(qApp->desktop()->availableGeometry());
IconHelper::Instance()->SetIcon(ui->btnMenu_Max, QChar(0xf079), 10);
ui->btnMenu_Max->setToolTip("还原");
}
max = !max;
}
void frmOperateParentInTree::on_btnMenu_Min_clicked()
{
this->showMinimized();
}
void frmOperateParentInTree::btnAddNewParentInTree()
{
int rowNum = tableModel->rowCount();
tableModel->insertRow(rowNum);
tableModel->setData(tableModel->index(rowNum, 0),"测试开发区域");
tableModel->setData(tableModel->index(rowNum, 1), rowNum);
ui->tableView->setCurrentIndex(tableModel->index(tableModel->rowCount() - 1, 0));
}
void frmOperateParentInTree::btnCancel()
{
tableModel->revert();
this->close();
}
void frmOperateParentInTree::btnDelete()
{
int curRow = ui->tableView->currentIndex().row();
tableModel->removeRow(curRow);
int ok = QMessageBox::warning(this,tr("删除当前行!"),tr("你确定"
"删除当前行吗?"),
QMessageBox::Yes,QMessageBox::No);
if(ok == QMessageBox::No)
{
tableModel->revertAll(); //如果不删除,则撤销
}
else
{
tableModel->submitAll(); //否则提交,在数据库中删除该行
}
}
void frmOperateParentInTree::btnSave()
{
tableModel->submitAll();
emit sigParentInTreeChanged(1);
this->close();
}
void frmOperateParentInTree::btnEdit()
{
}
void frmOperateParentInTree::setTreeViewModel(QSqlTableModel *model)
{
if(tableModel==NULL)
{
tableModel = model;
ui->tableView->setModel(tableModel);
ui->tableView->hideColumn(1);
}
}