-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] QgsSettings QGIS QSettings replacement #4160
Conversation
5f4633c
to
c1f8ea9
Compare
} | ||
if ( globalsettingsfile.isEmpty( ) ) | ||
{ | ||
QString default_globalsettingsfile = QgsApplication::pkgDataPath( ) + "/qgis_global_settings.ini"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might change this if this is ok based on the QEP. It will just look in a QgsApplication::pkgDataPath()/gloabl/QGIS/QGIS.ini
file. As per the QEP just makes it easier and allows use to include other things in the "global config" as it's just a copy of a user config but in the install folder. e.g we might want to include extra plugins, symbols, etc in there so we can setup a user config and then copy to install folder.
Leave for now though and I will rework with my QEP work this week.
@elpaso this looks really great. I will pull down and test this week. I think I will end up moving most of the settings loading logic that is found in main.cpp into a static method on QgsSettings in order to make it easier to find. The user config stuff will also live in there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Posted a couple of small code fixes.
Something I'm wondering- could we have an instance of this attached to QgsApplication? There's various parts of code which would benefit from being able to connect to a "changed" signal from the qsettings. At the moment this code relies on ugly "something->emitChanged()" type workarounds. It'd be much cleaner if this could be avoided and that code could just connect to a QgsApplication::settings changed signal.
src/core/qgssettings.h
Outdated
* called application from the organization called organization, and with parent parent. | ||
*/ | ||
explicit QgsSettings( const QString &organization, | ||
const QString &application = QString(), QObject *parent = 0 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 -> nullptr
src/core/qgssettings.h
Outdated
|
||
void init( ); | ||
QString sanitizeKey( QString key ) const; | ||
QSettings* mGlobalSettings; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please initialize pointer variables at declaration - see d19e707
src/core/qgssettings.h
Outdated
QString sanitizeKey( QString key ) const; | ||
QSettings* mGlobalSettings; | ||
static QString sGlobalSettingsPath; | ||
bool mUsingGlobalArray; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto with bools - safer to initialize here (c++11 style)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I like very much the idea. +1 on @nyalldawson 's idea for signals, I wanted to have something like that for a while. Going further, what do you think about adding project settings to it so we would have signals for them too. |
@nyalldawson , @m-kuhn travis is apparently failing on unrelated tests (I restarted the build but it's now failing on another test, Travis sometimes really looks like a good candidate for a slow entropy generator 😄 ), can you please have a look? https://travis-ci.org/qgis/QGIS/builds/203345828#L1481
I also like the idea, but in this case it would not be a drop-in Are you thinking to emit the signal whenever a BTW, I feel that maybe worth leaving |
@elpaso instead of inheriting QSettings, you can just use a private member. That would allow:
|
I was a bit fast on the merge button and fixed it 20 minutes later, you probably just caught a very bad time. Rebase and push ;) |
@elpaso @nyalldawson and I talked about this and it will still work with the current model. QSetings is a QObject. So we can just assign the settings object that we make in main to QgsApplication. If someone needs to listen to signals they can do
if they don't care and just want to read values you can just do
both work here and |
8a3892d
to
72cf11f
Compare
@3nids we can always override |
AFAIK |
@m-kuhn you are correct, but I don't see the problem here. Calling |
True, sounds like it's fine in this scenario here. |
Ok to merge? |
I just don't see any advantage of inheritance, only drawbacks. |
@3nids emit the signal in setValue() and connect to it via |
but you cannot override And again, is there any advantage of inheritance? I'm just seeing a constraint for the future. |
@3nids See my previous comment: #4160 (comment) |
@3nids thinking about it now I'm considering the same thing. And some google searching has turned up the same things, better to just wrap QSettings and not inherit. Would that break anything @elpaso? I think the main thing was that you would then have to use @elpaso I'm happy to take this work on if you can't. We will have to do a blank replace though out the code base but that is OK. |
It should be mainly just having the same methods as QSettings and then just forwarding the calls though right? |
@NathanW2 yep! |
@NathanW2 I still don't see a valid reason for doing it. But there are also no particular reasons for not doing it, beside that it's more complicated that it could be, and I tend to prefer simpler solutions.
Yes, that's it. I can do the implementation. |
@elpaso I think it will be easier to go from composition to inheritance later on rather than the other way. So if you are happy to make the change now that would be cool. My offer is still open if you need a hand. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be also in favor of composition - always a safer option especially if the class is not explicitly designed to be inherited (i.e. having virtual methods)
I am also wondering if we could combine QgsSettings with QgsProject somehow - in QgsProject we have those project properties that try to work the same way as QSettings, just on project level...
It seems that the global settings file is always newly opened and parsed - I think we should probably cache the global settings to avoid this extra overhead every time QgsSettings is used.
Could we make the API leaner by avoiding the use of getters/setters like guiValue(), setGuiValue() ? It seems to me that the concept of sections is not necessary if there is already support for groups in the API? In case we need some shortcuts for often used groups, why not just using constructor like this: QgsSettings s(QgsSettings.Server);
(where QgsSettings.Server
would be a string literal)
@NathanW2 do you think the signal @wonder-sk I'm already refactoring to a composition. |
src/core/qgssettings.h
Outdated
//! Removes the setting key and any sub-settings of key. | ||
void remove( const QString &key ); | ||
//! Overloaded getter that accepts an additional Section argument | ||
QVariant sectionValue( const QString &key, const Section section, const QVariant &defaultValue = QVariant() ) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not create a new method here, but rather use value and setValue overloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip, I'll add the Section
as an optional last argument to value getter/setter.
Thanks a lot for this @elpaso it will bring new opportunities! |
@elpaso once you have removed |
@elpaso thanks again for changing the design based on feedback. |
This is the new QgsSettings class that adds an (optional) Global Settings additional ini file where a system administrator can store default values for the settings and provide pre-configuration. If an ini file named qgis_global_settings.ini is found in the pkgDataPath directory it is automatically loaded, this path can be overriden by a command line argument ( --globalsettingsfile path ) and through an environment variable (QGIS_GLOBAL_SETTINGS_FILE). For now, the new class is used in main.cpp and WMS configuration (for testing and demonstration). When this PR will be merged, the new QgsSettings class will be applied to all QGIS code base.
... and 0 -> nullptr
f7f1316
to
3aaceac
Compare
Travis was passing unsure why GitHub was saying otherwise. Thanks to all for the review and feedback and @elpaso for all the work. |
I don't suspect so but unsure. It's working fine on my machine at the
moment.
…On Thu, Feb 23, 2017 at 8:21 PM, Mathieu Pellerin ***@***.***> wrote:
@elpaso <https://github.com/elpaso> , @NathanW2
<https://github.com/NathanW2> , on my machine, the QGIS startup tips
window keep showing up, even though I check the [x] I've had enough --
could this PR have caused this regression?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4160 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAXS3E3TxwVQ1FcfbOhVqHp7E6ewGVppks5rfV2pgaJpZM4MFLR4>
.
|
@nirvn I'll have a look |
@nirvn @NathanW2 , yes it is a (temporary) regression: the new I'm hesitant to do it now, we should first decide if we want to implement @nyalldawson proposal of a |
You can leave it for now. I am reworking the loading order etc of the
settings and will add it to QgsApplication as part of my QEP work or maybe
before.
…On Thu, Feb 23, 2017 at 10:42 PM, Alessandro Pasotti < ***@***.***> wrote:
@nirvn <https://github.com/nirvn> @NathanW2 <https://github.com/NathanW2>
, yes it is a (temporary) regression: the new QgsSettings keys are *not*
case sensititive, but QgsSettings is not yet used in all QGIS code, this
means that when all QSettings istances will be replaced by QgsSettings
this issue will go away.
There will be other issues like this until the migration from QSettings
to QgsSettings will be completed.
I'm hesitant to do it now, we should first decide if we want to implement
@nyalldawson <https://github.com/nyalldawson> proposal of a QgsSettings
QgsApplication()::settings() implementation (that looks good to me) or if
choose a plain search and replace from QSettings to QgsSettings.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4160 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAXS3AL8aHvbOF_Hcq_W7-OhHIxS846Gks5rfX7BgaJpZM4MFLR4>
.
|
@elpaso , @NathanW2 , here's another QgsSettings regression (which crashes QGIS): http://hub.qgis.org/issues/16233 Also, adding a WM(T)S layer fails now with the following error message: The welcome tips regression wasn't that serious, but this is rather more consequential 😄 , should we temporarily revert? |
One more: http://hub.qgis.org/issues/16234 -- here, an option setting (icon size) appears to be properly written, but not read upon QGIS launch. |
|
||
void QgsSettings::remove( const QString &key ) | ||
{ | ||
mGlobalSettings->remove( key ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nirvn there will be more: every time a mixed/upper case key is created by QSettings and read through QgsSettings. As I said the problem is temporary and will go away when QsgSettings will be used to write and read the settings. As a temporary solution, you can revert the QgsSettings use in WMS classes (that is the one I used to show off the class usage), and in qgisapp.cpp. Regarding http://hub.qgis.org/issues/16233 , see my comment here https://github.com/qgis/QGIS/pull/4160/files#r103233230 |
* [feature] QgsSettings QGIS QSettings replacement This is the new QgsSettings class that adds an (optional) Global Settings additional ini file where a system administrator can store default values for the settings and provide pre-configuration. If an ini file named qgis_global_settings.ini is found in the pkgDataPath directory it is automatically loaded, this path can be overriden by a command line argument ( --globalsettingsfile path ) and through an environment variable (QGIS_GLOBAL_SETTINGS_FILE). Cherry pick from e1ede70
* [feature] QgsSettings QGIS QSettings replacement (qgis#4160) This is the new QgsSettings class that adds an (optional) Global Settings additional ini file where a system administrator can store default values for the settings and provide pre-configuration. If an ini file named qgis_global_settings.ini is found in the pkgDataPath directory it is automatically loaded, this path can be overriden by a command line argument ( --globalsettingsfile path ) and through an environment variable (QGIS_GLOBAL_SETTINGS_FILE). Cherry pick from e1ede70, plus commits from Jurgen Fischer and Mathieu Pellerin
* [feature] QgsSettings QGIS QSettings replacement (qgis#4160) This is the new QgsSettings class that adds an (optional) Global Settings additional ini file where a system administrator can store default values for the settings and provide pre-configuration. If an ini file named qgis_global_settings.ini is found in the pkgDataPath directory it is automatically loaded, this path can be overriden by a command line argument ( --globalsettingsfile path ) and through an environment variable (QGIS_GLOBAL_SETTINGS_FILE). Cherry pick from e1ede70, plus commits from Jurgen Fischer and Mathieu Pellerin
As discussed in qgis/QGIS-Enhancement-Proposals#82 from
qgis/QGIS-Enhancement-Proposals#82 (comment)
This is the new QgsSettings class that adds an (optional)
Global Settings additional ini file where a system administrator
can store default values for the settings and provide
pre-configuration.
If an ini file named qgis_global_settings.ini is found
in the pkgDataPath directory it is automatically loaded,
this path can be overriden by a command line argument
( --globalsettingsfile path ) and through an environment
variable (QGIS_GLOBAL_SETTINGS_FILE).
For now, the new class is used in main.cpp
and WMS configuration (for testing and demonstration).
When this PR will be merged, the new QgsSettings
class will be applied to all QGIS code base.