1
/***************************************************************************
3
Set user options and preferences
6
copyright : (C) 2004 by Gary E.Sherman
7
email : sherman at mrcc.com
8
***************************************************************************/
10
/***************************************************************************
12
* This program is free software; you can redistribute it and/or modify *
13
* it under the terms of the GNU General Public License as published by *
14
* the Free Software Foundation; either version 2 of the License, or *
15
* (at your option) any later version. *
17
***************************************************************************/
18
/* $Id: qgsoptions.cpp 6251 2006-12-13 23:23:50Z telwertowski $ */
19
#include "qgsapplication.h"
20
#include "qgsoptions.h"
23
#include "qgslayerprojectionselector.h"
24
#include "qgsspatialrefsys.h"
26
#include <QFileDialog>
28
#include <QColorDialog>
36
* \class QgsOptions - Set user options and preferences
39
QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
43
connect(cmbTheme, SIGNAL(activated(const QString&)), this, SLOT(themeChanged(const QString&)));
44
connect(cmbTheme, SIGNAL(highlighted(const QString&)), this, SLOT(themeChanged(const QString&)));
45
connect(cmbTheme, SIGNAL(textChanged(const QString&)), this, SLOT(themeChanged(const QString&)));
46
connect(buttonOk, SIGNAL(clicked()), this, SLOT(saveOptions()));
47
connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
50
// read the current browser and set it
52
QString browser = settings.readEntry("/qgis/browser");
53
cmbBrowser->setCurrentText(browser);
55
std::cout << "Standard Identify radius setting: " << QGis::DEFAULT_IDENTIFY_RADIUS << std::endl;
57
double identifyValue = settings.value("/Map/identifyRadius",QGis::DEFAULT_IDENTIFY_RADIUS).toDouble();
59
std::cout << "Standard Identify radius setting read from settings file: " << identifyValue << std::endl;
61
spinBoxIdentifyValue->setValue(identifyValue);
63
// set the current theme
64
cmbTheme->setCurrentText(settings.readEntry("/Themes"));
65
// set the display update threshold
66
spinBoxUpdateThreshold->setValue(settings.readNumEntry("/Map/updateThreshold"));
67
//set the default projection behaviour radio buttongs
68
if (settings.readEntry("/Projections/defaultBehaviour")=="prompt")
70
radPromptForProjection->setChecked(true);
72
else if (settings.readEntry("/Projections/defaultBehaviour")=="useProject")
74
radUseProjectProjection->setChecked(true);
78
radUseGlobalProjection->setChecked(true);
80
mGlobalSRSID = settings.readNumEntry("/Projections/defaultProjectionSRSID",GEOSRS_ID);
81
//! @todo changes this control name in gui to txtGlobalProjString
82
QString myProjString = QgsSpatialRefSys::getProj4FromSrsId(mGlobalSRSID);
83
txtGlobalWKT->setText(myProjString);
85
// populate combo box with ellipsoids
87
QString myEllipsoidId = settings.readEntry("/qgis/measure/ellipsoid", "WGS84");
88
cmbEllipsoid->setCurrentText(getEllipsoidName(myEllipsoidId));
89
// add the themes to the combo box on the option dialog
90
QDir myThemeDir( QgsApplication::pkgDataPath()+"/themes/" );
91
myThemeDir.setFilter(QDir::Dirs);
92
QStringList myDirList = myThemeDir.entryList("*");
94
for(int i=0; i < myDirList.count(); i++)
96
if(myDirList[i] != "." && myDirList[i] != "..")
98
cmbTheme->insertItem(myDirList[i]);
102
// set the theme combo
103
cmbTheme->setCurrentText(settings.readEntry("/Themes","default"));
105
//set the state of the checkboxes
106
chkAntiAliasing->setChecked(settings.value("/qgis/enable_anti_aliasing",false).toBool());
108
// Slightly awkard here at the settings value is true to use QImage,
109
// but the checkbox is true to use QPixmap
110
chkUseQPixmap->setChecked(!(settings.value("/qgis/use_qimage_to_render", true).toBool()));
111
chkAddedVisibility->setChecked(settings.value("/qgis/new_layers_visible",true).toBool());
112
cbxHideSplash->setChecked(settings.value("/qgis/hideSplash",false).toBool());
114
//set the colour for selections
115
int myRed = settings.value("/qgis/default_selection_color_red",255).toInt();
116
int myGreen = settings.value("/qgis/default_selection_color_green",255).toInt();
117
int myBlue = settings.value("/qgis/default_selection_color_blue",0).toInt();
118
pbnSelectionColour->setColor( QColor(myRed,myGreen,myBlue) );
120
//set the default color for canvas background
121
myRed = settings.value("/qgis/default_canvas_color_red",255).toInt();
122
myGreen = settings.value("/qgis/default_canvas_color_green",255).toInt();
123
myBlue = settings.value("/qgis/default_canvas_color_blue",255).toInt();
124
pbnCanvasColor->setColor( QColor(myRed,myGreen,myBlue) );
126
capitaliseCheckBox->setChecked(settings.value("qgis/capitaliseLayerName", QVariant(false)).toBool());
128
cmbWheelAction->setCurrentIndex(settings.value("/qgis/wheel_action", 0).toInt());
129
spinZoomFactor->setValue(settings.value("/qgis/zoom_factor", 2).toDouble());
131
cbxSplitterRedraw->setChecked(settings.value("/qgis/splitterRedraw", QVariant(true)).toBool());
135
QgsOptions::~QgsOptions(){}
137
void QgsOptions::on_pbnSelectionColour_clicked()
139
QColor color = QColorDialog::getColor(pbnSelectionColour->color(), this);
142
pbnSelectionColour->setColor(color);
146
void QgsOptions::on_pbnCanvasColor_clicked()
148
QColor color = QColorDialog::getColor(pbnCanvasColor->color(), this);
151
pbnCanvasColor->setColor(color);
154
void QgsOptions::themeChanged(const QString &newThemeName)
156
// Slot to change the theme as user scrolls through the choices
157
QString newt = newThemeName;
158
((QgisApp*)qparent)->setTheme(newt);
160
QString QgsOptions::theme()
162
// returns the current theme (as selected in the cmbTheme combo box)
163
return cmbTheme->currentText();
166
void QgsOptions::saveOptions()
169
settings.writeEntry("/qgis/browser", cmbBrowser->currentText());
170
settings.writeEntry("/Map/identifyRadius", spinBoxIdentifyValue->value());
171
settings.writeEntry("/qgis/hideSplash",cbxHideSplash->isChecked());
172
settings.writeEntry("/qgis/new_layers_visible",chkAddedVisibility->isChecked());
173
settings.writeEntry("/qgis/enable_anti_aliasing",chkAntiAliasing->isChecked());
174
settings.writeEntry("/qgis/use_qimage_to_render", !(chkUseQPixmap->isChecked()));
175
settings.setValue("qgis/capitaliseLayerName", capitaliseCheckBox->isChecked());
177
if(cmbTheme->currentText().length() == 0)
179
settings.writeEntry("/Themes", "default");
181
settings.writeEntry("/Themes",cmbTheme->currentText());
183
settings.writeEntry("/Map/updateThreshold", spinBoxUpdateThreshold->value());
184
//check behaviour so default projection when new layer is added with no
185
//projection defined...
186
if (radPromptForProjection->isChecked())
189
settings.writeEntry("/Projections/defaultBehaviour", "prompt");
191
else if(radUseProjectProjection->isChecked())
194
settings.writeEntry("/Projections/defaultBehaviour", "useProject");
196
else //assumes radUseGlobalProjection is checked
199
settings.writeEntry("/Projections/defaultBehaviour", "useGlobal");
201
settings.writeEntry("/Projections/defaultProjectionSRSID",(int)mGlobalSRSID);
203
settings.writeEntry("/qgis/measure/ellipsoid", getEllipsoidAcronym(cmbEllipsoid->currentText()));
205
//set the colour for selections
206
QColor myColor = pbnSelectionColour->color();
207
int myRed = settings.writeEntry("/qgis/default_selection_color_red",myColor.red());
208
int myGreen = settings.writeEntry("/qgis/default_selection_color_green",myColor.green());
209
int myBlue = settings.writeEntry("/qgis/default_selection_color_blue",myColor.blue());
211
//set the default color for canvas background
212
myColor = pbnCanvasColor->color();
213
myRed = settings.writeEntry("/qgis/default_canvas_color_red",myColor.red());
214
myGreen = settings.writeEntry("/qgis/default_canvas_color_green",myColor.green());
215
myBlue = settings.writeEntry("/qgis/default_canvas_color_blue",myColor.blue());
217
settings.writeEntry("/qgis/wheel_action", cmbWheelAction->currentIndex());
218
settings.writeEntry("/qgis/zoom_factor", spinZoomFactor->value());
220
settings.setValue("/qgis/splitterRedraw", cbxSplitterRedraw->isChecked());
232
void QgsOptions::on_btnFindBrowser_clicked()
236
filter = "Applications (*.exe)";
238
filter = "All Files (*)";
240
QString browser = QFileDialog::getOpenFileName(
245
if(browser.length() > 0)
247
cmbBrowser->setCurrentText(browser);
252
void QgsOptions::on_pbnSelectProjection_clicked()
255
QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector(this);
256
mySelector->setSelectedSRSID(mGlobalSRSID);
257
if(mySelector->exec())
260
std::cout << "------ Global Default Projection Selection Set ----------" << std::endl;
262
mGlobalSRSID = mySelector->getCurrentSRSID();
263
//! @todo changes this control name in gui to txtGlobalProjString
264
txtGlobalWKT->setText(mySelector->getCurrentProj4String());
266
std::cout << "------ Global Default Projection now set to ----------\n" << mGlobalSRSID << std::endl;
272
std::cout << "------ Global Default Projection Selection change cancelled ----------" << std::endl;
274
QApplication::restoreOverrideCursor();
279
void QgsOptions::on_chkAntiAliasing_stateChanged()
281
// We can't have the anti-aliasing turned on when QPixmap is being
282
// used (we we can. but it then doesn't do anti-aliasing, and this
283
// will confuse people).
284
if (chkAntiAliasing->isChecked())
285
chkUseQPixmap->setChecked(false);
289
void QgsOptions::on_chkUseQPixmap_stateChanged()
291
// We can't have the anti-aliasing turned on when QPixmap is being
292
// used (we we can. but it then doesn't do anti-aliasing, and this
293
// will confuse people).
294
if (chkUseQPixmap->isChecked())
295
chkAntiAliasing->setChecked(false);
299
// Return state of the visibility flag for newly added layers. If
301
bool QgsOptions::newVisible()
303
return chkAddedVisibility->isChecked();
306
void QgsOptions::getEllipsoidList()
308
// (copied from qgscustomprojectiondialog.cpp)
311
// Populate the ellipsoid combo
315
sqlite3_stmt *myPreparedStatement;
317
//check the db is available
318
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
321
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
322
// XXX This will likely never happen since on open, sqlite creates the
323
// database if it does not exist.
324
assert(myResult == 0);
327
// Set up the query to retreive the projection information needed to populate the ELLIPSOID list
328
QString mySql = "select * from tbl_ellipsoid order by name";
329
myResult = sqlite3_prepare(myDatabase, (const char *)mySql, mySql.length(), &myPreparedStatement, &myTail);
330
// XXX Need to free memory from the error msg if one is set
331
if(myResult == SQLITE_OK)
333
while(sqlite3_step(myPreparedStatement) == SQLITE_ROW)
335
cmbEllipsoid->insertItem((char *)sqlite3_column_text(myPreparedStatement,1));
338
// close the sqlite3 statement
339
sqlite3_finalize(myPreparedStatement);
340
sqlite3_close(myDatabase);
343
QString QgsOptions::getEllipsoidAcronym(QString theEllipsoidName)
347
sqlite3_stmt *myPreparedStatement;
350
//check the db is available
351
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
354
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
355
// XXX This will likely never happen since on open, sqlite creates the
356
// database if it does not exist.
357
assert(myResult == 0);
359
// Set up the query to retreive the projection information needed to populate the ELLIPSOID list
360
QString mySql = "select acronym from tbl_ellipsoid where name='" + theEllipsoidName + "'";
361
myResult = sqlite3_prepare(myDatabase, (const char *)mySql, mySql.length(), &myPreparedStatement, &myTail);
362
// XXX Need to free memory from the error msg if one is set
363
if(myResult == SQLITE_OK)
365
sqlite3_step(myPreparedStatement) == SQLITE_ROW;
366
myName = QString((char *)sqlite3_column_text(myPreparedStatement,0));
368
// close the sqlite3 statement
369
sqlite3_finalize(myPreparedStatement);
370
sqlite3_close(myDatabase);
375
QString QgsOptions::getEllipsoidName(QString theEllipsoidAcronym)
379
sqlite3_stmt *myPreparedStatement;
382
//check the db is available
383
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath(), &myDatabase);
386
std::cout << "Can't open database: " << sqlite3_errmsg(myDatabase) << std::endl;
387
// XXX This will likely never happen since on open, sqlite creates the
388
// database if it does not exist.
389
assert(myResult == 0);
391
// Set up the query to retreive the projection information needed to populate the ELLIPSOID list
392
QString mySql = "select name from tbl_ellipsoid where acronym='" + theEllipsoidAcronym + "'";
393
myResult = sqlite3_prepare(myDatabase, (const char *)mySql, mySql.length(), &myPreparedStatement, &myTail);
394
// XXX Need to free memory from the error msg if one is set
395
if(myResult == SQLITE_OK)
397
sqlite3_step(myPreparedStatement) == SQLITE_ROW;
398
myName = QString((char *)sqlite3_column_text(myPreparedStatement,0));
400
// close the sqlite3 statement
401
sqlite3_finalize(myPreparedStatement);
402
sqlite3_close(myDatabase);