KD Chart 2  [rev.2.7]
KDChartDatasetSelector.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #include <QtDebug>
24 
25 #include "KDChartDatasetSelector.h"
26 
27 #include "ui_KDChartDatasetSelector.h"
28 
29 #include <KDABLibFakes>
30 
31 using namespace KDChart;
32 
34  : QFrame( parent )
35  , mUi( new Ui::DatasetSelector() )
36  , mSourceRowCount( 0 )
37  , mSourceColumnCount( 0 )
38 {
39  qWarning( "For DatasetSelectorWidget to become useful, it has to be connected to the proxy model it configures!" );
40 
41  mUi->setupUi( this );
42  setMinimumSize( minimumSizeHint() );
43 }
44 
46 {
47  delete mUi;
48 }
49 
50 void DatasetSelectorWidget::on_sbStartColumn_valueChanged( int )
51 {
52  calculateMapping();
53 }
54 
55 void DatasetSelectorWidget::on_sbStartRow_valueChanged( int )
56 {
57  calculateMapping();
58 }
59 
60 void DatasetSelectorWidget::on_sbColumnCount_valueChanged( int )
61 {
62  calculateMapping();
63 }
64 
65 void DatasetSelectorWidget::on_sbRowCount_valueChanged( int )
66 {
67  calculateMapping();
68 }
69 
70 void DatasetSelectorWidget::on_cbReverseRows_stateChanged( int )
71 {
72  calculateMapping();
73 }
74 
75 void DatasetSelectorWidget::on_cbReverseColumns_stateChanged( int )
76 {
77  calculateMapping();
78 }
79 
80 void DatasetSelectorWidget::on_groupBox_toggled( bool state )
81 {
82  if ( state )
83  {
84  calculateMapping();
85  } else {
86  emit mappingDisabled();
87  }
88 }
89 
90 
91 void DatasetSelectorWidget::setSourceRowCount( const int& rowCount )
92 {
93  if ( rowCount != mSourceRowCount )
94  {
95  mSourceRowCount = rowCount;
96  resetDisplayValues();
97  }
98 }
99 
100 void DatasetSelectorWidget::setSourceColumnCount( const int& columnCount )
101 {
102  if ( columnCount != mSourceColumnCount )
103  {
104  mSourceColumnCount = columnCount;
105  resetDisplayValues();
106  }
107 }
108 
109 void DatasetSelectorWidget::resetDisplayValues()
110 {
111  mUi->sbStartRow->setValue( 0 );
112  mUi->sbStartRow->setMinimum( 0 );
113  mUi->sbStartRow->setMaximum( qMax( mSourceRowCount - 1, 0 ) );
114  mUi->sbStartColumn->setValue( 0 );
115  mUi->sbStartColumn->setMinimum( 0 );
116  mUi->sbStartColumn->setMaximum( qMax( mSourceColumnCount - 1, 0 ) );
117  mUi->sbRowCount->setMinimum( 1 );
118  mUi->sbRowCount->setMaximum( mSourceRowCount );
119  mUi->sbRowCount->setValue( mSourceRowCount );
120  mUi->sbColumnCount->setMinimum( 1 );
121  mUi->sbColumnCount->setMaximum( mSourceColumnCount );
122  mUi->sbColumnCount->setValue( mSourceColumnCount );
123  mUi->groupBox->setChecked( false );
124  emit mappingDisabled();
125 }
126 
127 void DatasetSelectorWidget::calculateMapping()
128 {
129  if ( mSourceColumnCount < 2 && mSourceRowCount < 2 )
130  {
131  mUi->groupBox->setEnabled( false );
132  emit mappingDisabled();
133  } else {
134  mUi->groupBox->setEnabled( true );
135 
136  if ( ! mUi->groupBox->isChecked() )
137  {
138  emit mappingDisabled();
139  return;
140  }
141 
142  // retrieve values:
143  int startRow = mUi->sbStartRow->value();
144  int startColumn = mUi->sbStartColumn->value();
145  int rowCount = mUi->sbRowCount->value();
146  int columnCount = mUi->sbColumnCount->value();
147  bool reverseColumns = mUi->cbReverseColumns->checkState() == Qt::Checked;
148  bool reverseRows = mUi->cbReverseRows->checkState() == Qt::Checked;
149 
150  // verify values:
151  startRow = qMin( startRow, mSourceRowCount - 2 );
152  startRow = qMax( 0, startRow );
153  startColumn = qMin( startColumn, mSourceColumnCount - 2 );
154  startColumn = qMax( 0, startColumn );
155 
156  rowCount = qMin( rowCount, mSourceRowCount - startRow );
157  rowCount = qMax( 1, rowCount );
158  columnCount = qMin( columnCount, mSourceColumnCount - startColumn );
159  columnCount = qMax( 1, columnCount );
160 
161  DatasetDescriptionVector rowConfig( rowCount );
162  Q_ASSERT( rowConfig.size() > 0 );
163  DatasetDescriptionVector columnConfig( columnCount );
164  Q_ASSERT( columnConfig.size() > 0 );
165 
166  // fill the dataset description vectors:
167  for ( int row = 0; row < rowCount; ++row )
168  {
169  if ( reverseRows )
170  {
171  rowConfig[row] = startRow + rowCount - row - 1;
172  } else {
173  rowConfig[row] = startRow + row;
174  }
175  }
176 
177  for ( int column = 0; column < columnCount; ++ column )
178  {
179  if ( reverseColumns )
180  {
181  columnConfig[column] = startColumn + columnCount - column -1;
182  } else {
183  columnConfig[column] = startColumn + column;
184  }
185  }
186 
187  // and tell the world:
188  emit configureDatasetProxyModel( rowConfig, columnConfig );
189  }
190 }
191 
void configureDatasetProxyModel(const DatasetDescriptionVector &rowConfig, const DatasetDescriptionVector &columnConfig)
void setSourceRowCount(const int &rowCount)
void setSourceColumnCount(const int &columnCount)
Class only listed here to document inheritance of some KDChart classes.
Class only listed here to document inheritance of some KDChart classes.

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/