Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <QtDebug>
00024
00025 #include "KDChartDatasetSelector.h"
00026
00027 #include "ui_KDChartDatasetSelector.h"
00028
00029 #include <KDABLibFakes>
00030
00031 using namespace KDChart;
00032
00033 DatasetSelectorWidget::DatasetSelectorWidget ( QWidget* parent )
00034 : QFrame ( parent )
00035 , mUi ( new Ui::DatasetSelector () )
00036 , mSourceRowCount ( 0 )
00037 , mSourceColumnCount ( 0 )
00038 {
00039 qWarning("For DatasetSelectorWidget to become useful, it has to be connected to the proxy model it configures!");
00040
00041 mUi->setupUi ( this );
00042 setMinimumSize ( minimumSizeHint() );
00043 }
00044
00045 void DatasetSelectorWidget::on_sbStartColumn_valueChanged ( const int )
00046 {
00047 calculateMapping();
00048 }
00049
00050 void DatasetSelectorWidget::on_sbStartRow_valueChanged( const int )
00051 {
00052 calculateMapping();
00053 }
00054
00055 void DatasetSelectorWidget::on_sbColumnCount_valueChanged ( int )
00056 {
00057 calculateMapping();
00058 }
00059
00060 void DatasetSelectorWidget::on_sbRowCount_valueChanged ( int )
00061 {
00062 calculateMapping();
00063 }
00064
00065 void DatasetSelectorWidget::on_cbReverseRows_stateChanged ( int )
00066 {
00067 calculateMapping();
00068 }
00069
00070 void DatasetSelectorWidget::on_cbReverseColumns_stateChanged ( int )
00071 {
00072 calculateMapping();
00073 }
00074
00075 void DatasetSelectorWidget::on_groupBox_toggled( bool state )
00076 {
00077 if ( state )
00078 {
00079 calculateMapping();
00080 } else {
00081 emit mappingDisabled();
00082 }
00083 }
00084
00085
00086 void DatasetSelectorWidget::setSourceRowCount ( const int& rowCount )
00087 {
00088 if ( rowCount != mSourceRowCount )
00089 {
00090 mSourceRowCount = rowCount;
00091 resetDisplayValues();
00092 }
00093 }
00094
00095 void DatasetSelectorWidget::setSourceColumnCount ( const int& columnCount )
00096 {
00097 if ( columnCount != mSourceColumnCount )
00098 {
00099 mSourceColumnCount = columnCount;
00100 resetDisplayValues();
00101 }
00102 }
00103
00104 void DatasetSelectorWidget::resetDisplayValues()
00105 {
00106 mUi->sbStartRow->setValue( 0 );
00107 mUi->sbStartRow->setMinimum ( 0 );
00108 mUi->sbStartRow->setMaximum ( qMax ( mSourceRowCount - 1, 0 ) );
00109 mUi->sbStartColumn->setValue( 0 );
00110 mUi->sbStartColumn->setMinimum ( 0 );
00111 mUi->sbStartColumn->setMaximum ( qMax ( mSourceColumnCount - 1, 0 ) );
00112 mUi->sbRowCount->setMinimum ( 1 );
00113 mUi->sbRowCount->setMaximum ( mSourceRowCount );
00114 mUi->sbRowCount->setValue( mSourceRowCount );
00115 mUi->sbColumnCount->setMinimum ( 1 );
00116 mUi->sbColumnCount->setMaximum ( mSourceColumnCount );
00117 mUi->sbColumnCount->setValue( mSourceColumnCount );
00118 mUi->groupBox->setChecked ( false );
00119 emit mappingDisabled();
00120 }
00121
00122 void DatasetSelectorWidget::calculateMapping()
00123 {
00124 if ( mSourceColumnCount < 2 && mSourceRowCount < 2 )
00125 {
00126 mUi->groupBox->setEnabled ( false );
00127 emit mappingDisabled();
00128 } else {
00129 mUi->groupBox->setEnabled ( true );
00130
00131 if ( ! mUi->groupBox->isChecked() )
00132 {
00133 emit mappingDisabled();
00134 return;
00135 }
00136
00137
00138 int startRow = mUi->sbStartRow->value();
00139 int startColumn = mUi->sbStartColumn->value();
00140 int rowCount = mUi->sbRowCount->value();
00141 int columnCount = mUi->sbColumnCount->value();
00142 bool reverseColumns = mUi->cbReverseColumns->checkState() == Qt::Checked;
00143 bool reverseRows = mUi->cbReverseRows->checkState() == Qt::Checked;
00144
00145
00146 startRow = qMin ( startRow, mSourceRowCount - 2 );
00147 startRow = qMax ( 0, startRow );
00148 startColumn = qMin ( startColumn, mSourceColumnCount - 2 );
00149 startColumn = qMax ( 0, startColumn );
00150
00151 rowCount = qMin ( rowCount, mSourceRowCount - startRow );
00152 rowCount = qMax ( 1, rowCount );
00153 columnCount = qMin ( columnCount, mSourceColumnCount - startColumn );
00154 columnCount = qMax ( 1, columnCount );
00155
00156 DatasetDescriptionVector rowConfig ( rowCount );
00157 Q_ASSERT ( rowConfig.size() > 0 );
00158 DatasetDescriptionVector columnConfig ( columnCount );
00159 Q_ASSERT ( columnConfig.size() > 0 );
00160
00161
00162 for ( int row = 0; row < rowCount; ++row )
00163 {
00164 if ( reverseRows )
00165 {
00166 rowConfig[row] = startRow + rowCount - row - 1;
00167 } else {
00168 rowConfig[row] = startRow + row;
00169 }
00170 }
00171
00172 for ( int column = 0; column < columnCount; ++ column )
00173 {
00174 if ( reverseColumns )
00175 {
00176 columnConfig[column] = startColumn + columnCount - column -1;
00177 } else {
00178 columnConfig[column] = startColumn + column;
00179 }
00180 }
00181
00182
00183 emit configureDatasetProxyModel ( rowConfig, columnConfig );
00184 }
00185 }
00186