diff --git a/timeseriesviewer/mapcanvas.py b/timeseriesviewer/mapcanvas.py index 8337d1bd093fce2557f81942a00e31d2ec79b5c6..7767465f563245b705c361f2c6402383f588a6c9 100644 --- a/timeseriesviewer/mapcanvas.py +++ b/timeseriesviewer/mapcanvas.py @@ -1126,5 +1126,7 @@ if __name__ == '__main__': c.setExtent(lyr1.extent()) c.setCrs(QgsCoordinateReferenceSystem('EPSG:32632')) c.setExtent(c.spatialExtentHint()) + + c.refresh() qgsApp.exec_() \ No newline at end of file diff --git a/timeseriesviewer/profilevisualization.py b/timeseriesviewer/profilevisualization.py index 2416b522e6845332116c71a4cb3a9efeb70c4d5b..59c498a35bcee3b30280672fc644d0d84cc5e6e1 100644 --- a/timeseriesviewer/profilevisualization.py +++ b/timeseriesviewer/profilevisualization.py @@ -2221,7 +2221,9 @@ if __name__ == '__main__': STVis.createNewPlotStyle3D() STVis.ui.listWidget.setCurrentRow(1) - STVis.loadCoordinate(cpND) + STVis.loadCoordinate(cpND, backgroundProcess=False) + + STVis.tpCollection.mTemporalProfiles[0].setName('My Name') from example import exampleEvents #STVis.loadCoordinatesFromOgr(exampleEvents) diff --git a/timeseriesviewer/temporalprofiles2d.py b/timeseriesviewer/temporalprofiles2d.py index 2820ba0df15fd088cf1418ae4e782d78ad6a4117..86a9b461d2b7b9e5f82185a6f650a83ead3465c5 100644 --- a/timeseriesviewer/temporalprofiles2d.py +++ b/timeseriesviewer/temporalprofiles2d.py @@ -1131,10 +1131,16 @@ class TemporalProfileCollection(QAbstractTableModel): self.mColumNames = [self.mcnName, self.mcnLoaded, self.mcnCoordinate] crs = QgsCoordinateReferenceSystem('EPSG:4862') - uri = 'Point?crs={}'.format(crs.authid()) + uri = 'Point?crs={}&field=id:integer&field=name:string(120)'.format(crs.authid()) + self.mLocations = QgsVectorLayer(uri, 'LOCATIONS', 'memory') + symbol = QgsFillSymbol.createSimple({'style': 'no', 'color': 'red', 'outline_color': 'black'}) + self.mLocations.renderer().setSymbol(symbol) self.TS = None - self.mLocations = QgsVectorLayer(uri, 'LOCATIONS', 'memory') + + + + self.mTemporalProfiles = [] self.mTPLookupSpatialPoint = {} self.mTPLookupID = {} @@ -1274,6 +1280,8 @@ class TemporalProfileCollection(QAbstractTableModel): self.prune(nMax=self.mMaxProfiles - l) self.beginInsertRows(QModelIndex(), i, i + l - 1) + + features = [] for temporalProfile in temporalProfiles: assert isinstance(temporalProfile, TemporalProfile) id = self.nextID @@ -1282,9 +1290,21 @@ class TemporalProfileCollection(QAbstractTableModel): self.mTemporalProfiles.insert(i, temporalProfile) self.mTPLookupID[id] = temporalProfile self.mTPLookupSpatialPoint[temporalProfile.mCoordinate] = temporalProfile + + f = QgsFeature(self.mLocations.fields()) + f.setFields(self.mLocations.fields()) + f.setAttribute('id', QVariant(id)) + f.setAttribute('name', QVariant(temporalProfile.name())) + f.setGeometry(QgsGeometry.fromPointXY(temporalProfile.coordinate())) + features.append(f) + + temporalProfile.sigDataChanged.connect(lambda: self.onUpdate(temporalProfile)) - temporalProfile.sigNameChanged.connect(lambda: self.onUpdate(temporalProfile)) + temporalProfile.sigNameChanged.connect(lambda: self.onUpdateName(temporalProfile)) i += 1 + self.mLocations.startEditing() + assert self.mLocations.dataProvider().addFeatures(features) + assert self.mLocations.commitChanges() self.endInsertRows() self.sigTemporalProfilesAdded.emit(temporalProfiles) @@ -1302,6 +1322,19 @@ class TemporalProfileCollection(QAbstractTableModel): else: return None + def temporalProfileFromFeature(self, feature): + + return None + + def temporalProfileToLocationFeature(self, tp:TemporalProfile): + + self.mLocations.selectByIds([tp.id()]) + for f in self.mLocations.selectedFeatures(): + assert isinstance(f, QgsFeature) + return f + + return None + def id(self, temporalProfile): """ Returns the id of an TemporalProfile @@ -1429,9 +1462,26 @@ class TemporalProfileCollection(QAbstractTableModel): if tp in self.mTemporalProfiles: idx0 = self.tp2idx(tp) - idx1 = self.createIndex(idx0.row(), self.rowCount()) + idx1 = self.createIndex(idx0.row(), self.columnCount()) self.dataChanged.emit(idx0, idx1, [Qt.DisplayRole]) + + + def onUpdateName(self, tp): + assert isinstance(tp, TemporalProfile) + + if tp in self.mTemporalProfiles: + idx0 = self.tp2idx(tp) + c = self.mColumNames.index(self.mcnName) + idx = self.createIndex(idx0.row(), c) + self.dataChanged.emit(idx, idx, [Qt.DisplayRole]) + + f = self.temporalProfileToLocationFeature(tp) + + if isinstance(f, QgsFeature): + f.setAttribute('name', tp.name()) + + def sort(self, col, order): if self.rowCount() == 0: return @@ -1540,7 +1590,7 @@ if __name__ == '__main__': qgsApp = utils.initQgisApplication() DEBUG = False - w = TemporalProfilePlotStyle3DWidget() + w = TemporalProfile2DPlotStyle() w.show() print(w.plotStyle())