00001 /*************************************************************************** 00002 qgsgeomtypedialog.cpp - description 00003 ------------------- 00004 begin : October 2004 00005 copyright : (C) 2004 by Marco Hugentobler 00006 email : marco.hugentobler@autoform.ch 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 /* $Id: qgsgeomtypedialog.cpp 9471 2008-10-10 20:02:22Z jef $ */ 00018 00019 #include "qgsgeomtypedialog.h" 00020 #include "qgsapplication.h" 00021 #include "qgisapp.h" // <- for theme icons 00022 #include <QPushButton> 00023 00024 QgsGeomTypeDialog::QgsGeomTypeDialog( QWidget *parent, Qt::WFlags fl ) 00025 : QDialog( parent, fl ) 00026 { 00027 setupUi( this ); 00028 mAddAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionNewAttribute.png" ) ); 00029 mRemoveAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionDeleteAttribute.png" ) ); 00030 mTypeBox->addItem( tr( "Real" ), "Real" ); 00031 mTypeBox->addItem( tr( "Integer" ), "Integer" );; 00032 mTypeBox->addItem( tr( "String" ), "String" ); 00033 00034 mPointRadioButton->setChecked( true ); 00035 mFileFormatComboBox->addItem( "ESRI Shapefile" ); 00036 /*mFileFormatComboBox->addItem("Comma Separated Value"); 00037 mFileFormatComboBox->addItem("GML"); 00038 mFileFormatComboBox->addItem("Mapinfo File");*/ 00039 mOkButton = buttonBox->button( QDialogButtonBox::Ok ); 00040 mOkButton->setEnabled( false ); 00041 } 00042 00043 QgsGeomTypeDialog::~QgsGeomTypeDialog() 00044 { 00045 } 00046 00047 QGis::WkbType QgsGeomTypeDialog::selectedType() const 00048 { 00049 if ( mPointRadioButton->isChecked() ) 00050 { 00051 return QGis::WKBPoint; 00052 } 00053 else if ( mLineRadioButton->isChecked() ) 00054 { 00055 return QGis::WKBLineString; 00056 } 00057 else if ( mPolygonRadioButton->isChecked() ) 00058 { 00059 return QGis::WKBPolygon; 00060 } 00061 return QGis::WKBUnknown; 00062 } 00063 00064 void QgsGeomTypeDialog::on_mAddAttributeButton_clicked() 00065 { 00066 QString myName = mNameEdit->text(); 00067 //use userrole to avoid translated type string 00068 QString myType = mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toString(); 00069 mAttributeView->addTopLevelItem( new QTreeWidgetItem( QStringList() << myName << myType ) ); 00070 if ( mAttributeView->topLevelItemCount() > 0 ) 00071 { 00072 mOkButton->setEnabled( true ); 00073 } 00074 mNameEdit->clear(); 00075 } 00076 00077 void QgsGeomTypeDialog::on_mRemoveAttributeButton_clicked() 00078 { 00079 delete( mAttributeView->currentItem() ); 00080 if ( mAttributeView->topLevelItemCount() == 0 ) 00081 { 00082 mOkButton->setEnabled( false ); 00083 } 00084 } 00085 00086 void QgsGeomTypeDialog::on_buttonBox_helpRequested() 00087 { 00088 QgsContextHelp::run( context_id ); 00089 } 00090 00091 void QgsGeomTypeDialog::attributes( std::list<std::pair<QString, QString> >& at ) const 00092 { 00093 QTreeWidgetItemIterator it( mAttributeView ); 00094 while ( *it ) 00095 { 00096 QTreeWidgetItem *item = *it; 00097 at.push_back( std::make_pair( item->text( 0 ), item->text( 1 ) ) ); 00098 #ifdef QGISDEBUG 00099 qWarning(( "appending " + item->text( 0 ) + "//" + item->text( 1 ) ).toLocal8Bit().data() ); 00100 #endif 00101 ++it; 00102 } 00103 } 00104 00105 QString QgsGeomTypeDialog::selectedFileFormat() const 00106 { 00107 return mFileFormatComboBox->currentText(); 00108 }
1.5.1