def testRectangle(self): rect = QgsReferencedRectangle(QgsRectangle(0.0, 1.0, 20.0, 10.0), QgsCoordinateReferenceSystem('epsg:3111')) self.assertEqual(rect.xMinimum(), 0.0) self.assertEqual(rect.yMinimum(), 1.0) self.assertEqual(rect.xMaximum(), 20.0) self.assertEqual(rect.yMaximum(), 10.0) self.assertEqual(rect.crs().authid(), 'EPSG:3111') rect.setCrs(QgsCoordinateReferenceSystem('epsg:28356')) self.assertEqual(rect.crs().authid(), 'EPSG:28356') # in variant v = QVariant(QgsReferencedRectangle(QgsRectangle(1.0, 2.0, 3.0, 4.0), QgsCoordinateReferenceSystem('epsg:3111'))) self.assertEqual(v.value().xMinimum(), 1.0) self.assertEqual(v.value().yMinimum(), 2.0) self.assertEqual(v.value().xMaximum(), 3.0) self.assertEqual(v.value().yMaximum(), 4.0) self.assertEqual(v.value().crs().authid(), 'EPSG:3111') # to rectangle r = QgsRectangle(rect) self.assertEqual(r.xMinimum(), 0.0) self.assertEqual(r.yMinimum(), 1.0) self.assertEqual(r.xMaximum(), 20.0) self.assertEqual(r.yMaximum(), 10.0) # test that QgsReferencedRectangle IS a QgsRectangle r2 = QgsRectangle(5, 6, 30, 40) r2.combineExtentWith(rect) self.assertEqual(r2.xMinimum(), 0.0) self.assertEqual(r2.yMinimum(), 1.0) self.assertEqual(r2.xMaximum(), 30.0) self.assertEqual(r2.yMaximum(), 40.0)
def setExtent(self, extent): if extent is not None: tokens = extent.split(' ')[0].split(',') ext = QgsRectangle(float(tokens[0]), float(tokens[2]), float(tokens[1]), float(tokens[3])) if len(tokens) > 1: self.extent = QgsReferencedRectangle(ext, QgsCoordinateReferenceSystem(tokens[1][1:-1])) else: self.extent = ext self.pixelSizeChanged()
def setLayers(self, layersData): self.extent = QgsRectangle() self.layers = [] for row in layersData.split(';'): v = row.split('::~::') # need to keep a reference until interpolation is complete layer = QgsProcessingUtils.variantToSource(v[0], self.context) if layer: self.layers.append(layer) bbox = layer.sourceExtent() if self.extent.isEmpty(): self.extent = bbox else: self.extent.combineExtentWith(bbox) self.pixelSizeChanged()
def __init__(self): super(PixelSizeWidget, self).__init__(None) self.setupUi(self) self.context = dataobjects.createContext() self.extent = QgsRectangle() self.layers = [] self.mCellXSpinBox.setShowClearButton(False) self.mCellYSpinBox.setShowClearButton(False) self.mRowsSpinBox.setShowClearButton(False) self.mColumnsSpinBox.setShowClearButton(False) self.mCellYSpinBox.valueChanged.connect(self.mCellXSpinBox.setValue) self.mCellXSpinBox.valueChanged.connect(self.pixelSizeChanged) self.mRowsSpinBox.valueChanged.connect(self.rowsChanged) self.mColumnsSpinBox.valueChanged.connect(self.columnsChanged)
class PixelSizeWidget(BASE, WIDGET): def __init__(self): super(PixelSizeWidget, self).__init__(None) self.setupUi(self) self.context = dataobjects.createContext() self.extent = QgsRectangle() self.layers = [] self.mCellXSpinBox.setShowClearButton(False) self.mCellYSpinBox.setShowClearButton(False) self.mRowsSpinBox.setShowClearButton(False) self.mColumnsSpinBox.setShowClearButton(False) self.mCellYSpinBox.valueChanged.connect(self.mCellXSpinBox.setValue) self.mCellXSpinBox.valueChanged.connect(self.pixelSizeChanged) self.mRowsSpinBox.valueChanged.connect(self.rowsChanged) self.mColumnsSpinBox.valueChanged.connect(self.columnsChanged) def setLayers(self, layersData): self.extent = QgsRectangle() self.layers = [] for row in layersData.split(';'): v = row.split('::~::') # need to keep a reference until interpolation is complete layer = QgsProcessingUtils.variantToSource(v[0], self.context) if layer: self.layers.append(layer) bbox = layer.sourceExtent() if self.extent.isEmpty(): self.extent = bbox else: self.extent.combineExtentWith(bbox) self.pixelSizeChanged() def setExtent(self, extent): if extent is not None: tokens = extent.split(' ')[0].split(',') ext = QgsRectangle(float(tokens[0]), float(tokens[2]), float(tokens[1]), float(tokens[3])) if len(tokens) > 1: self.extent = QgsReferencedRectangle(ext, QgsCoordinateReferenceSystem(tokens[1][1:-1])) else: self.extent = ext self.pixelSizeChanged() def pixelSizeChanged(self): cell_size = self.mCellXSpinBox.value() if cell_size <= 0: return self.mCellYSpinBox.blockSignals(True) self.mCellYSpinBox.setValue(cell_size) self.mCellYSpinBox.blockSignals(False) rows = max(round(self.extent.height() / cell_size) + 1, 1) cols = max(round(self.extent.width() / cell_size) + 1, 1) self.mRowsSpinBox.blockSignals(True) self.mRowsSpinBox.setValue(rows) self.mRowsSpinBox.blockSignals(False) self.mColumnsSpinBox.blockSignals(True) self.mColumnsSpinBox.setValue(cols) self.mColumnsSpinBox.blockSignals(False) def rowsChanged(self): rows = self.mRowsSpinBox.value() if rows <= 0: return cell_size = self.extent.height() / rows cols = max(round(self.extent.width() / cell_size) + 1, 1) self.mColumnsSpinBox.blockSignals(True) self.mColumnsSpinBox.setValue(cols) self.mColumnsSpinBox.blockSignals(False) for w in [self.mCellXSpinBox, self.mCellYSpinBox]: w.blockSignals(True) w.setValue(cell_size) w.blockSignals(False) def columnsChanged(self): cols = self.mColumnsSpinBox.value() if cols < 2: return cell_size = self.extent.width() / (cols - 1) rows = max(round(self.extent.height() / cell_size), 1) self.mRowsSpinBox.blockSignals(True) self.mRowsSpinBox.setValue(rows) self.mRowsSpinBox.blockSignals(False) for w in [self.mCellXSpinBox, self.mCellYSpinBox]: w.blockSignals(True) w.setValue(cell_size) w.blockSignals(False) def setValue(self, value): try: numeric_value = float(value) except: return False self.mCellXSpinBox.setValue(numeric_value) self.mCellYSpinBox.setValue(numeric_value) return True def value(self): return self.mCellXSpinBox.value()
def useCanvasExtent(self): self.setValueFromRect( QgsReferencedRectangle( iface.mapCanvas().extent(), iface.mapCanvas().mapSettings().destinationCrs()))
def testRectangle(self): rect = QgsReferencedRectangle( QgsRectangle(0.0, 1.0, 20.0, 10.0), QgsCoordinateReferenceSystem('epsg:3111')) self.assertEqual(rect.xMinimum(), 0.0) self.assertEqual(rect.yMinimum(), 1.0) self.assertEqual(rect.xMaximum(), 20.0) self.assertEqual(rect.yMaximum(), 10.0) self.assertEqual(rect.crs().authid(), 'EPSG:3111') rect.setCrs(QgsCoordinateReferenceSystem('epsg:28356')) self.assertEqual(rect.crs().authid(), 'EPSG:28356') # in variant v = QVariant( QgsReferencedRectangle(QgsRectangle(1.0, 2.0, 3.0, 4.0), QgsCoordinateReferenceSystem('epsg:3111'))) self.assertEqual(v.value().xMinimum(), 1.0) self.assertEqual(v.value().yMinimum(), 2.0) self.assertEqual(v.value().xMaximum(), 3.0) self.assertEqual(v.value().yMaximum(), 4.0) self.assertEqual(v.value().crs().authid(), 'EPSG:3111') # to rectangle r = QgsRectangle(rect) self.assertEqual(r.xMinimum(), 0.0) self.assertEqual(r.yMinimum(), 1.0) self.assertEqual(r.xMaximum(), 20.0) self.assertEqual(r.yMaximum(), 10.0) # test that QgsReferencedRectangle IS a QgsRectangle r2 = QgsRectangle(5, 6, 30, 40) r2.combineExtentWith(rect) self.assertEqual(r2.xMinimum(), 0.0) self.assertEqual(r2.yMinimum(), 1.0) self.assertEqual(r2.xMaximum(), 30.0) self.assertEqual(r2.yMaximum(), 40.0)
class PixelSizeWidget(BASE, WIDGET): def __init__(self): super(PixelSizeWidget, self).__init__(None) self.setupUi(self) self.context = dataobjects.createContext() self.extent = QgsRectangle() self.layers = [] self.mCellXSpinBox.setShowClearButton(False) self.mCellYSpinBox.setShowClearButton(False) self.mRowsSpinBox.setShowClearButton(False) self.mColumnsSpinBox.setShowClearButton(False) self.mCellYSpinBox.valueChanged.connect(self.mCellXSpinBox.setValue) self.mCellXSpinBox.valueChanged.connect(self.pixelSizeChanged) self.mRowsSpinBox.valueChanged.connect(self.rowsChanged) self.mColumnsSpinBox.valueChanged.connect(self.columnsChanged) def setLayers(self, layersData): self.extent = QgsRectangle() self.layers = [] for row in layersData.split(';'): v = row.split('::~::') # need to keep a reference until interpolation is complete layer = QgsProcessingUtils.variantToSource(v[0], self.context) if layer: self.layers.append(layer) bbox = layer.sourceExtent() if self.extent.isEmpty(): self.extent = bbox else: self.extent.combineExtentWith(bbox) self.pixelSizeChanged() def setExtent(self, extent): if extent is not None: tokens = extent.split(' ')[0].split(',') ext = QgsRectangle(float(tokens[0]), float(tokens[2]), float(tokens[1]), float(tokens[3])) if len(tokens) > 1: self.extent = QgsReferencedRectangle( ext, QgsCoordinateReferenceSystem(tokens[1][1:-1])) else: self.extent = ext self.pixelSizeChanged() def pixelSizeChanged(self): cell_size = self.mCellXSpinBox.value() if cell_size <= 0: return self.mCellYSpinBox.blockSignals(True) self.mCellYSpinBox.setValue(cell_size) self.mCellYSpinBox.blockSignals(False) rows = max(round(self.extent.height() / cell_size) + 1, 1) cols = max(round(self.extent.width() / cell_size) + 1, 1) self.mRowsSpinBox.blockSignals(True) self.mRowsSpinBox.setValue(rows) self.mRowsSpinBox.blockSignals(False) self.mColumnsSpinBox.blockSignals(True) self.mColumnsSpinBox.setValue(cols) self.mColumnsSpinBox.blockSignals(False) def rowsChanged(self): rows = self.mRowsSpinBox.value() if rows <= 0: return cell_size = self.extent.height() / rows cols = max(round(self.extent.width() / cell_size) + 1, 1) self.mColumnsSpinBox.blockSignals(True) self.mColumnsSpinBox.setValue(cols) self.mColumnsSpinBox.blockSignals(False) for w in [self.mCellXSpinBox, self.mCellYSpinBox]: w.blockSignals(True) w.setValue(cell_size) w.blockSignals(False) def columnsChanged(self): cols = self.mColumnsSpinBox.value() if cols < 2: return cell_size = self.extent.width() / (cols - 1) rows = max(round(self.extent.height() / cell_size), 1) self.mRowsSpinBox.blockSignals(True) self.mRowsSpinBox.setValue(rows) self.mRowsSpinBox.blockSignals(False) for w in [self.mCellXSpinBox, self.mCellYSpinBox]: w.blockSignals(True) w.setValue(cell_size) w.blockSignals(False) def setValue(self, value): try: numeric_value = float(value) except: return False self.mCellXSpinBox.setValue(numeric_value) self.mCellYSpinBox.setValue(numeric_value) return True def value(self): return self.mCellXSpinBox.value()
def useLayerExtent(self): dlg = LayerSelectionDialog(self) if dlg.exec_(): layer = dlg.selected_layer() self.setValueFromRect( QgsReferencedRectangle(layer.extent(), layer.crs()))
def testQgsReferencedRectangleRepr(self): r = QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4), QgsCoordinateReferenceSystem('EPSG:4326')) self.assertEqual(r.__repr__(), '<QgsReferencedRectangle: 1 2, 3 4 (EPSG:4326)>')
def testFullExtent(self): p = QgsProject() p.setCrs(QgsCoordinateReferenceSystem('EPSG:3857')) self.assertTrue(p.viewSettings().fullExtent().isNull()) p.viewSettings().setPresetFullExtent( QgsReferencedRectangle(QgsRectangle(1, 2, 3, 4), QgsCoordinateReferenceSystem("EPSG:4326"))) self.assertAlmostEqual(p.viewSettings().fullExtent().xMinimum(), 111319, -1) self.assertAlmostEqual(p.viewSettings().fullExtent().xMaximum(), 333958, -1) self.assertAlmostEqual(p.viewSettings().fullExtent().yMinimum(), 222684, -1) self.assertAlmostEqual(p.viewSettings().fullExtent().yMaximum(), 445640, -1) self.assertEqual(p.viewSettings().fullExtent().crs().authid(), 'EPSG:3857') # add layers shapefile = os.path.join(TEST_DATA_DIR, 'polys.shp') layer = QgsVectorLayer(shapefile, 'Polys', 'ogr') p.addMapLayer(layer) # no change, because preset extent is set self.assertAlmostEqual(p.viewSettings().fullExtent().xMinimum(), 111319, -1) self.assertAlmostEqual(p.viewSettings().fullExtent().xMaximum(), 333958, -1) self.assertAlmostEqual(p.viewSettings().fullExtent().yMinimum(), 222684, -1) self.assertAlmostEqual(p.viewSettings().fullExtent().yMaximum(), 445640, -1) self.assertEqual(p.viewSettings().fullExtent().crs().authid(), 'EPSG:3857') # remove preset extent p.viewSettings().setPresetFullExtent(QgsReferencedRectangle()) # extent should come from layers self.assertAlmostEqual(p.viewSettings().fullExtent().xMinimum(), -13238432, -2) self.assertAlmostEqual(p.viewSettings().fullExtent().xMaximum(), -9327461, -2) self.assertAlmostEqual(p.viewSettings().fullExtent().yMinimum(), 2815417, -2) self.assertAlmostEqual(p.viewSettings().fullExtent().yMaximum(), 5897492, -2) self.assertEqual(p.viewSettings().fullExtent().crs().authid(), 'EPSG:3857') # add another layer shapefile = os.path.join(TEST_DATA_DIR, 'lines.shp') layer = QgsVectorLayer(shapefile, 'Lines', 'ogr') p.addMapLayer(layer) self.assertAlmostEqual(p.viewSettings().fullExtent().xMinimum(), -13238432, -2) self.assertAlmostEqual(p.viewSettings().fullExtent().xMaximum(), -9164115, -2) self.assertAlmostEqual(p.viewSettings().fullExtent().yMinimum(), 2657217, -2) self.assertAlmostEqual(p.viewSettings().fullExtent().yMaximum(), 5897492, -2) self.assertEqual(p.viewSettings().fullExtent().crs().authid(), 'EPSG:3857') # add a layer with a different crs layer = QgsVectorLayer( "Point?crs=EPSG:3857&field=fldtxt:string&field=fldint:integer", "x", "memory") p.addMapLayer(layer) f = QgsFeature() f.setAttributes(["test", 123]) f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(-8164115, 5997492))) layer.startEditing() layer.addFeatures([f]) layer.commitChanges() self.assertAlmostEqual(p.viewSettings().fullExtent().xMinimum(), -13238432, -2) self.assertAlmostEqual(p.viewSettings().fullExtent().xMaximum(), -8164115, -2) self.assertAlmostEqual(p.viewSettings().fullExtent().yMinimum(), 2657217, -2) self.assertAlmostEqual(p.viewSettings().fullExtent().yMaximum(), 5997492, -2) self.assertEqual(p.viewSettings().fullExtent().crs().authid(), 'EPSG:3857')
def testRenameGroup(self): """ Test renaming a bookmark group """ p = QgsProject() manager = QgsBookmarkManager(p) # add a bunch of bookmarks b = QgsBookmark() b.setId('1') b.setName('b1') b.setGroup('g1') b.setExtent( QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41), QgsCoordinateReferenceSystem('EPSG:4326'))) b2 = QgsBookmark() b2.setId('2') b2.setName('b2') b2.setGroup('g1') b2.setExtent( QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42), QgsCoordinateReferenceSystem('EPSG:4326'))) b3 = QgsBookmark() b3.setId('3') b3.setName('b3') b3.setGroup('g3') b3.setExtent( QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43), QgsCoordinateReferenceSystem('EPSG:4326'))) manager.addBookmark(b) manager.addBookmark(b2) manager.addBookmark(b3) changed_spy = QSignalSpy(manager.bookmarkChanged) self.assertEqual([b.group() for b in manager.bookmarks()], ['g1', 'g1', 'g3']) manager.renameGroup('xxxxx', 'yyyyy') self.assertEqual([b.group() for b in manager.bookmarks()], ['g1', 'g1', 'g3']) self.assertEqual(len(changed_spy), 0) manager.renameGroup('', '') self.assertEqual([b.group() for b in manager.bookmarks()], ['g1', 'g1', 'g3']) self.assertEqual(len(changed_spy), 0) manager.renameGroup('g1', 'g2') self.assertEqual([b.group() for b in manager.bookmarks()], ['g2', 'g2', 'g3']) self.assertEqual(len(changed_spy), 2) self.assertEqual(changed_spy[0][0], '1') self.assertEqual(changed_spy[1][0], '2') manager.renameGroup('g3', 'g2') self.assertEqual([b.group() for b in manager.bookmarks()], ['g2', 'g2', 'g2']) self.assertEqual(len(changed_spy), 3) self.assertEqual(changed_spy[2][0], '3') manager.renameGroup('g2', 'g') self.assertEqual([b.group() for b in manager.bookmarks()], ['g', 'g', 'g']) self.assertEqual(len(changed_spy), 6) self.assertEqual(changed_spy[3][0], '1') self.assertEqual(changed_spy[4][0], '2') self.assertEqual(changed_spy[5][0], '3')
def testExportImport(self): p = QgsProject() manager = QgsBookmarkManager.createProjectBasedManager(p) manager2 = QgsBookmarkManager.createProjectBasedManager(p) manager3 = QgsBookmarkManager.createProjectBasedManager(p) tmpDir = QTemporaryDir() tmpFile = "{}/bookmarks.xml".format(tmpDir.path()) # no managers self.assertTrue(QgsBookmarkManager.exportToFile(tmpFile, [])) self.assertTrue(manager3.importFromFile(tmpFile)) self.assertFalse(manager3.bookmarks()) # no bookmarks self.assertTrue(QgsBookmarkManager.exportToFile(tmpFile, [manager])) self.assertTrue(manager3.importFromFile(tmpFile)) self.assertFalse(manager3.bookmarks()) # add a bunch of bookmarks b = QgsBookmark() b.setId('1') b.setName('b1') b.setGroup('g1') b.setExtent( QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41), QgsCoordinateReferenceSystem('EPSG:4326'))) b2 = QgsBookmark() b2.setId('2') b2.setName('b2') b2.setExtent( QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42), QgsCoordinateReferenceSystem('EPSG:4326'))) b3 = QgsBookmark() b3.setId('3') b3.setName('b3') b3.setGroup('g1') b3.setExtent( QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43), QgsCoordinateReferenceSystem('EPSG:4326'))) manager.addBookmark(b) manager.addBookmark(b2) manager2.addBookmark(b3) # export one manager's bookmarks self.assertTrue(QgsBookmarkManager.exportToFile(tmpFile, [manager])) self.assertTrue(manager3.importFromFile(tmpFile)) self.assertEqual([(b.name(), b.extent()) for b in manager3.bookmarks()], [(b.name(), b.extent()) for b in [b, b2]]) manager3.clear() # export both manager's bookmarks self.assertTrue( QgsBookmarkManager.exportToFile(tmpFile, [manager, manager2])) self.assertTrue(manager3.importFromFile(tmpFile)) self.assertEqual([(b.name(), b.extent()) for b in manager3.bookmarks()], [(b.name(), b.extent()) for b in [b, b2, b3]]) manager3.clear() # restrict to group self.assertTrue( QgsBookmarkManager.exportToFile(tmpFile, [manager, manager2], 'g1')) self.assertTrue(manager3.importFromFile(tmpFile)) self.assertEqual([(b.name(), b.extent()) for b in manager3.bookmarks()], [(b.name(), b.extent()) for b in [b, b3]])
def testBookmarkModel(self): p = QgsProject() project_manager = QgsBookmarkManager.createProjectBasedManager(p) app_manager = QgsBookmarkManager() # initially no bookmarks model = QgsBookmarkManagerModel(app_manager, project_manager) self.assertEqual(model.rowCount(), 0) self.assertEqual(model.columnCount(), 8) self.assertFalse(model.data(model.index(-1, 0))) self.assertFalse(model.data(model.index(1, 0))) self.assertFalse(model.data(model.index(0, 0))) self.assertFalse( model.data(model.index(0, 0), QgsBookmarkManagerModel.RoleName)) self.assertEqual(model.headerData(0, Qt.Horizontal), 'Name') self.assertEqual(model.headerData(9, Qt.Horizontal), 10) self.assertEqual(model.headerData(-1, Qt.Horizontal), 0) self.assertFalse(model.setData(model.index(-1, 0), 4, Qt.EditRole)) self.assertFalse(model.setData(model.index(0, 0), 4, Qt.EditRole)) self.assertFalse( int(model.flags(model.index(0, 0)) & Qt.ItemIsEnabled)) self.assertFalse( int(model.flags(model.index(0, 0)) & Qt.ItemIsEditable)) # add some bookmarks b = QgsBookmark() b.setId('1') b.setGroup('group 1') b.setName('b1') b.setExtent( QgsReferencedRectangle(QgsRectangle(11, 21, 31, 41), QgsCoordinateReferenceSystem('EPSG:4326'))) b2 = QgsBookmark() b2.setId('2') b2.setGroup('group 2') b2.setName('b2') b2.setExtent( QgsReferencedRectangle(QgsRectangle(12, 22, 32, 42), QgsCoordinateReferenceSystem('EPSG:4326'))) app_manager.addBookmark(b) app_manager.addBookmark(b2) self.assertEqual(model.rowCount(), 2) self.assertFalse(model.data(model.index(-1, 0))) self.assertEqual(model.data(model.index(0, 0)), 'b1') self.assertEqual(model.data(model.index(0, 1)), 'group 1') self.assertEqual(model.data(model.index(0, 2)), 11.0) self.assertEqual(model.data(model.index(0, 3)), 21.0) self.assertEqual(model.data(model.index(0, 4)), 31.0) self.assertEqual(model.data(model.index(0, 5)), 41.0) self.assertEqual(model.data(model.index(0, 6)), 'EPSG:4326') self.assertEqual(model.data(model.index(0, 7)), None) self.assertEqual(model.data(model.index(0, 7), Qt.CheckStateRole), Qt.Unchecked) self.assertEqual( model.data(model.index(0, 0), QgsBookmarkManagerModel.RoleName), 'b1') self.assertEqual( model.data(model.index(0, 0), QgsBookmarkManagerModel.RoleGroup), 'group 1') id = model.data(model.index(0, 0), QgsBookmarkManagerModel.RoleId) self.assertEqual(app_manager.bookmarkById(id).name(), 'b1') self.assertEqual( model.data(model.index(0, 0), QgsBookmarkManagerModel.RoleExtent), app_manager.bookmarkById(id).extent()) self.assertEqual(model.data(model.index(1, 0)), 'b2') self.assertEqual(model.data(model.index(1, 1)), 'group 2') self.assertEqual(model.data(model.index(1, 2)), 12.0) self.assertEqual(model.data(model.index(1, 3)), 22.0) self.assertEqual(model.data(model.index(1, 4)), 32.0) self.assertEqual(model.data(model.index(1, 5)), 42.0) self.assertEqual(model.data(model.index(1, 6)), 'EPSG:4326') self.assertEqual(model.data(model.index(1, 7)), None) self.assertEqual(model.data(model.index(1, 7), Qt.CheckStateRole), Qt.Unchecked) self.assertEqual( model.data(model.index(1, 0), QgsBookmarkManagerModel.RoleName), 'b2') self.assertEqual( model.data(model.index(1, 0), QgsBookmarkManagerModel.RoleGroup), 'group 2') id = model.data(model.index(1, 0), QgsBookmarkManagerModel.RoleId) self.assertEqual(app_manager.bookmarkById(id).name(), 'b2') self.assertEqual( model.data(model.index(1, 0), QgsBookmarkManagerModel.RoleExtent), app_manager.bookmarkById(id).extent()) self.assertFalse(model.data(model.index(2, 0))) self.assertFalse(model.setData(model.index(-1, 0), 4, Qt.EditRole)) self.assertTrue( model.setData(model.index(0, 0), 'new name', Qt.EditRole)) self.assertEqual(model.data(model.index(0, 0)), 'new name') self.assertEqual(app_manager.bookmarks()[0].name(), 'new name') self.assertTrue( model.setData(model.index(1, 1), 'new group', Qt.EditRole)) self.assertEqual(model.data(model.index(1, 1)), 'new group') self.assertEqual(app_manager.bookmarks()[1].group(), 'new group') self.assertTrue(model.setData(model.index(0, 2), 1, Qt.EditRole)) self.assertEqual(model.data(model.index(0, 2)), 1.0) self.assertEqual(app_manager.bookmarks()[0].extent().xMinimum(), 1.0) self.assertTrue(model.setData(model.index(0, 3), 2, Qt.EditRole)) self.assertEqual(model.data(model.index(0, 3)), 2.0) self.assertEqual(app_manager.bookmarks()[0].extent().yMinimum(), 2.0) self.assertTrue(model.setData(model.index(0, 4), 3, Qt.EditRole)) self.assertEqual(model.data(model.index(0, 4)), 3.0) self.assertEqual(app_manager.bookmarks()[0].extent().xMaximum(), 3.0) self.assertTrue(model.setData(model.index(0, 5), 4, Qt.EditRole)) self.assertEqual(model.data(model.index(0, 5)), 4.0) self.assertEqual(app_manager.bookmarks()[0].extent().yMaximum(), 4.0) self.assertFalse(model.setData(model.index(2, 0), 4, Qt.EditRole)) self.assertTrue(int(model.flags(model.index(0, 0)) & Qt.ItemIsEnabled)) self.assertTrue( int(model.flags(model.index(0, 0)) & Qt.ItemIsEditable)) self.assertTrue( int(model.flags(model.index(0, 7)) & Qt.ItemIsUserCheckable)) self.assertTrue( int(model.flags(model.index(1, 7)) & Qt.ItemIsUserCheckable)) self.assertTrue(int(model.flags(model.index(1, 0)) & Qt.ItemIsEnabled)) self.assertTrue( int(model.flags(model.index(1, 0)) & Qt.ItemIsEditable)) self.assertFalse( int(model.flags(model.index(2, 0)) & Qt.ItemIsEnabled)) self.assertFalse( int(model.flags(model.index(2, 0)) & Qt.ItemIsEditable)) self.assertFalse( int(model.flags(model.index(2, 7)) & Qt.ItemIsUserCheckable)) # add bookmark to project manager b3 = QgsBookmark() b3.setId('3') b3.setName('b3') b3.setGroup('group 3') b3.setExtent( QgsReferencedRectangle(QgsRectangle(32, 32, 33, 43), QgsCoordinateReferenceSystem('EPSG:28355'))) project_manager.addBookmark(b3) self.assertEqual(model.rowCount(), 3) self.assertFalse(model.data(model.index(-1, 0))) self.assertEqual(model.data(model.index(0, 0)), 'new name') self.assertEqual(model.data(model.index(0, 1)), 'group 1') self.assertEqual(model.data(model.index(0, 2)), 1.0) self.assertEqual(model.data(model.index(0, 3)), 2.0) self.assertEqual(model.data(model.index(0, 4)), 3.0) self.assertEqual(model.data(model.index(0, 5)), 4.0) self.assertEqual(model.data(model.index(0, 6)), 'EPSG:4326') self.assertEqual(model.data(model.index(0, 7)), None) self.assertEqual(model.data(model.index(0, 7), Qt.CheckStateRole), Qt.Unchecked) self.assertEqual(model.data(model.index(1, 0)), 'b2') self.assertEqual(model.data(model.index(1, 1)), 'new group') self.assertEqual(model.data(model.index(1, 2)), 12.0) self.assertEqual(model.data(model.index(1, 3)), 22.0) self.assertEqual(model.data(model.index(1, 4)), 32.0) self.assertEqual(model.data(model.index(1, 5)), 42.0) self.assertEqual(model.data(model.index(1, 6)), 'EPSG:4326') self.assertEqual(model.data(model.index(1, 7)), None) self.assertEqual(model.data(model.index(1, 7), Qt.CheckStateRole), Qt.Unchecked) self.assertEqual(model.data(model.index(2, 0)), 'b3') self.assertEqual(model.data(model.index(2, 1)), 'group 3') self.assertEqual(model.data(model.index(2, 2)), 32.0) self.assertEqual(model.data(model.index(2, 3)), 32.0) self.assertEqual(model.data(model.index(2, 4)), 33.0) self.assertEqual(model.data(model.index(2, 5)), 43.0) self.assertEqual(model.data(model.index(2, 6)), 'EPSG:28355') self.assertEqual(model.data(model.index(2, 7)), None) self.assertEqual(model.data(model.index(2, 7), Qt.CheckStateRole), Qt.Checked) self.assertEqual( model.data(model.index(2, 0), QgsBookmarkManagerModel.RoleName), 'b3') self.assertEqual( model.data(model.index(2, 0), QgsBookmarkManagerModel.RoleGroup), 'group 3') id = model.data(model.index(2, 0), QgsBookmarkManagerModel.RoleId) self.assertEqual(project_manager.bookmarkById(id).name(), 'b3') self.assertEqual( model.data(model.index(2, 0), QgsBookmarkManagerModel.RoleExtent), project_manager.bookmarkById(id).extent()) self.assertFalse(model.data(model.index(3, 0))) self.assertTrue( model.setData(model.index(2, 0), 'new name 2', Qt.EditRole)) self.assertEqual(model.data(model.index(2, 0)), 'new name 2') self.assertEqual(project_manager.bookmarks()[0].name(), 'new name 2') self.assertTrue( model.setData(model.index(2, 1), 'new group', Qt.EditRole)) self.assertEqual(model.data(model.index(2, 1)), 'new group') self.assertEqual(project_manager.bookmarks()[0].group(), 'new group') self.assertTrue(model.setData(model.index(2, 2), 1, Qt.EditRole)) self.assertEqual(model.data(model.index(2, 2)), 1.0) self.assertEqual(project_manager.bookmarks()[0].extent().xMinimum(), 1.0) self.assertTrue(model.setData(model.index(2, 3), 2, Qt.EditRole)) self.assertEqual(model.data(model.index(2, 3)), 2.0) self.assertEqual(project_manager.bookmarks()[0].extent().yMinimum(), 2.0) self.assertTrue(model.setData(model.index(2, 4), 3, Qt.EditRole)) self.assertEqual(model.data(model.index(2, 4)), 3.0) self.assertEqual(project_manager.bookmarks()[0].extent().xMaximum(), 3.0) self.assertTrue(model.setData(model.index(2, 5), 4, Qt.EditRole)) self.assertEqual(model.data(model.index(2, 5)), 4.0) self.assertEqual(project_manager.bookmarks()[0].extent().yMaximum(), 4.0) self.assertFalse(model.setData(model.index(3, 0), 4, Qt.EditRole)) self.assertTrue(int(model.flags(model.index(0, 0)) & Qt.ItemIsEnabled)) self.assertTrue( int(model.flags(model.index(0, 0)) & Qt.ItemIsEditable)) self.assertTrue( int(model.flags(model.index(0, 7)) & Qt.ItemIsUserCheckable)) self.assertTrue( int(model.flags(model.index(1, 7)) & Qt.ItemIsUserCheckable)) self.assertTrue(int(model.flags(model.index(1, 0)) & Qt.ItemIsEnabled)) self.assertTrue( int(model.flags(model.index(1, 0)) & Qt.ItemIsEditable)) self.assertTrue(int(model.flags(model.index(2, 0)) & Qt.ItemIsEnabled)) self.assertTrue( int(model.flags(model.index(2, 0)) & Qt.ItemIsEditable)) self.assertTrue( int(model.flags(model.index(2, 7)) & Qt.ItemIsUserCheckable)) self.assertFalse( int(model.flags(model.index(3, 0)) & Qt.ItemIsEnabled)) self.assertFalse( int(model.flags(model.index(3, 0)) & Qt.ItemIsEditable)) self.assertFalse( int(model.flags(model.index(3, 7)) & Qt.ItemIsUserCheckable)) # try transferring bookmark from app->project self.assertTrue( model.setData(model.index(1, 7), Qt.Checked, Qt.CheckStateRole)) self.assertEqual([b.name() for b in project_manager.bookmarks()], ['new name 2', 'b2']) self.assertEqual([b.name() for b in app_manager.bookmarks()], ['new name']) self.assertFalse( model.setData(model.index(1, 7), Qt.Checked, Qt.CheckStateRole)) # try transferring bookmark from project->app self.assertTrue( model.setData(model.index(1, 7), Qt.Unchecked, Qt.CheckStateRole)) self.assertEqual([b.name() for b in project_manager.bookmarks()], ['b2']) self.assertEqual([b.name() for b in app_manager.bookmarks()], ['new name', 'new name 2']) self.assertFalse( model.setData(model.index(1, 7), Qt.Unchecked, Qt.CheckStateRole)) # remove rows model.removeRows(0, 1) self.assertEqual([b.name() for b in project_manager.bookmarks()], ['b2']) self.assertEqual([b.name() for b in app_manager.bookmarks()], ['new name 2']) model.removeRows(0, 2) self.assertEqual([b.name() for b in project_manager.bookmarks()], []) self.assertEqual([b.name() for b in app_manager.bookmarks()], [])