KD Chart 2
[rev.2.5]
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Chart library. 00005 ** 00006 ** Licensees holding valid commercial KD Chart licenses may use this file in 00007 ** accordance with the KD Chart Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 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 DatasetSelectorWidget::~DatasetSelectorWidget() 00046 { 00047 delete mUi; 00048 } 00049 00050 void DatasetSelectorWidget::on_sbStartColumn_valueChanged( int ) 00051 { 00052 calculateMapping(); 00053 } 00054 00055 void DatasetSelectorWidget::on_sbStartRow_valueChanged( int ) 00056 { 00057 calculateMapping(); 00058 } 00059 00060 void DatasetSelectorWidget::on_sbColumnCount_valueChanged( int ) 00061 { 00062 calculateMapping(); 00063 } 00064 00065 void DatasetSelectorWidget::on_sbRowCount_valueChanged( int ) 00066 { 00067 calculateMapping(); 00068 } 00069 00070 void DatasetSelectorWidget::on_cbReverseRows_stateChanged( int ) 00071 { 00072 calculateMapping(); 00073 } 00074 00075 void DatasetSelectorWidget::on_cbReverseColumns_stateChanged( int ) 00076 { 00077 calculateMapping(); 00078 } 00079 00080 void DatasetSelectorWidget::on_groupBox_toggled( bool state ) 00081 { 00082 if ( state ) 00083 { 00084 calculateMapping(); 00085 } else { 00086 emit mappingDisabled(); 00087 } 00088 } 00089 00090 00091 void DatasetSelectorWidget::setSourceRowCount( const int& rowCount ) 00092 { 00093 if ( rowCount != mSourceRowCount ) 00094 { 00095 mSourceRowCount = rowCount; 00096 resetDisplayValues(); 00097 } 00098 } 00099 00100 void DatasetSelectorWidget::setSourceColumnCount( const int& columnCount ) 00101 { 00102 if ( columnCount != mSourceColumnCount ) 00103 { 00104 mSourceColumnCount = columnCount; 00105 resetDisplayValues(); 00106 } 00107 } 00108 00109 void DatasetSelectorWidget::resetDisplayValues() 00110 { 00111 mUi->sbStartRow->setValue( 0 ); 00112 mUi->sbStartRow->setMinimum( 0 ); 00113 mUi->sbStartRow->setMaximum( qMax( mSourceRowCount - 1, 0 ) ); 00114 mUi->sbStartColumn->setValue( 0 ); 00115 mUi->sbStartColumn->setMinimum( 0 ); 00116 mUi->sbStartColumn->setMaximum( qMax( mSourceColumnCount - 1, 0 ) ); 00117 mUi->sbRowCount->setMinimum( 1 ); 00118 mUi->sbRowCount->setMaximum( mSourceRowCount ); 00119 mUi->sbRowCount->setValue( mSourceRowCount ); 00120 mUi->sbColumnCount->setMinimum( 1 ); 00121 mUi->sbColumnCount->setMaximum( mSourceColumnCount ); 00122 mUi->sbColumnCount->setValue( mSourceColumnCount ); 00123 mUi->groupBox->setChecked( false ); 00124 emit mappingDisabled(); 00125 } 00126 00127 void DatasetSelectorWidget::calculateMapping() 00128 { 00129 if ( mSourceColumnCount < 2 && mSourceRowCount < 2 ) 00130 { 00131 mUi->groupBox->setEnabled( false ); 00132 emit mappingDisabled(); 00133 } else { 00134 mUi->groupBox->setEnabled( true ); 00135 00136 if ( ! mUi->groupBox->isChecked() ) 00137 { 00138 emit mappingDisabled(); 00139 return; 00140 } 00141 00142 // retrieve values: 00143 int startRow = mUi->sbStartRow->value(); 00144 int startColumn = mUi->sbStartColumn->value(); 00145 int rowCount = mUi->sbRowCount->value(); 00146 int columnCount = mUi->sbColumnCount->value(); 00147 bool reverseColumns = mUi->cbReverseColumns->checkState() == Qt::Checked; 00148 bool reverseRows = mUi->cbReverseRows->checkState() == Qt::Checked; 00149 00150 // verify values: 00151 startRow = qMin( startRow, mSourceRowCount - 2 ); 00152 startRow = qMax( 0, startRow ); 00153 startColumn = qMin( startColumn, mSourceColumnCount - 2 ); 00154 startColumn = qMax( 0, startColumn ); 00155 00156 rowCount = qMin( rowCount, mSourceRowCount - startRow ); 00157 rowCount = qMax( 1, rowCount ); 00158 columnCount = qMin( columnCount, mSourceColumnCount - startColumn ); 00159 columnCount = qMax( 1, columnCount ); 00160 00161 DatasetDescriptionVector rowConfig( rowCount ); 00162 Q_ASSERT( rowConfig.size() > 0 ); 00163 DatasetDescriptionVector columnConfig( columnCount ); 00164 Q_ASSERT( columnConfig.size() > 0 ); 00165 00166 // fill the dataset description vectors: 00167 for ( int row = 0; row < rowCount; ++row ) 00168 { 00169 if ( reverseRows ) 00170 { 00171 rowConfig[row] = startRow + rowCount - row - 1; 00172 } else { 00173 rowConfig[row] = startRow + row; 00174 } 00175 } 00176 00177 for ( int column = 0; column < columnCount; ++ column ) 00178 { 00179 if ( reverseColumns ) 00180 { 00181 columnConfig[column] = startColumn + columnCount - column -1; 00182 } else { 00183 columnConfig[column] = startColumn + column; 00184 } 00185 } 00186 00187 // and tell the world: 00188 emit configureDatasetProxyModel( rowConfig, columnConfig ); 00189 } 00190 } 00191