PK jGH;3 " quick_map_services/about_dialog.py# -*- coding: utf-8 -*-
"""
/***************************************************************************
AboutDialog
A QGIS plugin
Collection of internet map services
-------------------
begin : 2014-11-21
git sha : $Format:%H$
copyright : (C) 2014 by NextGIS
email : info@nextgis.com
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
import ConfigParser
import os
from PyQt4 import uic
from PyQt4.QtGui import QDialog, QDialogButtonBox, QPixmap
CURR_PATH = os.path.dirname(__file__)
FORM_CLASS, _ = uic.loadUiType(os.path.join(CURR_PATH, 'about_dialog_base.ui'))
class AboutDialog(QDialog, FORM_CLASS):
def __init__(self, parent=None):
"""Constructor."""
super(AboutDialog, self).__init__(parent)
self.setupUi(self)
self.btnHelp = self.buttonBox.button(QDialogButtonBox.Help)
self.lblLogo.setPixmap(QPixmap(os.path.join(CURR_PATH, 'icons/mapservices.png')))
cfg = ConfigParser.SafeConfigParser()
cfg.read(os.path.join(os.path.dirname(__file__), 'metadata.txt'))
version = cfg.get('general', 'version')
self.lblVersion.setText(self.tr('Version: %s') % (version))
self.tbInfo.setHtml(self.get_about_text())
self.tbLicense.setPlainText(self.get_license_text())
self.tb3rd.setHtml(self.get_3rd_text())
def get_about_text(self):
return self.tr('
Collection of internet map services
'
'Developers: NextGIS
'
'Issue tracker: GitHub
'
'Source code: GitHub
')
def get_license_text(self):
with open(os.path.join(CURR_PATH, 'LICENSE')) as f:
return f.read()
def get_3rd_text(self):
return self.tr('Python tile layer: TileLayer Plugin by Minoru Akagi
'
'Some icons from QGIS: QGIS GitHub
')
PK -fG`BՑ ' quick_map_services/about_dialog_base.ui
Dialog
0
0
432
326
About QuickMapServices
-
Qt::Horizontal
QDialogButtonBox::Close
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;">
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Droid Sans'; font-size:16pt; font-weight:600;">QuickMapServices</span></p></body></html>
Qt::AlignCenter
-
0
0
TextLabel
Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
-
0
false
Info
-
true
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;">
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:9pt;"><br /></p></body></html>
Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse
true
License
-
true
Third-party Components
-
true
-
TextLabel
Qt::AlignCenter
buttonBox
accepted()
Dialog
accept()
248
254
157
274
buttonBox
rejected()
Dialog
reject()
316
260
286
274
PK -fGʉ * quick_map_services/config_reader_helper.py__author__ = 'yellow'
class ConfigReaderHelper:
@staticmethod
def try_read_config(parser, section, param, reraise=False):
try:
val = parser.get(section, param)
except:
if reraise:
raise
else:
val = None
return val
@staticmethod
def try_read_config_int(parser, section, param, reraise=False):
try:
val = parser.getint(section, param)
except:
if reraise:
raise
else:
val = None
return val
@staticmethod
def try_read_config_bool(parser, section, param, reraise=False):
try:
val = parser.getboolean(section, param)
except:
if reraise:
raise
else:
val = None
return valPK nKH&}@U U ' quick_map_services/custom_translator.py# -*- coding: utf-8 -*-
"""
/***************************************************************************
QuickMapServices
A QGIS plugin
Collection of internet map services
-------------------
begin : 2014-11-21
git sha : $Format:%H$
copyright : (C) 2014 by NextGIS
email : info@nextgis.com
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
from PyQt4.QtCore import QTranslator
from singleton import singleton
@singleton
class CustomTranslator(QTranslator):
def __init__(self):
QTranslator.__init__(self)
self.__translates = {}
def append(self, text, translation):
if text and translation:
self.__translates[text] = translation
def clear_translations(self):
self.__translates.clear()
def translate(self, context, text, disambiguation):
try:
if (isinstance(text, str) or isinstance(text, unicode)) and text in self.__translates.keys():
return self.__translates[text]
return ''
except:
return ''
PK OZOH> ' quick_map_services/data_sources_list.py# -*- coding: utf-8 -*-
"""
/***************************************************************************
QuickMapServices
A QGIS plugin
Collection of internet map services
-------------------
begin : 2014-11-21
git sha : $Format:%H$
copyright : (C) 2014 by NextGIS
email : info@nextgis.com
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
from ConfigParser import ConfigParser
import codecs
import os
import sys
from PyQt4.QtCore import QCoreApplication
from PyQt4.QtGui import QIcon, QAction
from qgis.core import QgsMessageLog
from config_reader_helper import ConfigReaderHelper
from custom_translator import CustomTranslator
from data_source_info import DataSourceInfo, DataSourceCategory
import extra_sources
from data_source_serializer import DataSourceSerializer
from locale import Locale
from supported_drivers import KNOWN_DRIVERS
CURR_PATH = os.path.dirname(__file__).decode(sys.getfilesystemencoding())
INTERNAL_DS_PATHS = [os.path.join(CURR_PATH, extra_sources.DATA_SOURCES_DIR_NAME), ]
CONTRIBUTE_DS_PATHS = [os.path.join(extra_sources.CONTRIBUTE_DIR_PATH, extra_sources.DATA_SOURCES_DIR_NAME), ]
USER_DS_PATHS = [os.path.join(extra_sources.USER_DIR_PATH, extra_sources.DATA_SOURCES_DIR_NAME), ]
ALL_DS_PATHS = INTERNAL_DS_PATHS + CONTRIBUTE_DS_PATHS + USER_DS_PATHS
ROOT_MAPPING = {
INTERNAL_DS_PATHS[0]: DataSourceCategory.BASE,
CONTRIBUTE_DS_PATHS[0]: DataSourceCategory.CONTRIB,
USER_DS_PATHS[0]: DataSourceCategory.USER
}
class DataSourcesList:
def __init__(self, ds_paths=ALL_DS_PATHS):
self.data_sources = {}
self.ds_paths = ds_paths
self._fill_data_sources_list()
def _fill_data_sources_list(self):
self.data_sources = {}
for ds_path in self.ds_paths:
for root, dirs, files in os.walk(ds_path):
for ini_file in [f for f in files if f.endswith('.ini')]:
try:
ini_full_path = os.path.join(root, ini_file)
ds = DataSourceSerializer.read_from_ini(ini_full_path)
# set contrib&user
if ds_path in ROOT_MAPPING.keys():
ds.category = ROOT_MAPPING[ds_path]
else:
ds.category = DataSourceCategory.USER
# action
ds.action = QAction(QIcon(ds.icon_path), self.tr(ds.alias), None)
ds.action.setData(ds)
# append to array
self.data_sources[ds.id] = ds
except Exception, e:
error_message = 'INI file can\'t be parsed: ' + e.message
QgsMessageLog.logMessage(error_message, level=QgsMessageLog.CRITICAL)
# noinspection PyMethodMayBeStatic
def tr(self, message):
try:
message = str(message)
except:
return message
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('QuickMapServices', message)
PK MHM* M* ( quick_map_services/data_sources_model.py# -*- coding: utf-8 -*-
"""
/***************************************************************************
QuickMapServices
A QGIS plugin
Collection of internet map services
-------------------
begin : 2014-11-21
git sha : $Format:%H$
copyright : (C) 2016 by NextGIS
email : info@nextgis.com
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
# from data_source_info import DataSourceCategory
# from group_info import
from data_sources_list import DataSourcesList
from groups_list import GroupsList
from PyQt4 import QtGui
from PyQt4.QtCore import Qt, QAbstractItemModel, QModelIndex
from PyQt4.QtGui import QIcon
from plugin_settings import PluginSettings
from singleton import QSingleton
class DSManagerModel(QAbstractItemModel):
__metaclass__ = QSingleton
COLUMN_GROUP_DS = 0
COLUMN_VISIBILITY = 1
COLUMN_SOURCE = 2
# instance = None
# @classmethod
# def getInstance(cls):
# if cls.instance
def __init__(self, parent=None):
super(DSManagerModel, self).__init__(parent)
self.columnNames = []
self.columnNames.insert(self.COLUMN_GROUP_DS, self.tr("Group/DS"))
self.columnNames.insert(self.COLUMN_VISIBILITY, self.tr("Visible"))
self.columnNames.insert(self.COLUMN_SOURCE, self.tr("Source"))
self.rootItem = QtGui.QTreeWidgetItem(self.columnNames)
self.__setupModelData()
def resetModel(self):
self.beginResetModel()
self.__clear()
self.__setupModelData()
self.endResetModel()
self.modelReset.emit()
def __clear(self):
for groupIndex in range(self.rootItem.childCount() - 1, -1, -1):
groupItem = self.rootItem.child(groupIndex)
for dsIndex in range(groupItem.childCount() - 1, -1, -1):
dsItem = groupItem.child(dsIndex)
groupItem.removeChild(dsItem)
self.rootItem.removeChild(groupItem)
def __setupModelData(self):
dsList = DataSourcesList().data_sources.values()
groupInfoList = GroupsList().groups
groupsItems = []
groups = []
for ds in dsList:
if ds.group in groups:
group_item = groupsItems[groups.index(ds.group)]
else:
group_item = QtGui.QTreeWidgetItem()
group_item.setData(self.COLUMN_GROUP_DS, Qt.DisplayRole, ds.group)
group_item.setData(self.COLUMN_VISIBILITY, Qt.DisplayRole, "")
group_item.setData(self.COLUMN_SOURCE, Qt.DisplayRole, ds.category)
group_item.setCheckState(self.COLUMN_VISIBILITY, Qt.Unchecked)
groupInfo = groupInfoList.get(ds.group)
if groupInfo is not None:
group_item.setIcon(self.COLUMN_GROUP_DS, QIcon(groupInfo.icon))
else:
group_item.setData(self.COLUMN_GROUP_DS, Qt.DisplayRole, ds.group + " (%s!)" % self.tr("group not found"))
group_item.setData(self.COLUMN_GROUP_DS, Qt.UserRole, groupInfo)
groups.append(ds.group)
groupsItems.append(group_item)
self.rootItem.addChild(group_item)
ds_item = QtGui.QTreeWidgetItem()
ds_item.setData(self.COLUMN_GROUP_DS, Qt.DisplayRole, ds.alias)
ds_item.setIcon(self.COLUMN_GROUP_DS, QIcon(ds.icon_path))
ds_item.setData(self.COLUMN_GROUP_DS, Qt.UserRole, ds)
ds_item.setData(self.COLUMN_VISIBILITY, Qt.DisplayRole, "")
ds_item.setData(self.COLUMN_SOURCE, Qt.DisplayRole, ds.category)
ds_check_state = Qt.Checked
if ds.id in PluginSettings.get_hide_ds_id_list():
ds_check_state = Qt.Unchecked
ds_item.setCheckState(self.COLUMN_VISIBILITY, ds_check_state)
if group_item.childCount() != 0 and group_item.checkState(1) != ds_check_state:
group_item.setCheckState(self.COLUMN_VISIBILITY, Qt.PartiallyChecked)
else:
group_item.setCheckState(self.COLUMN_VISIBILITY, ds_check_state)
group_item.addChild(
ds_item
)
def setData(self, index, value, role):
if not index.isValid():
return False
else:
item = index.internalPointer()
if role == Qt.CheckStateRole:
item.setData(self.COLUMN_VISIBILITY, role, value)
self.dataChanged.emit(
index,
index
)
self.updateChecks(index, value)
return True
def updateChecks(self, index, checkState):
if self.hasChildren(index):
for row in range(0, self.rowCount(index)):
childItem = index.internalPointer().child(row)
childItem.setCheckState(index.column(), checkState)
self.dataChanged.emit(
self.index(0, index.column(), index),
self.index(row, index.column(), index)
)
else:
parentIndex = self.parent(index)
parentItem = parentIndex.internalPointer()
diff = False
for row in range(0, self.rowCount(parentIndex)):
childItem = parentItem.child(row)
if childItem.checkState(index.column()) != checkState:
diff = True
break
if diff:
parentItem.setCheckState(index.column(), Qt.PartiallyChecked)
else:
parentItem.setCheckState(index.column(), checkState)
self.dataChanged.emit(
parentIndex,
parentIndex
)
def columnCount(self, parent):
if parent.isValid():
return parent.internalPointer().columnCount()
else:
return self.rootItem.columnCount()
def data(self, index, role):
if not index.isValid():
return None
if role not in [Qt.DisplayRole, Qt.CheckStateRole, Qt.DecorationRole, Qt.UserRole]:
return None
item = index.internalPointer()
return item.data(index.column(), role)
def flags(self, index):
if not index.isValid():
item = self.rootItem
else:
item = index.internalPointer()
return item.flags()
def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return self.rootItem.data(section, Qt.DisplayRole)
return None
def index(self, row, column, parent):
if not self.hasIndex(row, column, parent):
return QModelIndex()
if not parent.isValid():
parentItem = self.rootItem
else:
parentItem = parent.internalPointer()
childItem = parentItem.child(row)
if childItem:
return self.createIndex(row, column, childItem)
else:
return QModelIndex()
def parent(self, index):
if not index.isValid():
return QModelIndex()
childItem = index.internalPointer()
parentItem = childItem.parent()
if parentItem == self.rootItem:
return QModelIndex()
return self.createIndex(parentItem.parent().indexOfChild(parentItem), index.column(), parentItem)
def rowCount(self, parent):
if not parent.isValid():
parentItem = self.rootItem
else:
parentItem = parent.internalPointer()
return parentItem.childCount()
def sort(self, column, order=Qt.AscendingOrder):
self.layoutAboutToBeChanged.emit()
if column == self.COLUMN_VISIBILITY:
role = Qt.CheckStateRole
else:
role = Qt.DisplayRole
if order == Qt.AscendingOrder:
compareFunc = lambda a, b: True if cmp(a, b) < 0 else False
else:
compareFunc = lambda a, b: True if cmp(a, b) > 0 else False
for groupIndexI in range(0, self.rootItem.childCount()):
for groupIndexJ in range(0, groupIndexI):
groupItemI = self.rootItem.child(groupIndexI)
groupItemJ = self.rootItem.child(groupIndexJ)
if compareFunc(groupItemI.data(column, role), groupItemJ.data(column, role)):
self.rootItem.insertChild(groupIndexJ, self.rootItem.takeChild(groupIndexI))
break
self.layoutChanged.emit()
def checkAll(self):
for row in range(0, self.rootItem.childCount()):
groupItem = self.rootItem.child(row)
groupIndex = self.createIndex(row, self.COLUMN_VISIBILITY, groupItem)
self.setData(groupIndex, Qt.Checked, Qt.CheckStateRole)
def uncheckAll(self):
for row in range(0, self.rootItem.childCount()):
groupItem = self.rootItem.child(row)
groupIndex = self.createIndex(row, self.COLUMN_VISIBILITY, groupItem)
self.setData(groupIndex, Qt.Unchecked, Qt.CheckStateRole)
def saveSettings(self):
hideDSidList = []
for groupIndex in range(0, self.rootItem.childCount()):
groupItem = self.rootItem.child(groupIndex)
for dsIndex in range(0, groupItem.childCount()):
dsItem = groupItem.child(dsIndex)
if dsItem.checkState(self.COLUMN_VISIBILITY) == Qt.Unchecked:
hideDSidList.append(dsItem.data(self.COLUMN_GROUP_DS, Qt.UserRole).id)
PluginSettings.set_hide_ds_id_list(hideDSidList)
def isGroup(self, index):
childItem = index.internalPointer()
parentItem = childItem.parent()
if parentItem == self.rootItem:
return True
return False
PK iPHd &