3 #include <QStandardItemModel> 4 #include <QStandardItem> 11 #define PI 3.141592653590 18 QStandardItemModel *model =
new QStandardItemModel();
19 QList<QStandardItem *> items;
20 items.append(
new QStandardItem(
"Demo 1"));
21 items.append(
new QStandardItem(
"Demo 2"));
22 items.append(
new QStandardItem(
"Demo 3"));
23 items.append(
new QStandardItem(
"Demo 4"));
24 items.append(
new QStandardItem(
"Clear"));
25 model->appendColumn(items);
26 ui->selectionView->setModel(model);
27 ui->selectionView->header()->hide();
28 ui->selectionView->setColumnWidth(0,30);
30 connect(ui->theFigure, SIGNAL(curve_selected(
int)),
this, SLOT(on_selection_changed(
int)));
38 void MainWindow::on_selectionView_clicked(
const QModelIndex &index)
46 ui->theFigure->clear();
48 int cnt = index.row();
52 for (
double s=5.;s<=128.9;s+=0.1)
55 y.append( 2.+sin(0.1*s) );
56 z.append( 2.+cos(0.1*s) );
59 idx = ui->theFigure->plot(x,y);
62 ui->theFigure->setTitle(
"Demo #1: simple functions");
63 ui->theFigure->setXLabel(
"x -->");
64 ui->theFigure->setYLabel(
"f(x) -->");
65 ui->theFigure->showLegend();
70 for (
double s=0.;s<=2.*
PI;s+=
PI/20)
73 y.append( 200. + 150*sin(s) );
74 z.append( 200. + 150*cos(s) );
75 d.append( 200. + 175*0.5*s/
PI * cos(s));
76 u.append( 200. + 175*0.5*s/
PI * sin(s));
82 ui->theFigure->setTitle(
"Demo #2: parametric plot");
83 ui->theFigure->setXLabel(
"x(s) -->");
84 ui->theFigure->setYLabel(
"y(s) -->");
85 ui->theFigure->showLegend();
90 for (
double s=0.;s<=2.*
PI;s+=
PI/20)
93 y.append( 200. + 150*sin(s) );
94 z.append( 200. + 150*cos(s) );
95 d.append( 200. - 125. + 125*s/
PI );
96 u.append( 200. + 125 * sin(s));
102 ui->theFigure->setTitle(
"Demo #3: scatter plot");
103 ui->theFigure->setXLabel(
"x -->");
104 ui->theFigure->setYLabel(
"y = f(x) -->");
105 ui->theFigure->showLegend();
110 for (
double s=0.;s<=2.*
PI;s+=
PI/20)
113 y.append( 200. + 150*sin(s) );
114 z.append( 200. + 150*cos(s) );
115 d.append( 200. - 125. + 125*s/
PI );
116 u.append( 200. + 125 * sin(s));
122 ui->theFigure->setTitle(
"Demo #4: ");
123 ui->theFigure->setTitleFontSize(24);
124 ui->theFigure->setXLabel(
"index i");
125 ui->theFigure->setYLabel(
"element a_i");
126 ui->theFigure->setLabelFontSize(20);
127 ui->theFigure->showLegend();
137 ui->theFigure->showLegend(
false);
141 ui->showLegend->setCheckState(Qt::CheckState::Checked);
144 void MainWindow::on_selection_changed(
int ID)
148 ui->btn_option3->setText(tr(
"ID = %1\n\nclick to\nclear\nselection").arg(ID));
149 ui->btn_option3->setStyleSheet(
"color: #cc4444");
154 ui->btn_1st->setChecked(
true);
157 ui->btn_2nd->setChecked(
true);
160 ui->btn_none->setChecked(
true);
164 ui->btn_option3->setText(tr(
"none\nselected"));
165 ui->btn_option3->setStyleSheet(
"color: #cc4444");
167 ui->btn_none->setChecked(
true);
171 void MainWindow::on_btn_option1_clicked()
173 if (ui->theFigure->legendVisible()) {
174 ui->showLegend->setCheckState(Qt::CheckState::Unchecked);
177 ui->showLegend->setCheckState(Qt::CheckState::Checked);
182 void MainWindow::on_btn_option2_clicked()
184 QVector<SimFigure::Location> locList({
196 if (currentLocation >= locList.length()) currentLocation -= locList.length();
197 ui->theFigure->moveLegend(locList[currentLocation]);
200 void MainWindow::on_btn_option3_clicked()
202 ui->theFigure->clearSelection();
203 ui->btn_none->setChecked(
true);
206 void MainWindow::on_btn_1st_clicked()
208 ui->theFigure->select(1);
211 void MainWindow::on_btn_2nd_clicked()
213 ui->theFigure->select(2);
216 void MainWindow::on_btn_none_clicked()
218 ui->theFigure->clearSelection();
221 void MainWindow::on_action_Save_triggered()
226 void MainWindow::on_actionSave_As_triggered()
231 void MainWindow::on_actionSave_Hi_res_triggered()
236 void MainWindow::on_actionSave_PDF_triggered()
241 void MainWindow::on_actionShow_axis_controls_triggered()
243 ui->theFigure->showAxisControls(
true);
246 void MainWindow::on_actionHide_axis_controls_triggered()
248 ui->theFigure->showAxisControls(
false);
251 void MainWindow::on_btn_option4_clicked()
253 ui->theFigure->fit_data();
256 void MainWindow::on_showLegend_stateChanged(
int arg1)
258 ui->theFigure->showLegend((ui->showLegend->checkState()==Qt::CheckState::Checked));
261 void MainWindow::on_zoomOut_clicked()
263 double xmax = ui->theFigure->maxX();
264 double xmin = ui->theFigure->minX();
265 double ymax = ui->theFigure->maxY();
266 double ymin = ui->theFigure->minY();
271 ui->theFigure->setXLim(xmin-w/10.,xmax+w/10.);
272 ui->theFigure->setYLim(ymin-h/10.,ymax+h/10.);
275 void MainWindow::on_zoomIn_clicked()
277 double xmax = ui->theFigure->maxX();
278 double xmin = ui->theFigure->minX();
279 double ymax = ui->theFigure->maxY();
280 double ymin = ui->theFigure->minY();
285 ui->theFigure->setXLim(xmin+w/10.,xmax-w/10.);
286 ui->theFigure->setYLim(ymin+h/10.,ymax-h/10.);
MainWindow(QWidget *parent=0)