|
17 | 17 |
|
18 | 18 | #include "qgsaddattrdialog.h" |
19 | 19 | #include "qgsvectordataprovider.h" |
| 20 | +#include "qgslogger.h" |
20 | 21 |
|
21 | 22 | QgsAddAttrDialog::QgsAddAttrDialog( QgsVectorDataProvider* provider, QWidget *parent, Qt::WFlags fl ) |
22 | 23 | : QDialog( parent, fl ), mDataProvider( provider ) |
23 | 24 | { |
24 | 25 | setupUi( this ); |
25 | 26 |
|
26 | 27 | //fill data types into the combo box |
27 | | - const QgsNativeTypeMap &typelist = mDataProvider->supportedNativeTypes(); |
| 28 | + const QList< QgsVectorDataProvider::NativeType > &typelist = mDataProvider->nativeTypes(); |
28 | 29 |
|
29 | | - for ( QgsNativeTypeMap::const_iterator it = typelist.constBegin(); it != typelist.constEnd(); ++it ) |
| 30 | + for ( int i = 0; i < typelist.size(); i++ ) |
30 | 31 | { |
31 | | - mTypeBox->addItem( it.key() ); |
| 32 | + QgsDebugMsg( QString( "name:%1 type:%2 typeName:%3 length:%4-%5 prec:%6-%7" ) |
| 33 | + .arg( typelist[i].mTypeDesc ) |
| 34 | + .arg( typelist[i].mType ) |
| 35 | + .arg( typelist[i].mTypeName ) |
| 36 | + .arg( typelist[i].mMinLen ).arg( typelist[i].mMaxLen ) |
| 37 | + .arg( typelist[i].mMinPrec ).arg( typelist[i].mMaxPrec ) ); |
| 38 | + |
| 39 | + mTypeBox->addItem( typelist[i].mTypeDesc ); |
| 40 | + mTypeBox->setItemData( i, static_cast<int>( typelist[i].mType ), Qt::UserRole ); |
| 41 | + mTypeBox->setItemData( i, typelist[i].mTypeName, Qt::UserRole + 1 ); |
| 42 | + mTypeBox->setItemData( i, typelist[i].mMinLen, Qt::UserRole + 2 ); |
| 43 | + mTypeBox->setItemData( i, typelist[i].mMaxLen, Qt::UserRole + 3 ); |
| 44 | + mTypeBox->setItemData( i, typelist[i].mMinPrec, Qt::UserRole + 4 ); |
| 45 | + mTypeBox->setItemData( i, typelist[i].mMaxPrec, Qt::UserRole + 5 ); |
32 | 46 | } |
| 47 | + |
| 48 | + on_mTypeBox_currentIndexChanged( 0 ); |
33 | 49 | } |
34 | 50 |
|
35 | | -QgsAddAttrDialog::QgsAddAttrDialog( const std::list<QString>& typelist, QWidget *parent, Qt::WFlags fl ) |
36 | | - : QDialog( parent, fl ), mDataProvider( 0 ) |
| 51 | +void QgsAddAttrDialog::on_mTypeBox_currentIndexChanged( int idx ) |
37 | 52 | { |
38 | | - setupUi( this ); |
| 53 | + mTypeName->setText( mTypeBox->itemData( idx, Qt::UserRole + 1 ).toString() ); |
39 | 54 |
|
40 | | - for ( std::list<QString>::const_iterator iter = typelist.begin();iter != typelist.end();++iter ) |
41 | | - { |
42 | | - mTypeBox->addItem( *iter ); |
43 | | - } |
44 | | -} |
| 55 | + mLength->setMinimum( mTypeBox->itemData( idx, Qt::UserRole + 2 ).toInt() ); |
| 56 | + mLength->setMaximum( mTypeBox->itemData( idx, Qt::UserRole + 3 ).toInt() ); |
| 57 | + mLength->setVisible( mLength->minimum() < mLength->maximum() ); |
| 58 | + if ( mLength->value() < mLength->minimum() ) |
| 59 | + mLength->setValue( mLength->minimum() ); |
| 60 | + if ( mLength->value() > mLength->maximum() ) |
| 61 | + mLength->setValue( mLength->maximum() ); |
45 | 62 |
|
46 | | -QString QgsAddAttrDialog::name() const |
47 | | -{ |
48 | | - return mNameEdit->text(); |
| 63 | + mPrec->setMinimum( mTypeBox->itemData( idx, Qt::UserRole + 4 ).toInt() ); |
| 64 | + mPrec->setMaximum( mTypeBox->itemData( idx, Qt::UserRole + 5 ).toInt() ); |
| 65 | + mPrec->setVisible( mPrec->minimum() < mPrec->maximum() ); |
| 66 | + if ( mPrec->value() < mPrec->minimum() ) |
| 67 | + mPrec->setValue( mPrec->minimum() ); |
| 68 | + if ( mPrec->value() > mPrec->maximum() ) |
| 69 | + mPrec->setValue( mPrec->maximum() ); |
49 | 70 | } |
50 | 71 |
|
51 | | -QString QgsAddAttrDialog::type() const |
| 72 | +QgsField QgsAddAttrDialog::field() const |
52 | 73 | { |
53 | | - return mTypeBox->currentText(); |
| 74 | + QgsDebugMsg( QString( "idx:%1 name:%2 type:%3 typeName:%4 length:%5 prec:%6 comment:%7" ) |
| 75 | + .arg( mTypeBox->currentIndex() ) |
| 76 | + .arg( mNameEdit->text() ) |
| 77 | + .arg( mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toInt() ) |
| 78 | + .arg( mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole + 1 ).toString() ) |
| 79 | + .arg( mLength->value() ) |
| 80 | + .arg( mPrec->value() ) |
| 81 | + .arg( mCommentEdit->text() ) ); |
| 82 | + |
| 83 | + return QgsField( |
| 84 | + mNameEdit->text(), |
| 85 | + ( QVariant::Type ) mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toInt(), |
| 86 | + mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole + 1 ).toString(), |
| 87 | + mLength->value(), |
| 88 | + mPrec->value(), |
| 89 | + mCommentEdit->text() ); |
54 | 90 | } |
0 commit comments