mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-23 00:02:38 -05:00
allow full access from Python
This commit is contained in:
parent
eb841748ed
commit
8dc67afdf3
@ -24,14 +24,13 @@ class QgsSettingsTree
|
||||
public:
|
||||
|
||||
|
||||
static const QgsSettingsTreeNode *nodeCopy( const QString &key );
|
||||
static const QgsSettingsTreeNode *node( const QString &key );
|
||||
%Docstring
|
||||
Returns a copy of tree node at the given ``key``
|
||||
Returns the tree node at the given ``key``
|
||||
|
||||
.. note::
|
||||
|
||||
The returned node is a copy and any modification to it won't alter the main tree.
|
||||
This is intended to be used to access settings from Python.
|
||||
For Plugins, use :py:func:`~QgsSettingsTree.createPluginTreeNode` to create nodes for plugin settings.
|
||||
%End
|
||||
|
||||
static QgsSettingsTreeNode *createPluginTreeNode( const QString &pluginName );
|
||||
|
@ -160,11 +160,6 @@ Returns the number of named nodes in the complete key
|
||||
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
|
||||
%End
|
||||
|
||||
virtual void copy( const QgsSettingsTreeNode *other );
|
||||
%Docstring
|
||||
Copies the ``other`` node to this instance
|
||||
%End
|
||||
|
||||
protected:
|
||||
void registerChildNode( QgsSettingsTreeNode *node );
|
||||
%Docstring
|
||||
@ -264,8 +259,6 @@ Deletes a named item from the named list node
|
||||
Returns the setting used to store the selected item
|
||||
%End
|
||||
|
||||
virtual void copy( const QgsSettingsTreeNode *other );
|
||||
|
||||
protected:
|
||||
void initNamedList( const QgsSettingsTreeNode::Options &options );
|
||||
%Docstring
|
||||
|
@ -578,7 +578,7 @@ class QgsPluginInstaller(QObject):
|
||||
if not os.path.isfile(filePath):
|
||||
return
|
||||
|
||||
QgsSettingsTree.nodeCopy("plugin-manager").childSetting("last-zip-directory").setValue(QFileInfo(filePath).absoluteDir().absolutePath())
|
||||
QgsSettingsTree.node("plugin-manager").childSetting("last-zip-directory").setValue(QFileInfo(filePath).absoluteDir().absolutePath())
|
||||
|
||||
pluginName = None
|
||||
with zipfile.ZipFile(filePath, 'r') as zf:
|
||||
|
@ -229,22 +229,22 @@ class Repositories(QObject):
|
||||
|
||||
def checkingOnStart(self) -> bool:
|
||||
""" return true if checking for news and updates is enabled """
|
||||
return QgsSettingsTree.nodeCopy("plugin-manager").childSetting('automatically-check-for-updates').value()
|
||||
return QgsSettingsTree.node("plugin-manager").childSetting('automatically-check-for-updates').value()
|
||||
|
||||
def setCheckingOnStart(self, state: bool):
|
||||
""" set state of checking for news and updates """
|
||||
QgsSettingsTree.nodeCopy("plugin-manager").childSetting('automatically-check-for-updates').setValue(state)
|
||||
QgsSettingsTree.node("plugin-manager").childSetting('automatically-check-for-updates').setValue(state)
|
||||
|
||||
def saveCheckingOnStartLastDate(self):
|
||||
""" set today's date as the day of last checking """
|
||||
QgsSettingsTree.nodeCopy("plugin-manager").childSetting('check-on-start-last-date').setValue(QDate.currentDate())
|
||||
QgsSettingsTree.node("plugin-manager").childSetting('check-on-start-last-date').setValue(QDate.currentDate())
|
||||
|
||||
def timeForChecking(self) -> bool:
|
||||
""" determine whether it's the time for checking for news and updates now """
|
||||
settings = QgsSettings()
|
||||
try:
|
||||
# QgsSettings may contain ivalid value...
|
||||
interval = QgsSettingsTree.nodeCopy("plugin-manager").childSetting('check-on-start-last-date').valueAs(type=QDate).daysTo(QDate.currentDate())
|
||||
interval = QgsSettingsTree.node("plugin-manager").childSetting('check-on-start-last-date').valueAs(type=QDate).daysTo(QDate.currentDate())
|
||||
except:
|
||||
interval = 0
|
||||
if interval >= Repositories.CHECK_ON_START_INTERVAL:
|
||||
@ -711,8 +711,8 @@ class Plugins(QObject):
|
||||
self.mPlugins = {}
|
||||
for i in list(self.localCache.keys()):
|
||||
self.mPlugins[i] = self.localCache[i].copy()
|
||||
allowExperimental = QgsSettingsTree.nodeCopy("plugin-manager").childSetting("allow-experimental").value()
|
||||
allowDeprecated = QgsSettingsTree.nodeCopy("plugin-manager").childSetting("allow-deprecated").value()
|
||||
allowExperimental = QgsSettingsTree.node("plugin-manager").childSetting("allow-experimental").value()
|
||||
allowDeprecated = QgsSettingsTree.node("plugin-manager").childSetting("allow-deprecated").value()
|
||||
for i in list(self.repoCache.values()):
|
||||
for j in i:
|
||||
plugin = j.copy() # do not update repoCache elements!
|
||||
@ -808,7 +808,7 @@ class Plugins(QObject):
|
||||
# ----------------------------------------- #
|
||||
def markNews(self):
|
||||
""" mark all new plugins as new """
|
||||
seenPlugins = QgsSettingsTree.nodeCopy("plugin-manager").childSetting("seen-plugins").valueWithDefaultOverride(list(self.mPlugins.keys()))
|
||||
seenPlugins = QgsSettingsTree.node("plugin-manager").childSetting("seen-plugins").valueWithDefaultOverride(list(self.mPlugins.keys()))
|
||||
if len(seenPlugins) > 0:
|
||||
for plugin in list(self.mPlugins.keys()):
|
||||
if seenPlugins.count(plugin) == 0 and self.mPlugins[plugin]["status"] == "not installed":
|
||||
@ -817,7 +817,7 @@ class Plugins(QObject):
|
||||
# ----------------------------------------- #
|
||||
def updateSeenPluginsList(self):
|
||||
""" update the list of all seen plugins """
|
||||
setting = QgsSettingsTree.nodeCopy("plugin-manager").childSetting("seen-plugins")
|
||||
setting = QgsSettingsTree.node("plugin-manager").childSetting("seen-plugins")
|
||||
seenPlugins = setting.valueWithDefaultOverride(list(self.mPlugins.keys()))
|
||||
for plugin in list(self.mPlugins.keys()):
|
||||
if seenPlugins.count(plugin) == 0:
|
||||
|
@ -22,18 +22,6 @@ QgsSettingsTreeNode *QgsSettingsTree::treeRoot()
|
||||
return sTreeRoot;
|
||||
}
|
||||
|
||||
const QgsSettingsTreeNode *QgsSettingsTree::nodeCopy( const QString &key )
|
||||
{
|
||||
QgsSettingsTreeNode *copyNode = nullptr;
|
||||
const QgsSettingsTreeNode *node = treeRoot()->childNode( key );
|
||||
if ( node )
|
||||
{
|
||||
copyNode = new QgsSettingsTreeNode();
|
||||
copyNode->copy( node );
|
||||
}
|
||||
return copyNode;
|
||||
}
|
||||
|
||||
QgsSettingsTreeNode *QgsSettingsTree::createPluginTreeNode( const QString &pluginName )
|
||||
{
|
||||
QgsSettingsTreeNode *te = sTreePlugins->childNode( pluginName );
|
||||
|
@ -65,11 +65,10 @@ class CORE_EXPORT QgsSettingsTree
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns a copy of tree node at the given \a key
|
||||
* \note The returned node is a copy and any modification to it won't alter the main tree.
|
||||
* This is intended to be used to access settings from Python.
|
||||
* Returns the tree node at the given \a key
|
||||
* \note For Plugins, use createPluginTreeNode() to create nodes for plugin settings.
|
||||
*/
|
||||
static const QgsSettingsTreeNode *nodeCopy( const QString &key );
|
||||
static const QgsSettingsTreeNode *node( const QString &key ) {return treeRoot()->childNode( key );}
|
||||
|
||||
/**
|
||||
* Creates a settings tree node for the given \a pluginName
|
||||
|
@ -27,8 +27,7 @@ QgsSettingsTreeNode::~QgsSettingsTreeNode()
|
||||
mParent->unregisterChildNode( this );
|
||||
|
||||
qDeleteAll( mChildrenNodes );
|
||||
if ( !mIsCopy )
|
||||
qDeleteAll( mChildrenSettings );
|
||||
qDeleteAll( mChildrenSettings );
|
||||
}
|
||||
|
||||
QgsSettingsTreeNode *QgsSettingsTreeNode::createRootNode()
|
||||
@ -116,48 +115,6 @@ void QgsSettingsTreeNode::registerChildNode( QgsSettingsTreeNode *node )
|
||||
mChildrenNodes.append( node );
|
||||
}
|
||||
|
||||
void QgsSettingsTreeNode::copy( const QgsSettingsTreeNode *other )
|
||||
{
|
||||
mIsCopy = true;
|
||||
mType = other->type();
|
||||
mChildrenSettings = other->mChildrenSettings;
|
||||
mParent = other->mParent;
|
||||
mKey = other->mKey;
|
||||
mCompleteKey = other->mCompleteKey;
|
||||
mNamedNodesCount = other->mNamedNodesCount;
|
||||
|
||||
const QList<QgsSettingsTreeNode *> children = other->mChildrenNodes;
|
||||
for ( const QgsSettingsTreeNode *child : children )
|
||||
{
|
||||
switch ( child->type() )
|
||||
{
|
||||
case Type::Root:
|
||||
{
|
||||
Q_ASSERT( false );
|
||||
break;
|
||||
}
|
||||
|
||||
case Type::Standard:
|
||||
{
|
||||
QgsSettingsTreeNode *newChild = new QgsSettingsTreeNode();
|
||||
newChild->copy( child );
|
||||
mChildrenNodes.append( newChild );
|
||||
break;
|
||||
}
|
||||
|
||||
case Type::NamedList:
|
||||
{
|
||||
QgsSettingsTreeNamedListNode *newChild = new QgsSettingsTreeNamedListNode();
|
||||
newChild->copy( child );
|
||||
mChildrenNodes.append( newChild );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mChildrenSettings = other->childrenSettings();
|
||||
}
|
||||
|
||||
void QgsSettingsTreeNode::unregisterChildSetting( const QgsSettingsEntryBase *setting, bool deleteSettingValues, const QStringList &parentsNamedItems )
|
||||
{
|
||||
if ( deleteSettingValues )
|
||||
@ -193,17 +150,6 @@ void QgsSettingsTreeNamedListNode::initNamedList( const QgsSettingsTreeNode::Opt
|
||||
mCompleteKey.append( QStringLiteral( "items/%%1/" ).arg( mNamedNodesCount ) );
|
||||
}
|
||||
|
||||
void QgsSettingsTreeNamedListNode::copy( const QgsSettingsTreeNode *other )
|
||||
{
|
||||
QgsSettingsTreeNode::copy( other );
|
||||
|
||||
const QgsSettingsTreeNamedListNode *otherNamedList = dynamic_cast<const QgsSettingsTreeNamedListNode *>( other );
|
||||
|
||||
mOptions = otherNamedList->mOptions;
|
||||
mSelectedItemSetting = otherNamedList->mSelectedItemSetting;
|
||||
mItemsCompleteKey = otherNamedList->mItemsCompleteKey;
|
||||
}
|
||||
|
||||
QgsSettingsTreeNamedListNode::~QgsSettingsTreeNamedListNode()
|
||||
{
|
||||
delete mSelectedItemSetting;
|
||||
|
@ -157,9 +157,6 @@ class CORE_EXPORT QgsSettingsTreeNode
|
||||
% End
|
||||
#endif
|
||||
|
||||
//! Copies the \a other node to this instance
|
||||
virtual void copy( const QgsSettingsTreeNode *other );
|
||||
|
||||
protected:
|
||||
//! Registers a child nodes
|
||||
void registerChildNode( QgsSettingsTreeNode *node );
|
||||
@ -189,7 +186,6 @@ class CORE_EXPORT QgsSettingsTreeNode
|
||||
QList<const QgsSettingsEntryBase *> mChildrenSettings;
|
||||
QgsSettingsTreeNode *mParent = nullptr;
|
||||
|
||||
bool mIsCopy = false;
|
||||
QString mKey;
|
||||
QString mCompleteKey;
|
||||
int mNamedNodesCount = 0;
|
||||
@ -257,8 +253,6 @@ class CORE_EXPORT QgsSettingsTreeNamedListNode : public QgsSettingsTreeNode
|
||||
//! Returns the setting used to store the selected item
|
||||
const QgsSettingsEntryString *selectedItemSetting() const {return mSelectedItemSetting;}
|
||||
|
||||
virtual void copy( const QgsSettingsTreeNode *other ) override;
|
||||
|
||||
protected:
|
||||
//! Init the nodes with the specific \a options
|
||||
void initNamedList( const QgsSettingsTreeNode::Options &options );
|
||||
|
@ -148,13 +148,12 @@ class TestQgsSettingsEntry(unittest.TestCase):
|
||||
self.assertEqual(type(proot.childSetting("python-implemented-setting")), QgsSettingsEntryEnumFlag)
|
||||
|
||||
def test_get_node(self):
|
||||
node = QgsSettingsTree.nodeCopy("gps")
|
||||
node = QgsSettingsTree.node("gps")
|
||||
self.assertIsNotNone(node)
|
||||
count = len(node.childrenNodes())
|
||||
# cannot add a child node since the getter returns a const
|
||||
node.createChildNode("test")
|
||||
self.assertEqual(len(node.childrenNodes()), count + 1)
|
||||
self.assertEqual(len(QgsSettingsTree.nodeCopy("gps").childrenNodes()), count)
|
||||
self.assertEqual(len(QgsSettingsTree.node("gps").childrenNodes()), count + 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user