22
22
#include < QListWidget>
23
23
#include < QMessageBox>
24
24
#include < QScrollBar>
25
- #include < QSettings>
26
25
#include < QStackedWidget>
27
26
#include < QSplitter>
28
27
#include < QTimer>
29
28
30
29
31
- QgsOptionsDialogBase::QgsOptionsDialogBase ( QString settingsKey, QWidget* parent, Qt::WFlags fl )
30
+ QgsOptionsDialogBase::QgsOptionsDialogBase ( QString settingsKey, QWidget* parent, Qt::WFlags fl, QSettings* settings )
32
31
: QDialog( parent, fl )
33
32
, mOptsKey( settingsKey )
34
33
, mInit( false )
35
34
, mDialogTitle( " " )
35
+ , mSettings( settings )
36
36
{
37
37
}
38
38
39
39
QgsOptionsDialogBase::~QgsOptionsDialogBase ()
40
40
{
41
41
if ( mInit )
42
42
{
43
- QSettings settings;
44
- settings.setValue ( QString ( " /Windows/%1/geometry" ).arg ( mOptsKey ), saveGeometry () );
45
- settings.setValue ( QString ( " /Windows/%1/splitState" ).arg ( mOptsKey ), mOptSplitter ->saveState () );
46
- settings.setValue ( QString ( " /Windows/%1/tab" ).arg ( mOptsKey ), mOptStackedWidget ->currentIndex () );
43
+ mSettings ->setValue ( QString ( " /Windows/%1/geometry" ).arg ( mOptsKey ), saveGeometry () );
44
+ mSettings ->setValue ( QString ( " /Windows/%1/splitState" ).arg ( mOptsKey ), mOptSplitter ->saveState () );
45
+ mSettings ->setValue ( QString ( " /Windows/%1/tab" ).arg ( mOptsKey ), mOptStackedWidget ->currentIndex () );
47
46
}
47
+
48
+ if ( mDelSettings ) // local settings obj to delete
49
+ {
50
+ delete mSettings ;
51
+ }
52
+
53
+ mSettings = 0 ; // null the pointer (in case of outside settings obj)
48
54
}
49
55
50
56
void QgsOptionsDialogBase::initOptionsBase ( bool restoreUi, QString title )
51
57
{
58
+ // use pointer to app QSettings if no custom QSettings specified
59
+ // custom QSettings object may be from Python plugin
60
+ mDelSettings = false ;
61
+
62
+ if ( !mSettings )
63
+ {
64
+ mSettings = new QSettings ();
65
+ mDelSettings = true ; // only delete obj created by class
66
+ }
67
+
52
68
// save dialog title so it can be used to be concatenated
53
69
// with category title in icon-only mode
54
70
if ( title.isEmpty () )
@@ -76,8 +92,7 @@ void QgsOptionsDialogBase::initOptionsBase( bool restoreUi, QString title )
76
92
return ;
77
93
}
78
94
79
- QSettings settings;
80
- int size = settings.value ( " /IconSize" , 24 ).toInt ();
95
+ int size = mSettings ->value ( " /IconSize" , 24 ).toInt ();
81
96
// buffer size to match displayed icon size in toolbars, and expected geometry restore
82
97
// newWidth (above) may need adjusted if you adjust iconBuffer here
83
98
int iconBuffer = 4 ;
@@ -115,6 +130,17 @@ void QgsOptionsDialogBase::initOptionsBase( bool restoreUi, QString title )
115
130
restoreOptionsBaseUi ( mDialogTitle );
116
131
}
117
132
133
+ void QgsOptionsDialogBase::setSettings ( QSettings* settings )
134
+ {
135
+ if ( mDelSettings ) // local settings obj to delete
136
+ {
137
+ delete mSettings ;
138
+ }
139
+
140
+ mSettings = settings;
141
+ mDelSettings = false ; // don't delete outside obj
142
+ }
143
+
118
144
void QgsOptionsDialogBase::restoreOptionsBaseUi ( QString title )
119
145
{
120
146
if ( !mInit )
@@ -131,14 +157,13 @@ void QgsOptionsDialogBase::restoreOptionsBaseUi( QString title )
131
157
// re-save original dialog title in case it was changed after dialog initialization
132
158
mDialogTitle = windowTitle ();
133
159
134
- QSettings settings;
135
- restoreGeometry ( settings.value ( QString ( " /Windows/%1/geometry" ).arg ( mOptsKey ) ).toByteArray () );
160
+ restoreGeometry ( mSettings ->value ( QString ( " /Windows/%1/geometry" ).arg ( mOptsKey ) ).toByteArray () );
136
161
// mOptListWidget width is fixed to take up less space in QtDesigner
137
162
// revert it now unless the splitter's state hasn't been saved yet
138
163
mOptListWidget ->setMaximumWidth (
139
- settings. value ( QString ( " /Windows/%1/splitState" ).arg ( mOptsKey ) ).isNull () ? 150 : 16777215 );
140
- mOptSplitter ->restoreState ( settings. value ( QString ( " /Windows/%1/splitState" ).arg ( mOptsKey ) ).toByteArray () );
141
- int curIndx = settings. value ( QString ( " /Windows/%1/tab" ).arg ( mOptsKey ), 0 ).toInt ();
164
+ mSettings -> value ( QString ( " /Windows/%1/splitState" ).arg ( mOptsKey ) ).isNull () ? 150 : 16777215 );
165
+ mOptSplitter ->restoreState ( mSettings -> value ( QString ( " /Windows/%1/splitState" ).arg ( mOptsKey ) ).toByteArray () );
166
+ int curIndx = mSettings -> value ( QString ( " /Windows/%1/tab" ).arg ( mOptsKey ), 0 ).toInt ();
142
167
143
168
// if the last used tab is out of range or not enabled display the first enabled one
144
169
if ( mOptStackedWidget ->count () < ( curIndx + 1 )
0 commit comments