~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/app/qgsnewvectorlayerdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                         qgsnewvectorlayerdialog.cpp  -  description
 
3
                             -------------------
 
4
    begin                : October 2004
 
5
    copyright            : (C) 2004 by Marco Hugentobler
 
6
    email                : marco.hugentobler@autoform.ch
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
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.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
/* $Id$ */
 
18
 
 
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>
 
26
 
 
27
 
 
28
QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WFlags fl )
 
29
    : QDialog( parent, fl )
 
30
{
 
31
  setupUi( this );
 
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" );
 
37
 
 
38
  mWidth->setValidator( new QIntValidator( 1, 255, this ) );
 
39
  mPrecision->setValidator( new QIntValidator( 0, 5, this ) );
 
40
 
 
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 )
 
48
  {
 
49
    mFileFormatComboBox->setVisible( false );
 
50
    mFileFormatLabel->setVisible( false );
 
51
  }
 
52
  mOkButton = buttonBox->button( QDialogButtonBox::Ok );
 
53
  mOkButton->setEnabled( false );
 
54
 
 
55
  QgsCoordinateReferenceSystem srs;
 
56
  srs.validate();
 
57
 
 
58
  mCrsId = srs.srsid();
 
59
  leSpatialRefSys->setText( srs.toProj4() );
 
60
}
 
61
 
 
62
QgsNewVectorLayerDialog::~QgsNewVectorLayerDialog()
 
63
{
 
64
}
 
65
 
 
66
void QgsNewVectorLayerDialog::on_mTypeBox_currentIndexChanged( int index )
 
67
{
 
68
  // FIXME: sync with providers/ogr/qgsogrprovider.cpp
 
69
  switch ( index )
 
70
  {
 
71
    case 0: // Text data
 
72
      mWidth->setValidator( new QIntValidator( 1, 255, this ) );
 
73
      mPrecision->setEnabled( false );
 
74
      break;
 
75
 
 
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 ) );
 
81
      break;
 
82
 
 
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 );
 
89
      break;
 
90
 
 
91
    default:
 
92
      QgsDebugMsg( "unexpected index" );
 
93
      break;
 
94
  }
 
95
}
 
96
 
 
97
QGis::WkbType QgsNewVectorLayerDialog::selectedType() const
 
98
{
 
99
  if ( mPointRadioButton->isChecked() )
 
100
  {
 
101
    return QGis::WKBPoint;
 
102
  }
 
103
  else if ( mLineRadioButton->isChecked() )
 
104
  {
 
105
    return QGis::WKBLineString;
 
106
  }
 
107
  else if ( mPolygonRadioButton->isChecked() )
 
108
  {
 
109
    return QGis::WKBPolygon;
 
110
  }
 
111
  return QGis::WKBUnknown;
 
112
}
 
113
 
 
114
int QgsNewVectorLayerDialog::selectedCrsId() const
 
115
{
 
116
  return mCrsId;
 
117
}
 
118
 
 
119
void QgsNewVectorLayerDialog::on_mAddAttributeButton_clicked()
 
120
{
 
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 )
 
128
  {
 
129
    mOkButton->setEnabled( true );
 
130
  }
 
131
  mNameEdit->clear();
 
132
}
 
133
 
 
134
void QgsNewVectorLayerDialog::on_mRemoveAttributeButton_clicked()
 
135
{
 
136
  delete( mAttributeView->currentItem() );
 
137
  if ( mAttributeView->topLevelItemCount() == 0 )
 
138
  {
 
139
    mOkButton->setEnabled( false );
 
140
  }
 
141
}
 
142
 
 
143
void QgsNewVectorLayerDialog::on_pbnChangeSpatialRefSys_clicked()
 
144
{
 
145
  QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this );
 
146
  mySelector->setMessage();
 
147
  mySelector->setSelectedCrsId( pbnChangeSpatialRefSys->text().toInt() );
 
148
  if ( mySelector->exec() )
 
149
  {
 
150
    mCrsId = mySelector->selectedCrsId();
 
151
    leSpatialRefSys->setText( mySelector->selectedProj4String() );
 
152
  }
 
153
  else
 
154
  {
 
155
    QApplication::restoreOverrideCursor();
 
156
  }
 
157
  delete mySelector;
 
158
}
 
159
 
 
160
void QgsNewVectorLayerDialog::attributes( std::list<std::pair<QString, QString> >& at ) const
 
161
{
 
162
  QTreeWidgetItemIterator it( mAttributeView );
 
163
  while ( *it )
 
164
  {
 
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 ) );
 
169
    ++it;
 
170
  }
 
171
}
 
172
 
 
173
QString QgsNewVectorLayerDialog::selectedFileFormat() const
 
174
{
 
175
  //use userrole to avoid translated type string
 
176
  QString myType = mFileFormatComboBox->itemData( mFileFormatComboBox->currentIndex(), Qt::UserRole ).toString();
 
177
  return myType;
 
178
}