-
Notifications
You must be signed in to change notification settings - Fork 0
/
PieDesign.cpp
137 lines (131 loc) · 5.9 KB
/
PieDesign.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
#include"widget.cpp"
void Widget::PieCharts()
{
Pseries = new QPieSeries();
Pseries->setPieSize(ui->PieSize->value());
ui->PieTool->show();
Pseries->setPieStartAngle(0);
Pseries->setPieEndAngle(-360);
for(int i=0,j=0;i<ui->Piedata->columnCount();i++)
{
if(ui->Piedata->item(1,i)->text().toFloat() != 0)
{
// if(ui->Piedata->item(0,i)==NULL)
// {
// Pseries->append("",ui->Piedata->item(1,i)->text().toInt());
// Pseries->slices().at(i)->setLabel("%"+ QString::number(ui->Piedata->item(1,i)->text().toDouble()));
// }
// else
{
Pseries->append(ui->Piedata->item(0,i)->text()+":%",ui->Piedata->item(1,i)->text().toInt());
// QString perca=QString::number(virtulP.slices().at(i)->percentage(),'f',ui->Float->value());
Pseries->slices().at(j)->setLabel(Pseries->slices().at(j)->label()+QString::number(ui->Piedata->item(2,i)->text().toFloat()*100,'f',ui->Float->value()-2));
Pseries->slices().at(j)->setColor(QColor(rand()%256,rand()%256,rand()%256));
Pseries->slices().at(j)->setLabelColor(Pseries->slices().at(j)->color());
}
connect(Pseries->slices().at(j),&QPieSlice::doubleClicked,[=](){
QColor *color = new QColor(Pseries->slices().at(j)->color());
Pseries->slices().at(j)->setColor(QColorDialog::getColor());
Pseries->slices().at(j)->setLabelColor( Pseries->slices().at(j)->color());
if(Pseries->slices().at(j)->color().red()==0 && Pseries->slices().at(j)->color().green()==0 && Pseries->slices().at(j)->color().blue()==0)
{
Pseries->slices().at(j)->setColor(*color);
Pseries->slices().at(j)->setLabelColor( *color);
}
});
j++;
}
qDebug()<<i;
}
Pseries->setLabelsVisible(true);
Pseries->setUseOpenGL(true);
}
void Widget::DIVIDE()
{
for(int i=0;i<Pseries->count();i++)
{
Pseries->slices().at(i)->setExploded(*tag);
}
update();
if(*tag=!(*tag))
ui->Divide->setText("切片分离");
else
ui->Divide->setText("切片聚合");
}
void Widget::PIECHANGED()
{
if((ui->Piedata->currentItem()&&(ui->Piedata->currentItem()->text()=="" || *(ui->Piedata->currentItem()->text().toLocal8Bit().data()) < 48 ||*(ui->Piedata->currentItem()->text().toLocal8Bit().data()) > 57)))
{
if(ui->Piedata->currentItem()->row()!=0 )ui->Piedata->currentItem()->setText("0");
}
//&&
else if(ui->Piedata->currentRow() == 1 )
{
QPieSeries virtulP;//虚圆构造
InitP(&virtulP);
// qDebug()<<"虚圆构造";
*VirtulSum=virtulP.sum();
float wei=1;
for(int i=0;i<ui->Float->value();i++)
wei/=10;
qDebug()<<wei;
for(int i=0;i<ui->Piedata->columnCount();i++)
{
// qDebug()<<i<<"占比 : "<<virtulP.slices().at(i)->percentage();
// qDebug()<<virtulP.slices().at(i)->percentage() <<"-"<<ui->Piedata->item(2,i)->text().toDouble()<<"="<<
// virtulP.slices().at(i)->percentage() - ui->Piedata->item(2,i)->text().toDouble();
if(ui->Piedata->item(2,i)/*&&((virtulP.slices().at(i)->percentage() - ui->Piedata->item(2,i)->text().toDouble() >wei) || (virtulP.slices().at(i)->percentage() - ui->Piedata->item(2,i)->text().toDouble() <-wei)*/)
{
qDebug()<<"偏差值符合 : "<<virtulP.slices().at(i)->percentage();
QString perca=QString::number(virtulP.slices().at(i)->percentage(),'f',ui->Float->value());
qDebug()<<perca;
ui->Piedata->item(2,i)->setText(perca);
}
}
}
else if(ui->Piedata->currentRow()==2)
{
// qDebug()<<"啊?";
float c,b;
b=ui->Piedata->currentItem()->text().toFloat();
c=ui->Piedata->item(1,ui->Piedata->currentColumn())->text().toFloat();
float per=(((*VirtulSum)*b-c))/(1-b);
// qDebug()<<*a<<"*"<<b<<"-"<<c<<"/"<<"1-"<<b<<"="<<per;
QString res=QString::number((int)(per+c));
*VirtulSum += per;
// qDebug()<<"res"<<res;
ui->Piedata->item(1,ui->Piedata->currentItem()->column())->setText(res);
QPieSeries virtulP;//虚圆构造
InitP(&virtulP);
// qDebug()<<"虚圆构造";
*VirtulSum=virtulP.sum();
float wei=1;
for(int i=0;i<ui->Float->value();i++)
wei/=10;
qDebug()<<wei;
for(int i=0;i<ui->Piedata->columnCount();i++)
{
// qDebug()<<i;
// qDebug()<<i<<"占比 : "<<virtulP.slices().at(i)->percentage();
// qDebug()<<virtulP.slices().at(i)->percentage() <<"-"<<ui->Piedata->item(2,i)->text().toDouble()<<"="<<
// virtulP.slices().at(i)->percentage() - ui->Piedata->item(2,i)->text().toDouble();
if(ui->Piedata->item(2,i)/*&&((virtulP.slices().at(i)->percentage() - ui->Piedata->item(2,i)->text().toDouble() >wei) || (virtulP.slices().at(i)->percentage() - ui->Piedata->item(2,i)->text().toDouble() < -wei)*/)
{
qDebug()<<"偏差值符合 : "<<virtulP.slices().at(i)->percentage();
QString perca=QString::number(virtulP.slices().at(i)->percentage(),'f',ui->Float->value());
qDebug()<<perca;
ui->Piedata->item(2,i)->setText(perca);
}
}
}
}
void Widget::InitP(QPieSeries *temp)
{
for(int i=0;i<ui->Piedata->columnCount();i++)
{
if(ui->Piedata->item(1,i)!=NULL)
{
(temp)->append("",ui->Piedata->item(1,i)->text().toInt());
}
}
}