From 3657ee672517fb6a8e3dab3d84c268ee4729321a Mon Sep 17 00:00:00 2001 From: Benjamin Jakimow <benjamin.jakimow@geo.hu-berlin.de> Date: Sat, 3 Nov 2018 20:46:53 +0100 Subject: [PATCH] tbd --- test/gridwidgets.py | 100 ++++---------------------------------------- 1 file changed, 8 insertions(+), 92 deletions(-) diff --git a/test/gridwidgets.py b/test/gridwidgets.py index 3bb3c245..5423a406 100644 --- a/test/gridwidgets.py +++ b/test/gridwidgets.py @@ -6,98 +6,14 @@ from qgis.PyQt.QtWidgets import * from timeseriesviewer.utils import * - +viewModes = ['timeXmapview', 'mapviewXtime', 'time2Xmapview'] class MapViewGridLayout(QGridLayout): def __init__(self): pass -class GridWidgetModel(QAbstractTableModel): - def __init__(self): - - super(GridWidgetModel, self).__init__() - def columnNames(self)->list: - """ - Returns the column names - :return: [list-of-str] - """ - return [self.mColLabel, self.mColName, self.mColColor] - - def rowCount(self, parent:QModelIndex=None): - """ - Returns the number of row / ClassInfos - :param parent: QModelIndex - :return: int - """ - return len(self.mClasses) - - def columnCount(self, parent: QModelIndex=None): - return len(self.columnNames()) - - - def index2ClassInfo(self, index)->ClassInfo: - if isinstance(index, QModelIndex): - index = index.row() - return self.mClasses[index] - - def classInfo2index(self, classInfo:ClassInfo)->QModelIndex: - row = self.mClasses.index(classInfo) - return self.createIndex(row, 0) - - - def data(self, index: QModelIndex, role: int = Qt.DisplayRole): - if not index.isValid(): - return None - - value = None - col = index.column() - row = index.row() - classInfo = self.index2ClassInfo(row) - - if role == Qt.DisplayRole: - if col == 0: - return classInfo.label() - if col == 1: - return classInfo.name() - if col == 2: - return classInfo.color().name() - - if role == Qt.ForegroundRole: - if col == self.mColColor: - return QBrush(getTextColorWithContrast(classInfo.color())) - - - if role == Qt.BackgroundColorRole: - if col == 2: - return QBrush(classInfo.color()) - - if role == Qt.AccessibleTextRole: - if col == 0: - return str(classInfo.label()) - if col == 1: - return classInfo.name() - if col == 2: - return classInfo.color().name() - - if role == Qt.ToolTipRole: - if col == 0: - return 'Class label "{}"'.format(classInfo.label()) - if col == 1: - return 'Class name "{}"'.format(classInfo.name()) - if col == 2: - return 'Class color "{}"'.format(classInfo.color().name()) - - if role == Qt.EditRole: - if col == 1: - return classInfo.name() - if col == 2: - return classInfo.color() - - if role == Qt.UserRole: - return classInfo - - return None - + def setViewMode(self, viewMode=str): + assert viewMode in viewModes @@ -107,10 +23,10 @@ if __name__ == '__main__': app = initQgisApplication() - view = QTableView() - - - view.resize(QSize(300,200)) - view.show() + w = QWidget() + l = MapViewGridLayout() + w.setLayout(l) + w.show() + w.resize(QSize(300,200)) app.exec_() \ No newline at end of file -- GitLab