| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 or (at your option) any later version | 
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by | 
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 | 
| 22 | ** included in the packaging of this file. Please review the following | 
| 23 | ** information to ensure the GNU General Public License requirements will | 
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 25 | ** | 
| 26 | ** $QT_END_LICENSE$ | 
| 27 | ** | 
| 28 | ****************************************************************************/ | 
| 29 |  | 
| 30 | #include "dataseriedialog.h" | 
| 31 | #include <QtWidgets/QDialogButtonBox> | 
| 32 | #include <QtWidgets/QGridLayout> | 
| 33 | #include <QtWidgets/QCheckBox> | 
| 34 | #include <QtWidgets/QPushButton> | 
| 35 | #include <QtWidgets/QGroupBox> | 
| 36 | #include <QtWidgets/QRadioButton> | 
| 37 | #include <QtWidgets/QLabel> | 
| 38 | #include <QtCore/QDebug> | 
| 39 |  | 
| 40 | DataSerieDialog::DataSerieDialog(QWidget *parent) : | 
| 41 |     QDialog(parent) | 
| 42 | { | 
| 43 |     QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); | 
| 44 |     QPushButton *b = addSeriesBox->addButton(button: QDialogButtonBox::Ok); | 
| 45 |     connect(sender: b, SIGNAL(clicked()), receiver: this, SLOT(accept())); | 
| 46 |     b = addSeriesBox->addButton(button: QDialogButtonBox::Cancel); | 
| 47 |     connect(sender: b, SIGNAL(clicked()), receiver: this, SLOT(reject())); | 
| 48 |  | 
| 49 |     QGridLayout *grid = new QGridLayout(); | 
| 50 |  | 
| 51 |     m_seriesTypeSelector = seriesTypeSelector(); | 
| 52 |     m_columnCountSelector = columnCountSelector(); | 
| 53 |     m_rowCountSelector = rowCountSelector(); | 
| 54 |     m_dataCharacteristicsSelector = dataCharacteristicsSelector(); | 
| 55 |  | 
| 56 |     grid->addWidget(m_seriesTypeSelector, row: 0, column: 0); | 
| 57 |     grid->addWidget(m_columnCountSelector, row: 0, column: 1); | 
| 58 |     grid->addWidget(m_rowCountSelector, row: 1, column: 1); | 
| 59 |     grid->addWidget(m_dataCharacteristicsSelector, row: 1, column: 0); | 
| 60 |     m_labelsSelector = new QCheckBox("Labels defined" ); | 
| 61 |     m_labelsSelector->setChecked(true); | 
| 62 |     grid->addWidget(m_labelsSelector, row: 2, column: 0); | 
| 63 |     grid->addWidget(addSeriesBox, row: 3, column: 1); | 
| 64 |  | 
| 65 |     setLayout(grid); | 
| 66 | } | 
| 67 |  | 
| 68 | QGroupBox *DataSerieDialog::seriesTypeSelector() | 
| 69 | { | 
| 70 |     QVBoxLayout *layout = new QVBoxLayout(); | 
| 71 |  | 
| 72 |     QRadioButton *line = new QRadioButton("Line" ); | 
| 73 |     line->setChecked(true); | 
| 74 |     layout->addWidget(line); | 
| 75 |     layout->addWidget(new QRadioButton("Area" )); | 
| 76 |     layout->addWidget(new QRadioButton("Pie" )); | 
| 77 |     layout->addWidget(new QRadioButton("Bar" )); | 
| 78 |     layout->addWidget(new QRadioButton("Stacked bar" )); | 
| 79 |     layout->addWidget(new QRadioButton("Percent bar" )); | 
| 80 |     layout->addWidget(new QRadioButton("Scatter" )); | 
| 81 |     layout->addWidget(new QRadioButton("Spline" )); | 
| 82 |  | 
| 83 |     QGroupBox *groupBox = new QGroupBox("Series type" ); | 
| 84 |     groupBox->setLayout(layout); | 
| 85 |     selectRadio(groupBox, defaultSelection: 0); | 
| 86 |  | 
| 87 |     return groupBox; | 
| 88 | } | 
| 89 |  | 
| 90 | QGroupBox *DataSerieDialog::columnCountSelector() | 
| 91 | { | 
| 92 |     QVBoxLayout *layout = new QVBoxLayout(); | 
| 93 |  | 
| 94 |     QRadioButton *radio = new QRadioButton("1" ); | 
| 95 |     radio->setChecked(true); | 
| 96 |     layout->addWidget(radio); | 
| 97 |     layout->addWidget(new QRadioButton("2" )); | 
| 98 |     layout->addWidget(new QRadioButton("3" )); | 
| 99 |     layout->addWidget(new QRadioButton("4" )); | 
| 100 |     layout->addWidget(new QRadioButton("5" )); | 
| 101 |     layout->addWidget(new QRadioButton("8" )); | 
| 102 |     layout->addWidget(new QRadioButton("10" )); | 
| 103 |     layout->addWidget(new QRadioButton("100" )); | 
| 104 |  | 
| 105 |     QGroupBox *groupBox = new QGroupBox("Column count" ); | 
| 106 |     groupBox->setLayout(layout); | 
| 107 |     selectRadio(groupBox, defaultSelection: 0); | 
| 108 |  | 
| 109 |     return groupBox; | 
| 110 | } | 
| 111 |  | 
| 112 | QGroupBox *DataSerieDialog::rowCountSelector() | 
| 113 | { | 
| 114 |     QVBoxLayout *layout = new QVBoxLayout(); | 
| 115 |  | 
| 116 |     layout->addWidget(new QRadioButton("1" )); | 
| 117 |     QRadioButton *radio = new QRadioButton("10" ); | 
| 118 |     radio->setChecked(true); | 
| 119 |     layout->addWidget(radio); | 
| 120 |     layout->addWidget(new QRadioButton("50" )); | 
| 121 |     layout->addWidget(new QRadioButton("100" )); | 
| 122 |     layout->addWidget(new QRadioButton("1000" )); | 
| 123 |     layout->addWidget(new QRadioButton("10000" )); | 
| 124 |     layout->addWidget(new QRadioButton("100000" )); | 
| 125 |     layout->addWidget(new QRadioButton("1000000" )); | 
| 126 |  | 
| 127 |     QGroupBox *groupBox = new QGroupBox("Row count" ); | 
| 128 |     groupBox->setLayout(layout); | 
| 129 |     selectRadio(groupBox, defaultSelection: 0); | 
| 130 |  | 
| 131 |     return groupBox; | 
| 132 | } | 
| 133 |  | 
| 134 | QGroupBox *DataSerieDialog::dataCharacteristicsSelector() | 
| 135 | { | 
| 136 |     QVBoxLayout *layout = new QVBoxLayout(); | 
| 137 |  | 
| 138 |     layout->addWidget(new QRadioButton("Linear" )); | 
| 139 |     layout->addWidget(new QRadioButton("Constant" )); | 
| 140 |     layout->addWidget(new QRadioButton("Random" )); | 
| 141 |     layout->addWidget(new QRadioButton("Sin" )); | 
| 142 |     layout->addWidget(new QRadioButton("Sin + random" )); | 
| 143 |  | 
| 144 |     QGroupBox *groupBox = new QGroupBox("Data Characteristics" ); | 
| 145 |     groupBox->setLayout(layout); | 
| 146 |     selectRadio(groupBox, defaultSelection: 0); | 
| 147 |  | 
| 148 |     return groupBox; | 
| 149 | } | 
| 150 |  | 
| 151 | void DataSerieDialog::accept() | 
| 152 | { | 
| 153 |     accepted(series: radioSelection(groupBox: m_seriesTypeSelector), | 
| 154 |              columnCount: radioSelection(groupBox: m_columnCountSelector).toInt(), | 
| 155 |              rowCount: radioSelection(groupBox: m_rowCountSelector).toInt(), | 
| 156 |              dataCharacteristics: radioSelection(groupBox: m_dataCharacteristicsSelector), | 
| 157 |              labelsDefined: m_labelsSelector->isChecked()); | 
| 158 |     QDialog::accept(); | 
| 159 | } | 
| 160 |  | 
| 161 | void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection) | 
| 162 | { | 
| 163 |     QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(object: groupBox->layout()); | 
| 164 |     Q_ASSERT(layout); | 
| 165 |     Q_ASSERT(layout->count()); | 
| 166 |  | 
| 167 |     QLayoutItem *item = 0; | 
| 168 |     if (defaultSelection == -1) { | 
| 169 |         item = layout->itemAt(0); | 
| 170 |     } else if (layout->count() > defaultSelection) { | 
| 171 |         item = layout->itemAt(defaultSelection); | 
| 172 |     } | 
| 173 |     Q_ASSERT(item); | 
| 174 |     QRadioButton *radio = qobject_cast<QRadioButton *>(object: item->widget()); | 
| 175 |     Q_ASSERT(radio); | 
| 176 |     radio->setChecked(true); | 
| 177 | } | 
| 178 |  | 
| 179 | QString DataSerieDialog::radioSelection(QGroupBox *groupBox) | 
| 180 | { | 
| 181 |     QString selection; | 
| 182 |     QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(object: groupBox->layout()); | 
| 183 |     Q_ASSERT(layout); | 
| 184 |  | 
| 185 |     for (int i(0); i < layout->count(); i++) { | 
| 186 |         QLayoutItem *item = layout->itemAt(i); | 
| 187 |         Q_ASSERT(item); | 
| 188 |         QRadioButton *radio = qobject_cast<QRadioButton *>(object: item->widget()); | 
| 189 |         Q_ASSERT(radio); | 
| 190 |         if (radio->isChecked()) { | 
| 191 |             selection = radio->text(); | 
| 192 |             break; | 
| 193 |         } | 
| 194 |     } | 
| 195 |  | 
| 196 |     qDebug() << "radioSelection: "  << selection; | 
| 197 |     return selection; | 
| 198 | } | 
| 199 |  |