1
/***************************************************************************
2
qgsnewvectorlayerdialog.cpp - description
5
copyright : (C) 2004 by Marco Hugentobler
6
email : marco.hugentobler@autoform.ch
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
19
#include "qgsnewvectorlayerdialog.h"
20
#include "qgsapplication.h"
21
#include "qgisapp.h" // <- for theme icons
22
#include "qgslogger.h"
23
#include "qgscoordinatereferencesystem.h"
24
#include "qgsgenericprojectionselector.h"
25
#include <QPushButton>
28
QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WFlags fl )
29
: QDialog( parent, fl )
32
mAddAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionNewAttribute.png" ) );
33
mRemoveAttributeButton->setIcon( QgisApp::getThemeIcon( "/mActionDeleteAttribute.png" ) );
34
mTypeBox->addItem( tr( "Text data" ), "String" );
35
mTypeBox->addItem( tr( "Whole number" ), "Integer" );
36
mTypeBox->addItem( tr( "Decimal number" ), "Real" );
38
mWidth->setValidator( new QIntValidator( 1, 255, this ) );
39
mPrecision->setValidator( new QIntValidator( 0, 5, this ) );
41
mPointRadioButton->setChecked( true );
42
mFileFormatComboBox->addItem( tr( "ESRI Shapefile" ), "ESRI Shapefile" );
43
/* Disabled until provider properly supports editing the created file formats */
44
//mFileFormatComboBox->addItem( tr( "Comma Separated Value" ), "Comma Separated Value" );
45
//mFileFormatComboBox->addItem(tr( "GML"), "GML" );
46
//mFileFormatComboBox->addItem(tr( "Mapinfo File" ), "Mapinfo File" );
47
if ( mFileFormatComboBox->count() == 1 )
49
mFileFormatComboBox->setVisible( false );
50
mFileFormatLabel->setVisible( false );
52
mOkButton = buttonBox->button( QDialogButtonBox::Ok );
53
mOkButton->setEnabled( false );
55
QgsCoordinateReferenceSystem srs;
59
leSpatialRefSys->setText( srs.toProj4() );
62
QgsNewVectorLayerDialog::~QgsNewVectorLayerDialog()
66
void QgsNewVectorLayerDialog::on_mTypeBox_currentIndexChanged( int index )
68
// FIXME: sync with providers/ogr/qgsogrprovider.cpp
72
mWidth->setValidator( new QIntValidator( 1, 255, this ) );
73
mPrecision->setEnabled( false );
76
case 1: // Whole number
77
if ( mWidth->text().toInt() > 10 )
78
mWidth->setText( "10" );
79
mPrecision->setEnabled( false );
80
mWidth->setValidator( new QIntValidator( 1, 10, this ) );
83
case 2: // Decimal number
84
if ( mWidth->text().toInt() > 20 )
85
mWidth->setText( "20" );
86
mPrecision->setEnabled( false );
87
mWidth->setValidator( new QIntValidator( 1, 20, this ) );
88
mPrecision->setEnabled( true );
92
QgsDebugMsg( "unexpected index" );
97
QGis::WkbType QgsNewVectorLayerDialog::selectedType() const
99
if ( mPointRadioButton->isChecked() )
101
return QGis::WKBPoint;
103
else if ( mLineRadioButton->isChecked() )
105
return QGis::WKBLineString;
107
else if ( mPolygonRadioButton->isChecked() )
109
return QGis::WKBPolygon;
111
return QGis::WKBUnknown;
114
int QgsNewVectorLayerDialog::selectedCrsId() const
119
void QgsNewVectorLayerDialog::on_mAddAttributeButton_clicked()
121
QString myName = mNameEdit->text();
122
QString myWidth = mWidth->text();
123
QString myPrecision = mPrecision->text();
124
//use userrole to avoid translated type string
125
QString myType = mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toString();
126
mAttributeView->addTopLevelItem( new QTreeWidgetItem( QStringList() << myName << myType << myWidth << myPrecision ) );
127
if ( mAttributeView->topLevelItemCount() > 0 )
129
mOkButton->setEnabled( true );
134
void QgsNewVectorLayerDialog::on_mRemoveAttributeButton_clicked()
136
delete( mAttributeView->currentItem() );
137
if ( mAttributeView->topLevelItemCount() == 0 )
139
mOkButton->setEnabled( false );
143
void QgsNewVectorLayerDialog::on_pbnChangeSpatialRefSys_clicked()
145
QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this );
146
mySelector->setMessage();
147
mySelector->setSelectedCrsId( pbnChangeSpatialRefSys->text().toInt() );
148
if ( mySelector->exec() )
150
mCrsId = mySelector->selectedCrsId();
151
leSpatialRefSys->setText( mySelector->selectedProj4String() );
155
QApplication::restoreOverrideCursor();
160
void QgsNewVectorLayerDialog::attributes( std::list<std::pair<QString, QString> >& at ) const
162
QTreeWidgetItemIterator it( mAttributeView );
165
QTreeWidgetItem *item = *it;
166
QString type = QString( "%1;%2;%3" ).arg( item->text( 1 ) ).arg( item->text( 2 ) ).arg( item->text( 3 ) );
167
at.push_back( std::make_pair( item->text( 0 ), type ) );
168
QgsDebugMsg( QString( "appending %1//%2" ).arg( item->text( 0 ) ).arg( type ) );
173
QString QgsNewVectorLayerDialog::selectedFileFormat() const
175
//use userrole to avoid translated type string
176
QString myType = mFileFormatComboBox->itemData( mFileFormatComboBox->currentIndex(), Qt::UserRole ).toString();