-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueryinfo.cpp
161 lines (142 loc) · 4.51 KB
/
queryinfo.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "queryinfo.h"
QueryInfo::QueryInfo(QWidget *parent):QAbstractItemView(parent)
{
}
int QueryInfo::Pointof(QPointF *line,int n)
{
int count = 0;
for(int i = 0;i<n;i++)
{
if(!line[i].isNull())
{
count++;
}
}
return count;
}
void QueryInfo::selector()
{
this->DataModel3.setQuery("select id,one,two,three from saveline1 where pose!= -1 and posc != -1 and poso != -1 and posh != -1");
this->DataModel3.setHeaderData(0, Qt::Horizontal, QObject::tr("id"));
this->DataModel3.setHeaderData(1, Qt::Horizontal, QObject::tr("one"));
this->DataModel3.setHeaderData(2, Qt::Horizontal, QObject::tr("two"));
this->DataModel3.setHeaderData(3, Qt::Horizontal, QObject::tr("three"));
qDebug() << this->DataModel3.lastError();
}
int QueryInfo::getXfromMap(int data)
{
for(int i = 0;i<4;i++)
{
for(int j = 0;j<5;j++)
{
if(data == mapper[i][j])
return i;
}
}
return -1;
}
int QueryInfo::getYfromMap(int data)
{
for(int i = 0;i<4;i++)
{
for(int j = 0;j<5;j++)
{
if(data == mapper[i][j])
return j;
}
}
return -1;
}
bool QueryInfo::selected(QSqlDatabase db,int index,QTableView *tv)
{
if(!db.isOpen())
return false;
else
{
ok = true;
int i = 0,j = 0;
QSqlQuery sql1;
QSqlQuery sql2;
QString as1;
QString as2;
QString s = QString::number(index-4, 10);
QString t = QString::number(index+1, 10);
as1 ="select one,two,three from saveline1 where 'id' >"+s+" and 'id' < "+t+"";
as2 ="select one,two,three from saveline2 where 'id' >"+s+" and 'id' < "+t+"";
sql1.prepare(as1);
sql1.exec();
qDebug() << sql1.lastError()<<as1;
while(sql1.next())
{
switch(i)
{
case 0: {
line1[0].setX(tv->columnViewportPosition(getXfromMap(sql1.value(0).toInt())));
line1[0].setY(tv->rowViewportPosition(getYfromMap(sql1.value(0).toInt())));
break;
}
case 1: {
line1[1].setX(tv->columnViewportPosition(getXfromMap(sql1.value(1).toInt())));
line1[1].setY(tv->rowViewportPosition(getYfromMap(sql1.value(1).toInt())));
break;
}
case 2: {
line1[2].setX(tv->columnViewportPosition(getXfromMap(sql1.value(2).toInt())));
line1[2].setY(tv->rowViewportPosition(getYfromMap(sql1.value(2).toInt())));
break;
}
}
i++;
}
sql2.prepare(as2);
sql2.exec();
qDebug() << sql2.lastError()<<as2;
while(sql2.next())
{
switch(j)
{
case 0: {
line2[0].setX(tv->columnViewportPosition(getXfromMap(sql2.value(0).toInt())));
line2[0].setY(tv->rowViewportPosition(getYfromMap(sql2.value(0).toInt())));
break;
}
case 1: {
line2[1].setX(tv->columnViewportPosition(getXfromMap(sql2.value(1).toInt())));
line2[1].setY(tv->rowViewportPosition(getYfromMap(sql2.value(1).toInt())));
break;
}
case 2: {
line2[2].setX(tv->columnViewportPosition(getXfromMap(sql2.value(2).toInt())));
line2[2].setY(tv->rowViewportPosition(getYfromMap(sql2.value(2).toInt())));
break;
}
}
j++;
}
len1 = Pointof(line1,6);
len2 = Pointof(line2,6);
}
repaint();
return true;
}
void QueryInfo::paintEvent(QPaintEvent *e)
{ // 创建QPainter一个对象
if(!ok)
return;
QPainter painter(viewport());
QPen pen;
//painter.begin(this);
QBrush bruch(Qt::FDiagPattern); // 画刷
pen.setColor(Qt::red);
painter.setPen(pen);
qDebug() <<"Hey Man";
bruch.setStyle(Qt::NoBrush); // 将画刷设置成null//fow what
painter.setBrush(bruch);
painter.drawPolyline(line1, len1);
painter.drawText(10,80,"FUck ouo!");
pen.setColor(Qt::red);
painter.setPen(pen);
bruch.setStyle(Qt::NoBrush); // 将画刷设置成null//fow what
painter.setBrush(bruch);
painter.drawPolyline(line2, len2);
}