##// END OF EJS Templates
Add dialog of chartwidgettest now remembers selections
Tero Ahola -
r376:173abb78cc61
parent child
Show More
@@ -8,7 +8,7
8 8 #include <QLabel>
9 9 #include <QDebug>
10 10
11 DataSerieDialog::DataSerieDialog(QString defaultType, QWidget *parent) :
11 DataSerieDialog::DataSerieDialog(QWidget *parent) :
12 12 QDialog(parent)
13 13 {
14 14 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
@@ -53,6 +53,7 QGroupBox *DataSerieDialog::seriesTypeSelector()
53 53
54 54 QGroupBox *groupBox = new QGroupBox("Series type");
55 55 groupBox->setLayout(layout);
56 selectRadio(groupBox, 0);
56 57
57 58 return groupBox;
58 59 }
@@ -72,6 +73,7 QGroupBox *DataSerieDialog::columnCountSelector()
72 73
73 74 QGroupBox *groupBox = new QGroupBox("Column count");
74 75 groupBox->setLayout(layout);
76 selectRadio(groupBox, 0);
75 77
76 78 return groupBox;
77 79 }
@@ -91,6 +93,7 QGroupBox *DataSerieDialog::rowCountSelector()
91 93
92 94 QGroupBox *groupBox = new QGroupBox("Row count");
93 95 groupBox->setLayout(layout);
96 selectRadio(groupBox, 0);
94 97
95 98 return groupBox;
96 99 }
@@ -99,9 +102,7 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
99 102 {
100 103 QVBoxLayout *layout = new QVBoxLayout();
101 104
102 QRadioButton *radio1 = new QRadioButton("Linear");
103 radio1->setChecked(true);
104 layout->addWidget(radio1);
105 layout->addWidget(new QRadioButton("Linear"));
105 106 layout->addWidget(new QRadioButton("Constant"));
106 107 layout->addWidget(new QRadioButton("Random"));
107 108 layout->addWidget(new QRadioButton("Sin"));
@@ -109,6 +110,7 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
109 110
110 111 QGroupBox *groupBox = new QGroupBox("Data Characteristics");
111 112 groupBox->setLayout(layout);
113 selectRadio(groupBox, 0);
112 114
113 115 return groupBox;
114 116 }
@@ -123,6 +125,24 void DataSerieDialog::accept()
123 125 QDialog::accept();
124 126 }
125 127
128 void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection)
129 {
130 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
131 Q_ASSERT(layout);
132 Q_ASSERT(layout->count());
133
134 QLayoutItem *item = 0;
135 if (defaultSelection == -1) {
136 item = layout->itemAt(0);
137 } else if (layout->count() > defaultSelection) {
138 item = layout->itemAt(defaultSelection);
139 }
140 Q_ASSERT(item);
141 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
142 Q_ASSERT(radio);
143 radio->setChecked(true);
144 }
145
126 146 QString DataSerieDialog::radioSelection(QGroupBox *groupBox)
127 147 {
128 148 QString selection;
@@ -10,7 +10,7 class DataSerieDialog : public QDialog
10 10 {
11 11 Q_OBJECT
12 12 public:
13 explicit DataSerieDialog(QString defaultType, QWidget *parent = 0);
13 explicit DataSerieDialog(QWidget *parent = 0);
14 14
15 15 signals:
16 16 void accepted(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsDefined);
@@ -23,6 +23,7 private:
23 23 QGroupBox *columnCountSelector();
24 24 QGroupBox *rowCountSelector();
25 25 QGroupBox *dataCharacteristicsSelector();
26 void selectRadio(QGroupBox *groupBox, int defaultSelection);
26 27 QString radioSelection(QGroupBox *groupBox);
27 28 QGroupBox *m_seriesTypeSelector;
28 29 QGroupBox *m_columnCountSelector;
@@ -25,7 +25,9
25 25 QTCOMMERCIALCHART_USE_NAMESPACE
26 26
27 27 MainWidget::MainWidget(QWidget *parent) :
28 QWidget(parent)
28 QWidget(parent),
29 m_addSerieDialog(0),
30 m_chartWidget(0)
29 31 {
30 32 m_chartWidget = new QChartView(this);
31 33 m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand);
@@ -163,10 +165,12 void MainWidget::initPieControls()
163 165
164 166 void MainWidget::addSeries()
165 167 {
166 DataSerieDialog dialog(m_defaultSeriesName, this);
167 connect(&dialog, SIGNAL(accepted(QString, int, int, QString, bool)),
168 this, SLOT(addSeries(QString, int, int, QString, bool)));
169 dialog.exec();
168 if (!m_addSerieDialog) {
169 m_addSerieDialog = new DataSerieDialog(this);
170 connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)),
171 this, SLOT(addSeries(QString, int, int, QString, bool)));
172 }
173 m_addSerieDialog->exec();
170 174 }
171 175
172 176 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
@@ -12,6 +12,7 class QGridLayout;
12 12 QTCOMMERCIALCHART_USE_NAMESPACE
13 13
14 14 #define RealList QList<qreal>
15 class DataSerieDialog;
15 16
16 17 class MainWidget : public QWidget
17 18 {
@@ -44,6 +45,7 private slots:
44 45 QStringList generateLabels(int count);
45 46
46 47 private:
48 DataSerieDialog *m_addSerieDialog;
47 49 QChartView *m_chartWidget;
48 50 QCheckBox *m_autoScaleCheck;
49 51 QSpinBox *m_xMinSpin;
General Comments 0
You need to be logged in to leave comments. Login now