目录
上一篇文章《QGIS+qt 二次开发 移动要素》中提到了如何实现要素移动的功能,本文来说一下要素的缩放功能怎么实现。
打开QGIS,先导入一张shp图层文件:
观察到要素工具栏里有缩放要素按钮,按下激活要素缩放功能。
然后和移动要素一样,鼠标点击图层中的要素,再移动鼠标,会有缩放调整效果的展示,如下:
有了之前移动要素的实现经验,我们还是先来看一下源码,在qgsmaptoolmovefeature.cpp的目录下,很快就能看见一个叫qgsmaptoolscalefeature.cpp的文件,打开看一下。
qgsmaptoolscalefeature.cpp
- /***************************************************************************
- qgsmaptoolscalefeature.cpp - map tool for scaling features by mouse drag
- ---------------------
- Date : December 2020
- Copyright : (C) 2020 by roya0045
- Contact : ping me on github
- ***************************************************************************
- * *
- * 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. *
- * *
- ***************************************************************************/
-
- #include
- #include
- #include
- #include
- #include
-
- #include
- #include
-
- #include "qgsadvanceddigitizingdockwidget.h"
- #include "qgsmaptoolscalefeature.h"
- #include "qgsfeatureiterator.h"
- #include "qgsgeometry.h"
- #include "qgslogger.h"
- #include "qgsmapcanvas.h"
- #include "qgsrubberband.h"
- #include "qgsvectorlayer.h"
- #include "qgstolerance.h"
- #include "qgisapp.h"
- #include "qgsspinbox.h"
- #include "qgsdoublespinbox.h"
- #include "qgssnapindicator.h"
- #include "qgsmapmouseevent.h"
-
-
- QgsScaleMagnetWidget::QgsScaleMagnetWidget( const QString &label, QWidget *parent )
- : QWidget( parent )
- {
- mLayout = new QHBoxLayout( this );
- mLayout->setContentsM