9#include "KChartDatasetSelector.h"
11#include "ui_KChartDatasetSelector.h"
13#include "KChartMath_p.h"
17DatasetSelectorWidget::DatasetSelectorWidget(
QWidget* parent )
19 , mUi( new Ui::DatasetSelector() )
20 , mSourceRowCount( 0 )
21 , mSourceColumnCount( 0 )
23 qWarning(
"For DatasetSelectorWidget to become useful, it has to be connected to the proxy model it configures!" );
26 setMinimumSize( minimumSizeHint() );
28 connect( mUi->sbStartColumn, SIGNAL(valueChanged(
int)),
this, SLOT(calculateMapping()) );
29 connect( mUi->sbStartRow, SIGNAL(valueChanged(
int)),
this, SLOT(calculateMapping()) );
30 connect( mUi->sbColumnCount, SIGNAL(valueChanged(
int)),
this, SLOT(calculateMapping()) );
31 connect( mUi->sbRowCount, SIGNAL(valueChanged(
int)),
this, SLOT(calculateMapping()) );
32 connect( mUi->cbReverseRows, SIGNAL(stateChanged(
int)),
this, SLOT(calculateMapping()) );
33 connect( mUi->cbReverseColumns, SIGNAL(stateChanged(
int)),
this, SLOT(calculateMapping()) );
34 connect( mUi->groupBox, SIGNAL(toggled(
bool)),
this, SLOT(updateState(
bool)) );
37DatasetSelectorWidget::~DatasetSelectorWidget()
42void DatasetSelectorWidget::updateState(
bool state )
53void DatasetSelectorWidget::setSourceRowCount(
const int& rowCount )
55 if ( rowCount != mSourceRowCount )
57 mSourceRowCount = rowCount;
62void DatasetSelectorWidget::setSourceColumnCount(
const int& columnCount )
64 if ( columnCount != mSourceColumnCount )
66 mSourceColumnCount = columnCount;
71void DatasetSelectorWidget::resetDisplayValues()
73 mUi->sbStartRow->setValue( 0 );
74 mUi->sbStartRow->setMinimum( 0 );
75 mUi->sbStartRow->setMaximum( qMax( mSourceRowCount - 1, 0 ) );
76 mUi->sbStartColumn->setValue( 0 );
77 mUi->sbStartColumn->setMinimum( 0 );
78 mUi->sbStartColumn->setMaximum( qMax( mSourceColumnCount - 1, 0 ) );
79 mUi->sbRowCount->setMinimum( 1 );
80 mUi->sbRowCount->setMaximum( mSourceRowCount );
81 mUi->sbRowCount->setValue( mSourceRowCount );
82 mUi->sbColumnCount->setMinimum( 1 );
83 mUi->sbColumnCount->setMaximum( mSourceColumnCount );
84 mUi->sbColumnCount->setValue( mSourceColumnCount );
85 mUi->groupBox->setChecked(
false );
89void DatasetSelectorWidget::calculateMapping()
91 if ( mSourceColumnCount < 2 && mSourceRowCount < 2 )
93 mUi->groupBox->setEnabled(
false );
96 mUi->groupBox->setEnabled(
true );
98 if ( ! mUi->groupBox->isChecked() )
105 int startRow = mUi->sbStartRow->value();
106 int startColumn = mUi->sbStartColumn->value();
107 int rowCount = mUi->sbRowCount->value();
108 int columnCount = mUi->sbColumnCount->value();
109 bool reverseColumns = mUi->cbReverseColumns->checkState() ==
Qt::Checked;
110 bool reverseRows = mUi->cbReverseRows->checkState() ==
Qt::Checked;
113 startRow = qMin( startRow, mSourceRowCount - 2 );
114 startRow = qMax( 0, startRow );
115 startColumn = qMin( startColumn, mSourceColumnCount - 2 );
116 startColumn = qMax( 0, startColumn );
118 rowCount = qMin( rowCount, mSourceRowCount - startRow );
119 rowCount = qMax( 1, rowCount );
120 columnCount = qMin( columnCount, mSourceColumnCount - startColumn );
121 columnCount = qMax( 1, columnCount );
124 Q_ASSERT( rowConfig.size() > 0 );
126 Q_ASSERT( columnConfig.size() > 0 );
129 for (
int row = 0; row < rowCount; ++row )
133 rowConfig[row] = startRow + rowCount - row - 1;
135 rowConfig[row] = startRow + row;
139 for (
int column = 0; column < columnCount; ++ column )
141 if ( reverseColumns )
143 columnConfig[column] = startColumn + columnCount - column -1;
145 columnConfig[column] = startColumn + column;
150 Q_EMIT configureDatasetProxyModel( rowConfig, columnConfig );
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)