QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsencodingfiledialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsencodingfiledialog.cpp - File dialog which queries the encoding type
3  --------------------------------------
4  Date : 16-Feb-2005
5  Copyright : (C) 2005 by Marco Hugentobler
6  email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsencodingfiledialog.h"
17 #include "qgsproject.h"
18 #include "qgslogger.h"
19 #include "qgsvectordataprovider.h"
20 
21 #include <QSettings>
22 #include <QComboBox>
23 #include <QPushButton>
24 #include <QLabel>
25 #include <QLayout>
26 #include <QTextCodec>
27 
29  const QString & caption, const QString & directory,
30  const QString & filter, const QString & encoding )
31  : QFileDialog( parent, caption, directory, filter )
32 {
33  mCancelAll = false;
34  mCancelAllButton = 0;
35  mEncodingComboBox = new QComboBox( this );
36  QLabel* l = new QLabel( tr( "Encoding:" ), this );
37  layout()->addWidget( l );
38  layout()->addWidget( mEncodingComboBox );
39 
41 
42  // Use default encoding if none supplied
43  QString enc = encoding;
44  if ( encoding.isEmpty() )
45  {
46  QSettings settings;
47  enc = settings.value( "/UI/encoding", "System" ).toString();
48  }
49 
50  // The specified decoding is added if not existing alread, and then set current.
51  // This should select it.
52  int encindex = mEncodingComboBox->findText( enc );
53  if ( encindex < 0 )
54  {
55  mEncodingComboBox->insertItem( 0, enc );
56  encindex = 0;
57  }
58  mEncodingComboBox->setCurrentIndex( encindex );
59 
60  // if this dialog is being invoked from QgisApp::findFiles_(), then we
61  // need to force selection of the first filter since that corresponds to
62  // the file name we're looking for; even if we're not here from
63  // findFiles_(), it won't hurt to force selection of the first file filter
64  selectFilter( filters().at( 0 ) );
65 
66  // Connect our slot to get a signal when the user is done with the file dialog
67  connect( this, SIGNAL( accepted() ), this, SLOT( saveUsedEncoding() ) );
68 
69 
70 }
71 
73 {
74 
75 }
76 
78 {
79  return mEncodingComboBox->currentText();
80 }
81 
83 {
84  QSettings settings;
85  settings.setValue( "/UI/encoding", encoding() );
86  QgsDebugMsg( QString( "Set encoding " + encoding() + " as default." ) );
87 }
88 
90 {
91  if ( ! mCancelAllButton )
92  {
93  mCancelAllButton = new QPushButton( tr( "Cancel &All" ), NULL );
94  layout()->addWidget( mCancelAllButton ); // Ownership transfered, no need to delete later on
95  connect( mCancelAllButton, SIGNAL( clicked() ), this, SLOT( pbnCancelAll_clicked() ) );
96  }
97 }
98 
100 {
101  return mCancelAll;
102 }
103 
105 {
106  mCancelAll = true;
107  // Now, continue as the user clicked the cancel button
108  reject();
109 }