本文整理匯總了Python中qgis.PyQt.QtCore.QSettings方法的典型用法代碼示例。如果您正苦於以下問題:Python QtCore.QSettings方法的具體用法?Python QtCore.QSettings怎麽用?Python QtCore.QSettings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.PyQt.QtCore
的用法示例。
在下文中一共展示了QtCore.QSettings方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getProxiesConf
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def getProxiesConf():
s = QSettings() # getting proxy from qgis options settings
proxyEnabled = s.value("proxy/proxyEnabled", "")
proxyType = s.value("proxy/proxyType", "")
proxyHost = s.value("proxy/proxyHost", "")
proxyPort = s.value("proxy/proxyPort", "")
proxyUser = s.value("proxy/proxyUser", "")
proxyPassword = s.value("proxy/proxyPassword", "")
if proxyEnabled == "true" and proxyType == 'HttpProxy': # test if there are proxy settings
proxyDict = {
"http": "http://%s:%s@%s:%s" % (proxyUser, proxyPassword, proxyHost, proxyPort),
"https": "http://%s:%s@%s:%s" % (proxyUser, proxyPassword, proxyHost, proxyPort)
}
return proxyDict
else:
return None
示例2: exportVectorLayer
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def exportVectorLayer(layer):
'''accepts a QgsVectorLayer or a string with a filepath'''
settings = QtCore.QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" )
if isinstance(layer, QgsMapLayer):
filename = str(layer.source())
destFilename = str(layer.name())
else:
filename = str(layer)
destFilename = str(os.path.splitext(os.path.basename(filename))[0])
if (not filename.lower().endswith("shp")):
if not isinstance(layer, QgsMapLayer):
layer = QgsVectorLayer(filename, "layer", "ogr")
if not layer.isValid() or layer.type() != QgsMapLayer.VectorLayer:
raise Exception ("Error reading file {} or it is not a valid vector layer file".format(filename))
output = tempFilenameInTempFolder(destFilename + ".shp")
QgsVectorFileWriter.writeAsVectorFormat(layer, output, systemEncoding, layer.crs(), "ESRI Shapefile")
QgsMessageLog.logMessage("Layer '%s' had to be exported to shapefile for importing. Data might be lost." % layer.name(),
level = Qgis.Warning)
return output
else:
return filename
示例3: getConnectionNameFromLayer
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def getConnectionNameFromLayer(self, layer):
connName = "postgis_store"
uri = QgsDataSourceURI(layer.dataProvider().dataSourceUri())
host = uri.host()
database = uri.database()
port = uri.port()
settings = QtCore.QSettings()
settings.beginGroup(u'/PostgreSQL/connections')
for name in settings.childGroups():
settings.beginGroup(name)
host2 = str(settings.value('host'))
database2 = str(settings.value('database'))
port2 = str(settings.value('port'))
settings.endGroup()
if port == port2 and database == database2 and host == host2:
connName = name + "_" + str(uri.schema())
settings.endGroup()
return connName
示例4: readSettings
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def readSettings(self):
'''Load the user selected settings. The settings are retained even when
the user quits QGIS.'''
qset = QSettings()
self.geomXName = qset.value('/ShapeTools/GeomXName', 'geom_x')
self.geomYName = qset.value('/ShapeTools/GeomYName', 'geom_y')
self.maxSegLength = float(qset.value('/ShapeTools/MaxSegLength', 20.0)) # In km
self.maxSegments = int(qset.value('/ShapeTools/MaxSegments', 1000))
self.mtAzMode = int(qset.value('/ShapeTools/MtAzMode', 0))
self.measureSignificantDigits = int(qset.value('/ShapeTools/MeasureSignificantDigits', 2))
color = qset.value('/ShapeTools/RubberBandColor', '#dea743')
self.rubberBandColor = QColor(color)
value = int(qset.value('/ShapeTools/RubberBandOpacity', 192))
self.rubberBandColor.setAlpha(value)
color = qset.value('/ShapeTools/MeasureLineColor', '#000000')
self.measureLineColor = QColor(color)
color = qset.value('/ShapeTools/MeasureTextColor', '#000000')
self.measureTextColor = QColor(color)
acronym = qset.value('/ShapeTools/Ellipsoid', 'WGS84')
self.setEllipsoid(acronym)
示例5: storeConnection
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def storeConnection(self, server, database):
'''
Stores database connection in the QSettings
'''
(host, port, user, password) = self.getServerConfiguration(server)
connection = server+'_'+database
settings = QSettings()
if not settings.contains('PostgreSQL/connections/'+connection+'/database'):
settings.beginGroup('PostgreSQL/connections/'+connection)
settings.setValue('database', database)
settings.setValue('host', host)
settings.setValue('port', port)
settings.setValue('username', user)
settings.setValue('password', password)
settings.endGroup()
return True
return False
示例6: storeConnectionConfiguration
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def storeConnectionConfiguration(self, server, database):
'''
Stores connection configuration in thw QSettings
server: server name
database: database name
'''
name = self.connectionEdit.text()
(host, port, user, password) = self.getServerConfiguration(server)
settings = QSettings()
if not settings.contains('PostgreSQL/servers/'+name+'/host'):
settings.beginGroup('PostgreSQL/connections/'+name)
settings.setValue('database', database)
settings.setValue('host', host)
settings.setValue('port', port)
settings.setValue('username', user)
settings.setValue('password', password)
settings.endGroup()
示例7: setDefaultConnectionParameters
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def setDefaultConnectionParameters(self, connection, host, port, user, password):
defaultConnectionDict = dict()
if host and port and user and password:
defaultConnectionDict['host'] = host
defaultConnectionDict['port'] = port
defaultConnectionDict['user'] = user
defaultConnectionDict['password'] = password
# set all connection on QSettings to not default and this connetion to default
settings = QSettings()
settings.beginGroup('PostgreSQL/servers')
connections = settings.childGroups()
settings.endGroup()
for conn in connections:
settings.beginGroup('PostgreSQL/servers/{0}'.format(conn))
settings.setValue('isDefault', conn == connection)
settings.endGroup()
else:
defaultConnectionDict = dict()
return defaultConnectionDict
示例8: on_dropDatabasePushButton_clicked
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def on_dropDatabasePushButton_clicked(self):
'''
Drops a database and updates QSettings
'''
currentItem = self.dbListWidget.currentItem()
if not currentItem:
return
if QMessageBox.question(self, self.tr('Question'), self.tr('Do you really want to drop database: ')+currentItem.text().split(' ')[0], QMessageBox.Ok|QMessageBox.Cancel) == QMessageBox.Cancel:
return
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
localDbName = self.localDb.getDatabaseName()
self.renewDb()
try:
self.serverWidget.abstractDb.dropDatabase(localDbName)
QApplication.restoreOverrideCursor()
QMessageBox.warning(self, self.tr('Success!'), self.tr('Database ')+localDbName+self.tr(' dropped successfully!'))
self.clearQSettings(localDbName)
except Exception as e:
QApplication.restoreOverrideCursor()
QMessageBox.critical(self, self.tr('Critical!'), ':'.join(e.args))
self.clearAll()
self.populateListWithDatabasesFromServer()
示例9: setServerConfiguration
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def setServerConfiguration(self, name):
'''
Sets server confogiration by its name
'''
self.isEdit = 1
self.oldName=name
settings = QSettings()
settings.beginGroup('PostgreSQL/servers/'+name)
host = settings.value('host')
port = settings.value('port')
user = settings.value('username')
password = settings.value('password')
settings.endGroup()
self.servEdit.setText(name)
self.hostEdit.setText(host)
self.portEdit.setText(port)
self.userEdit.setText(user)
self.passwordEdit.setText(password)
示例10: getCustomSizesDict
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def getCustomSizesDict(self):
#get custom sizes from qsettings
settings = QSettings()
settings.beginGroup('DSGTools/CustomSizes/')
currentSettings = settings.childGroups()
settings.endGroup()
customSizesDict = dict()
#get each parameter
for settingName in currentSettings:
customSizesDict[settingName] = dict()
settings = QSettings()
settings.beginGroup('DSGTools/CustomSizes/'+settingName)
customSizesDict[settingName]['shape'] = settings.value('shape')
customSizesDict[settingName]['value'] = settings.value('value')
settings.endGroup()
return customSizesDict
示例11: validationToolbarConfig
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def validationToolbarConfig(self):
"""
Reads all parameters for Validation Toolbar.
:return: (dict) set of parameters for Validation Toolbar.
"""
settings = QSettings()
settings.beginGroup('PythonPlugins/DsgTools/Options')
loadModelOutput = settings.value('loadModelOutput')
checkBeforeRunModel = settings.value('checkBeforeRunModel')
removeModelsOnExit = settings.value('removeModelsOnExit')
removeModelsOnNewProject = settings.value('removeModelsOnNewProject')
defaultModelPath = settings.value('defaultModelPath')
settings.endGroup()
return {
"loadModelOutput" : loadModelOutput in (True, "true"),
"checkBeforeRunModel" : checkBeforeRunModel in (True, "true"),
"removeModelsOnExit" : removeModelsOnExit in (True, "true"),
"removeModelsOnNewProject" : removeModelsOnNewProject in (True, "true"),
"defaultModelPath" : defaultModelPath
}
示例12: updateValidationToolbarConfig
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def updateValidationToolbarConfig(self):
"""
Updates current Validation Toolbar parameter values from GUI.
"""
settings = QSettings()
settings.beginGroup('PythonPlugins/DsgTools/Options')
settings.setValue('loadModelOutput', self.loadModelOutputCheckBox.isChecked())
settings.setValue('checkBeforeRunModel', self.checkBeforeRunModelCheckBox.isChecked())
settings.setValue('removeModelsOnExit', self.resetModelsCheckBox.isChecked())
settings.setValue('removeModelsOnNewProject', self.removeModelsProjectCheckBox.isChecked())
# oldModelPath = settings.value('defaultModelPath')
# newModelPath = self.modelPathComboBox.currentText()
settings.setValue('defaultModelPath', self.modelPathComboBox.currentText())
settings.endGroup()
# if oldModelPath != newModelPath:
# self.modelPathChanged.emit()
示例13: getProxyConfiguration
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def getProxyConfiguration(self):
"""
Gets the proxy configuration from QSettings
"""
settings = QSettings()
settings.beginGroup('proxy')
enabled = settings.value('proxyEnabled')
host = settings.value('proxyHost')
port = settings.value('proxyPort')
user = settings.value('proxyUser')
password = settings.value('proxyPassword')
type = settings.value('proxyType')
excludedUrls = settings.value('proxyExcludedUrls')
# try:
# urlsList = excludedUrls.split('|')
# except:
# urlsList = []
settings.endGroup()
return (enabled, host, port, user, password, type, excludedUrls)
示例14: storeConnection
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def storeConnection(self, server):
"""
Stores a connection into QSettings
"""
(host, port, user, password) = self.getServerConfiguration(server)
database = self.db.databaseName()
connection = server+'_'+database
settings = QSettings()
if not settings.contains('PostgreSQL/connections/'+connection+'/database'):
settings.beginGroup('PostgreSQL/connections/'+connection)
settings.setValue('database', database)
settings.setValue('host', host)
settings.setValue('port', port)
settings.setValue('username', user)
settings.setValue('password', password)
settings.endGroup()
return True
return False
示例15: get_proxy_config
# 需要導入模塊: from qgis.PyQt import QtCore [as 別名]
# 或者: from qgis.PyQt.QtCore import QSettings [as 別名]
def get_proxy_config(self):
""" Get proxy config from QSettings and builds proxy parameters
:return: dictionary of transfer protocols mapped to addresses, also authentication if set in QSettings
:rtype: (dict, requests.auth.HTTPProxyAuth) or (dict, None)
"""
enabled, host, port, user, password = self.get_proxy_from_qsettings()
proxy_dict = {}
if enabled and host:
port_str = ':{}'.format(port) if port else ''
for protocol in ['http', 'https', 'ftp']:
proxy_dict[protocol] = '{}://{}{}'.format(protocol, host, port_str)
auth = requests.auth.HTTPProxyAuth(user, password) if enabled and user and password else None
return proxy_dict, auth