KD Chart API Documentation  3.1
KDChartDatasetSelector.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file is part of the KD Chart library.
4 **
5 ** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: MIT
8 **
9 ****************************************************************************/
10 
11 #include <QtDebug>
12 
13 #include "KDChartDatasetSelector.h"
14 
15 #include "ui_KDChartDatasetSelector.h"
16 
17 #include <KDABLibFakes>
18 
19 using namespace KDChart;
20 
22  : QFrame(parent)
23  , mUi(new Ui::DatasetSelector())
24 {
25  qWarning("For DatasetSelectorWidget to become useful, it has to be connected to the proxy model it configures!");
26 
27  mUi->setupUi(this);
28  setMinimumSize(minimumSizeHint());
29 }
30 
32 {
33  delete mUi;
34 }
35 
36 void DatasetSelectorWidget::on_sbStartColumn_valueChanged(int)
37 {
38  calculateMapping();
39 }
40 
41 void DatasetSelectorWidget::on_sbStartRow_valueChanged(int)
42 {
43  calculateMapping();
44 }
45 
46 void DatasetSelectorWidget::on_sbColumnCount_valueChanged(int)
47 {
48  calculateMapping();
49 }
50 
51 void DatasetSelectorWidget::on_sbRowCount_valueChanged(int)
52 {
53  calculateMapping();
54 }
55 
56 void DatasetSelectorWidget::on_cbReverseRows_stateChanged(int)
57 {
58  calculateMapping();
59 }
60 
61 void DatasetSelectorWidget::on_cbReverseColumns_stateChanged(int)
62 {
63  calculateMapping();
64 }
65 
66 void DatasetSelectorWidget::on_groupBox_toggled(bool state)
67 {
68  if (state) {
69  calculateMapping();
70  } else {
71  Q_EMIT mappingDisabled();
72  }
73 }
74 
76 {
77  if (rowCount != mSourceRowCount) {
78  mSourceRowCount = rowCount;
79  resetDisplayValues();
80  }
81 }
82 
83 void DatasetSelectorWidget::setSourceColumnCount(const int &columnCount)
84 {
85  if (columnCount != mSourceColumnCount) {
86  mSourceColumnCount = columnCount;
87  resetDisplayValues();
88  }
89 }
90 
91 void DatasetSelectorWidget::resetDisplayValues()
92 {
93  mUi->sbStartRow->setValue(0);
94  mUi->sbStartRow->setMinimum(0);
95  mUi->sbStartRow->setMaximum(qMax(mSourceRowCount - 1, 0));
96  mUi->sbStartColumn->setValue(0);
97  mUi->sbStartColumn->setMinimum(0);
98  mUi->sbStartColumn->setMaximum(qMax(mSourceColumnCount - 1, 0));
99  mUi->sbRowCount->setMinimum(1);
100  mUi->sbRowCount->setMaximum(mSourceRowCount);
101  mUi->sbRowCount->setValue(mSourceRowCount);
102  mUi->sbColumnCount->setMinimum(1);
103  mUi->sbColumnCount->setMaximum(mSourceColumnCount);
104  mUi->sbColumnCount->setValue(mSourceColumnCount);
105  mUi->groupBox->setChecked(false);
106  Q_EMIT mappingDisabled();
107 }
108 
109 void DatasetSelectorWidget::calculateMapping()
110 {
111  if (mSourceColumnCount < 2 && mSourceRowCount < 2) {
112  mUi->groupBox->setEnabled(false);
113  Q_EMIT mappingDisabled();
114  } else {
115  mUi->groupBox->setEnabled(true);
116 
117  if (!mUi->groupBox->isChecked()) {
118  Q_EMIT mappingDisabled();
119  return;
120  }
121 
122  // retrieve values:
123  int startRow = mUi->sbStartRow->value();
124  int startColumn = mUi->sbStartColumn->value();
125  int rowCount = mUi->sbRowCount->value();
126  int columnCount = mUi->sbColumnCount->value();
127  bool reverseColumns = mUi->cbReverseColumns->checkState() == Qt::Checked;
128  bool reverseRows = mUi->cbReverseRows->checkState() == Qt::Checked;
129 
130  // verify values:
131  startRow = qMin(startRow, mSourceRowCount - 2);
132  startRow = qMax(0, startRow);
133  startColumn = qMin(startColumn, mSourceColumnCount - 2);
134  startColumn = qMax(0, startColumn);
135 
136  rowCount = qMin(rowCount, mSourceRowCount - startRow);
137  rowCount = qMax(1, rowCount);
138  columnCount = qMin(columnCount, mSourceColumnCount - startColumn);
139  columnCount = qMax(1, columnCount);
140 
141  DatasetDescriptionVector rowConfig(rowCount);
142  Q_ASSERT(rowConfig.size() > 0);
143  DatasetDescriptionVector columnConfig(columnCount);
144  Q_ASSERT(columnConfig.size() > 0);
145 
146  // fill the dataset description vectors:
147  for (int row = 0; row < rowCount; ++row) {
148  if (reverseRows) {
149  rowConfig[row] = startRow + rowCount - row - 1;
150  } else {
151  rowConfig[row] = startRow + row;
152  }
153  }
154 
155  for (int column = 0; column < columnCount; ++column) {
156  if (reverseColumns) {
157  columnConfig[column] = startColumn + columnCount - column - 1;
158  } else {
159  columnConfig[column] = startColumn + column;
160  }
161  }
162 
163  // and tell the world:
164  Q_EMIT configureDatasetProxyModel(rowConfig, columnConfig);
165  }
166 }
DatasetSelectorWidget(QWidget *parent=nullptr)
void setSourceRowCount(const int &rowCount)
void configureDatasetProxyModel(const DatasetDescriptionVector &rowConfig, const DatasetDescriptionVector &columnConfig)
void setSourceColumnCount(const int &columnCount)
QVector< int > DatasetDescriptionVector

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated by doxygen 1.9.1