1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
11 | **
|
---|
12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
13 | ** modification, are permitted provided that the following conditions are
|
---|
14 | ** met:
|
---|
15 | ** * Redistributions of source code must retain the above copyright
|
---|
16 | ** notice, this list of conditions and the following disclaimer.
|
---|
17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
18 | ** notice, this list of conditions and the following disclaimer in
|
---|
19 | ** the documentation and/or other materials provided with the
|
---|
20 | ** distribution.
|
---|
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
22 | ** the names of its contributors may be used to endorse or promote
|
---|
23 | ** products derived from this software without specific prior written
|
---|
24 | ** permission.
|
---|
25 | **
|
---|
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
37 | ** $QT_END_LICENSE$
|
---|
38 | **
|
---|
39 | ****************************************************************************/
|
---|
40 |
|
---|
41 | #include <QtGui>
|
---|
42 |
|
---|
43 | QWidget *win;
|
---|
44 | QWidget *panel;
|
---|
45 |
|
---|
46 | void snippet_ctor1()
|
---|
47 | {
|
---|
48 | //! [0]
|
---|
49 | QSettings settings("MySoft", "Star Runner");
|
---|
50 | //! [0]
|
---|
51 | }
|
---|
52 |
|
---|
53 | void snippet_ctor2()
|
---|
54 | {
|
---|
55 | //! [1]
|
---|
56 | QCoreApplication::setOrganizationName("MySoft");
|
---|
57 | //! [1] //! [2]
|
---|
58 | QCoreApplication::setOrganizationDomain("mysoft.com");
|
---|
59 | //! [2] //! [3]
|
---|
60 | QCoreApplication::setApplicationName("Star Runner");
|
---|
61 | //! [3]
|
---|
62 |
|
---|
63 | //! [4]
|
---|
64 | QSettings settings;
|
---|
65 | //! [4]
|
---|
66 |
|
---|
67 | //! [5]
|
---|
68 | settings.setValue("editor/wrapMargin", 68);
|
---|
69 | //! [5] //! [6]
|
---|
70 | int margin = settings.value("editor/wrapMargin").toInt();
|
---|
71 | //! [6]
|
---|
72 | {
|
---|
73 | //! [7]
|
---|
74 | int margin = settings.value("editor/wrapMargin", 80).toInt();
|
---|
75 | //! [7]
|
---|
76 | }
|
---|
77 |
|
---|
78 | //! [8]
|
---|
79 | settings.setValue("mainwindow/size", win->size());
|
---|
80 | //! [8] //! [9]
|
---|
81 | settings.setValue("mainwindow/fullScreen", win->isFullScreen());
|
---|
82 | //! [9] //! [10]
|
---|
83 | settings.setValue("outputpanel/visible", panel->isVisible());
|
---|
84 | //! [10]
|
---|
85 |
|
---|
86 | //! [11]
|
---|
87 | settings.beginGroup("mainwindow");
|
---|
88 | settings.setValue("size", win->size());
|
---|
89 | settings.setValue("fullScreen", win->isFullScreen());
|
---|
90 | settings.endGroup();
|
---|
91 | //! [11]
|
---|
92 |
|
---|
93 | //! [12]
|
---|
94 | settings.beginGroup("outputpanel");
|
---|
95 | settings.setValue("visible", panel->isVisible());
|
---|
96 | settings.endGroup();
|
---|
97 | //! [12]
|
---|
98 | }
|
---|
99 |
|
---|
100 | void snippet_locations()
|
---|
101 | {
|
---|
102 | //! [13]
|
---|
103 | QSettings obj1("MySoft", "Star Runner");
|
---|
104 | //! [13] //! [14]
|
---|
105 | QSettings obj2("MySoft");
|
---|
106 | QSettings obj3(QSettings::SystemScope, "MySoft", "Star Runner");
|
---|
107 | QSettings obj4(QSettings::SystemScope, "MySoft");
|
---|
108 | //! [14]
|
---|
109 |
|
---|
110 | {
|
---|
111 | //! [15]
|
---|
112 | QSettings settings(QSettings::IniFormat, QSettings::UserScope,
|
---|
113 | "MySoft", "Star Runner");
|
---|
114 | //! [15]
|
---|
115 | }
|
---|
116 |
|
---|
117 | {
|
---|
118 | QSettings settings("starrunner.ini", QSettings::IniFormat);
|
---|
119 | }
|
---|
120 |
|
---|
121 | {
|
---|
122 | QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft",
|
---|
123 | QSettings::NativeFormat);
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | class MainWindow : public QMainWindow
|
---|
128 | {
|
---|
129 | public:
|
---|
130 | MainWindow();
|
---|
131 |
|
---|
132 | void writeSettings();
|
---|
133 | void readSettings();
|
---|
134 |
|
---|
135 | protected:
|
---|
136 | void closeEvent(QCloseEvent *event);
|
---|
137 | };
|
---|
138 |
|
---|
139 | //! [16]
|
---|
140 | void MainWindow::writeSettings()
|
---|
141 | {
|
---|
142 | QSettings settings("Moose Soft", "Clipper");
|
---|
143 |
|
---|
144 | settings.beginGroup("MainWindow");
|
---|
145 | settings.setValue("size", size());
|
---|
146 | settings.setValue("pos", pos());
|
---|
147 | settings.endGroup();
|
---|
148 | }
|
---|
149 | //! [16]
|
---|
150 |
|
---|
151 | //! [17]
|
---|
152 | void MainWindow::readSettings()
|
---|
153 | {
|
---|
154 | QSettings settings("Moose Soft", "Clipper");
|
---|
155 |
|
---|
156 | settings.beginGroup("MainWindow");
|
---|
157 | resize(settings.value("size", QSize(400, 400)).toSize());
|
---|
158 | move(settings.value("pos", QPoint(200, 200)).toPoint());
|
---|
159 | settings.endGroup();
|
---|
160 | }
|
---|
161 | //! [17]
|
---|
162 |
|
---|
163 | //! [18]
|
---|
164 | MainWindow::MainWindow()
|
---|
165 | {
|
---|
166 | //! [18] //! [19]
|
---|
167 | readSettings();
|
---|
168 | //! [19] //! [20]
|
---|
169 | }
|
---|
170 | //! [20]
|
---|
171 |
|
---|
172 | bool userReallyWantsToQuit() { return true; }
|
---|
173 |
|
---|
174 | //! [21]
|
---|
175 | void MainWindow::closeEvent(QCloseEvent *event)
|
---|
176 | {
|
---|
177 | if (userReallyWantsToQuit()) {
|
---|
178 | writeSettings();
|
---|
179 | event->accept();
|
---|
180 | } else {
|
---|
181 | event->ignore();
|
---|
182 | }
|
---|
183 | }
|
---|
184 | //! [21]
|
---|