Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
luyikei
VLMC
Commits
609e52a3
Commit
609e52a3
authored
Dec 09, 2009
by
Hugo Beauzee-Luyssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a SettingValue class.
So we can watch for configuration changes without polling the configmanager.
parent
b7078463
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
137 additions
and
36 deletions
+137
-36
src/Configuration/SettingValue.cpp
src/Configuration/SettingValue.cpp
+46
-0
src/Configuration/SettingValue.h
src/Configuration/SettingValue.h
+44
-0
src/Configuration/SettingsManager.cpp
src/Configuration/SettingsManager.cpp
+35
-25
src/Configuration/SettingsManager.h
src/Configuration/SettingsManager.h
+3
-2
src/Configuration/configuration.pri
src/Configuration/configuration.pri
+8
-8
src/GUI/settings/KeyboardShortcut.cpp
src/GUI/settings/KeyboardShortcut.cpp
+1
-1
No files found.
src/Configuration/SettingValue.cpp
0 → 100644
View file @
609e52a3
/*****************************************************************************
* SettingValue.cpp: A setting value that can broadcast its changes
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "SettingValue.h"
SettingValue
::
SettingValue
(
const
QVariant
&
val
)
:
m_val
(
val
)
{
}
void
SettingValue
::
set
(
const
QVariant
&
val
)
{
if
(
val
!=
m_val
)
{
m_val
=
val
;
emit
changed
(
m_val
);
}
}
const
QVariant
&
SettingValue
::
get
()
const
{
return
m_val
;
}
QVariant
&
SettingValue
::
get
()
{
return
m_val
;
}
src/Configuration/SettingValue.h
0 → 100644
View file @
609e52a3
/*****************************************************************************
* SettingValue.h: A setting value that can broadcast its changes
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef SETTINGVALUE_H
#define SETTINGVALUE_H
#include <QObject>
#include <QVariant>
class
SettingValue
:
public
QObject
{
Q_OBJECT
Q_DISABLE_COPY
(
SettingValue
);
public:
SettingValue
(
const
QVariant
&
val
);
void
set
(
const
QVariant
&
val
);
const
QVariant
&
get
()
const
;
QVariant
&
get
();
private:
QVariant
m_val
;
signals:
void
changed
(
const
QVariant
&
);
};
#endif // SETTINGVALUE_H
src/Configuration/SettingsManager.cpp
View file @
609e52a3
...
...
@@ -44,21 +44,21 @@ SettingsManager::~SettingsManager()
{
}
void
SettingsManager
::
setValues
(
const
QString
&
part
,
QHash
<
QString
,
QVariant
>
values
)
{
if
(
!
m_tempData
.
contains
(
part
)
)
addNewSettingsPart
(
part
);
m_globalLock
.
lockForRead
();
SettingsPart
*
sett
=
m_tempData
[
part
];
m_globalLock
.
unlock
();
QHash
<
QString
,
QVariant
>
::
iterator
it
=
values
.
begin
();
QHash
<
QString
,
QVariant
>
::
iterator
end
=
values
.
end
();
QWriteLocker
lock
(
&
sett
->
m_lock
);
for
(
;
it
!=
end
;
++
it
)
sett
->
m_data
.
insert
(
it
.
key
(),
it
.
value
()
);
return
;
}
//
void SettingsManager::setValues( const QString& part,
SettingsPart::ConfigPair
values )
//
{
//
if ( !m_tempData.contains( part ) )
//
addNewSettingsPart( part );
//
m_globalLock.lockForRead();
//
SettingsPart* sett = m_tempData[part];
//
m_globalLock.unlock();
//
SettingsPart::ConfigPair
::iterator it = values.begin();
//
SettingsPart::ConfigPair
::iterator end = values.end();
//
//
QWriteLocker lock( &sett->m_lock );
//
for ( ; it != end; ++it )
//
sett->m_data.insert( it.key(), it.value() );
//
return ;
//
}
void
SettingsManager
::
setValue
(
const
QString
&
part
,
const
QString
&
key
,
const
QVariant
&
value
)
{
...
...
@@ -70,7 +70,11 @@ void SettingsManager::setValue( const QString& part , const QString& key, const
m_globalLock
.
unlock
();
QWriteLocker
lock
(
&
m_globalLock
);
SettingsPart
*
tmp
=
m_tempData
[
part
];
tmp
->
m_data
.
insert
(
key
,
value
);
SettingsPart
::
ConfigPair
::
iterator
it
=
tmp
->
m_data
.
find
(
key
);
if
(
it
==
tmp
->
m_data
.
end
()
)
tmp
->
m_data
[
key
]
=
new
SettingValue
(
value
);
else
it
.
value
()
->
set
(
value
);
return
;
}
...
...
@@ -80,7 +84,7 @@ const QVariant& SettingsManager::getValue( const QString& part, const QString&
return
getValue
(
"default"
,
key
);
QReadLocker
readLock
(
&
m_globalLock
);
QReadLocker
rdLock
(
&
m_data
[
part
]
->
m_lock
);
QVariant
&
value
=
m_data
[
part
]
->
m_data
[
key
];
QVariant
&
value
=
m_data
[
part
]
->
m_data
[
key
]
->
get
()
;
return
value
;
}
...
...
@@ -97,13 +101,13 @@ void SettingsManager::saveSettings( const QString& part, QDomDocument& xmlfile,
m_globalLock
.
unlock
();
//SAVE SETTINGS TO DomDocument
QReadLocker
lock
(
&
sett
->
m_lock
);
QHash
<
QString
,
QVariant
>::
iterator
it
=
sett
->
m_data
.
begin
();
QHash
<
QString
,
QVariant
>::
iterator
end
=
sett
->
m_data
.
end
();
SettingsPart
::
ConfigPair
::
const_
iterator
it
=
sett
->
m_data
.
begin
();
SettingsPart
::
ConfigPair
::
const_
iterator
end
=
sett
->
m_data
.
end
();
QDomElement
settingsNode
=
xmlfile
.
createElement
(
part
);
for
(
;
it
!=
end
;
++
it
)
{
QDomElement
elem
=
xmlfile
.
createElement
(
it
.
key
()
);
elem
.
setAttribute
(
"value"
,
it
.
value
().
toString
()
);
elem
.
setAttribute
(
"value"
,
it
.
value
()
->
get
()
.
toString
()
);
settingsNode
.
appendChild
(
elem
);
}
...
...
@@ -140,7 +144,7 @@ void SettingsManager::loadSettings( const QString& part, const QDomElement& set
return
;
}
sett
->
m_data
.
insert
(
list
.
at
(
idx
).
toElement
().
tagName
(),
QVariant
(
attrMap
.
item
(
0
).
nodeValue
()
));
new
SettingValue
(
QVariant
(
attrMap
.
item
(
0
).
nodeValue
()
)
)
);
}
sett
->
m_lock
.
unlock
();
m_globalLock
.
unlock
();
...
...
@@ -171,11 +175,17 @@ void SettingsManager::commit()
SettingsPart
*
sett
=
it
.
value
();
QReadLocker
rLock
(
&
sett
->
m_lock
);
QHash
<
QString
,
QVariant
>
::
iterator
iter
=
sett
->
m_data
.
begin
();
QHash
<
QString
,
QVariant
>
::
iterator
ed
=
sett
->
m_data
.
end
();
SettingsPart
::
ConfigPair
::
iterator
iter
=
sett
->
m_data
.
begin
();
SettingsPart
::
ConfigPair
::
iterator
e
n
d
=
sett
->
m_data
.
end
();
QWriteLocker
wLock
(
&
m_data
[
it
.
key
()]
->
m_lock
);
for
(
;
iter
!=
ed
;
++
iter
)
m_data
[
it
.
key
()]
->
m_data
.
insert
(
iter
.
key
(),
iter
.
value
()
);
for
(
;
iter
!=
end
;
++
iter
)
{
SettingsPart
::
ConfigPair
::
iterator
insert_it
=
m_data
[
it
.
key
()]
->
m_data
.
find
(
iter
.
key
()
);
if
(
insert_it
==
m_data
[
it
.
key
()]
->
m_data
.
end
()
)
m_data
[
it
.
key
()]
->
m_data
.
insert
(
iter
.
key
(),
new
SettingValue
(
iter
.
value
()
->
get
()
)
);
else
m_data
[
it
.
key
()]
->
m_data
[
iter
.
key
()
]
->
set
(
iter
.
value
()
->
get
()
);
}
}
lock
.
unlock
();
flush
();
...
...
src/Configuration/SettingsManager.h
View file @
609e52a3
...
...
@@ -31,11 +31,12 @@
#include <QVariant>
#include <QDomDocument>
#include "SettingValue.h"
#include "QSingleton.hpp"
struct
SettingsPart
{
typedef
QHash
<
QString
,
QVariant
>
ConfigPair
;
typedef
QHash
<
QString
,
SettingValue
*
>
ConfigPair
;
SettingsPart
()
{}
ConfigPair
m_data
;
...
...
@@ -55,7 +56,7 @@ class SettingsManager : public QObject, public QSingleton<SettingsManager>
friend
class
QSingleton
<
SettingsManager
>
;
public:
void
setValues
(
const
QString
&
part
,
QHash
<
QString
,
QVariant
>
);
//
void setValues( const QString& part,
SettingsPart::ConfigPair
);
void
setValue
(
const
QString
&
part
,
const
QString
&
key
,
const
QVariant
&
value
);
const
QVariant
&
getValue
(
const
QString
&
part
,
const
QString
&
key
)
const
;
const
SettingsPart
*
getConfigPart
(
const
QString
&
part
)
const
;
...
...
src/Configuration/configuration.pri
View file @
609e52a3
HEADERS +=
ProjectSettingsDefault.h
\
SettingsManager.h
\
VLMCSettingsDefault.h
SOURCES +=
ProjectSettingsDefault.cpp
\
SettingsManager.cpp
\
VLMCSettingsDefault.cpp
HEADERS += ProjectSettingsDefault.h \
SettingsManager.h \
VLMCSettingsDefault.h
\
SettingValue.h
SOURCES += ProjectSettingsDefault.cpp \
SettingsManager.cpp \
VLMCSettingsDefault.cpp
\
SettingValue.cpp
src/GUI/settings/KeyboardShortcut.cpp
View file @
609e52a3
...
...
@@ -37,7 +37,7 @@ KeyboardShortcut::KeyboardShortcut( QWidget* parent ) :
SettingsPart
::
ConfigPair
::
const_iterator
ite
=
parts
->
m_data
.
end
();
while
(
it
!=
ite
)
{
m_keySeq
[
it
.
key
()]
=
new
QKeySequence
(
it
.
value
().
toString
()
);
m_keySeq
[
it
.
key
()]
=
new
QKeySequence
(
it
.
value
()
->
get
()
.
toString
()
);
m_layout
->
addRow
(
it
.
key
(),
new
KeyboardShortcutInput
(
m_keySeq
[
it
.
key
()]
->
toString
(),
this
)
);
++
it
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment