第三讲主要实现了矢量要素的标注(Label)功能,代码是在第二节的基础上进行修改
第一步:在qgis2.h文件中,增加相关头文件,主要三个头文件如下:qgslabel.h,qgslabelattribute.h qgsfield.h文件
具体代码如下所示:
#include <QtGui/QMainWindow>
#include "ui_qgis2.h"
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrenderer.h>
#include <qgsmapcanvas.h>
#include <qgsvectorlayer.h>
#include <qgsmaptool.h>
#include <QtGui/QVBoxLayout>
#include <qgsmaplayerregistry.h>
#include <QtGui/QToolBar>
#include<qgsmaptoolpan.h>
#include <qgsmaptoolzoom.h>
#include <qgsvectordataprovider.h>
//标注添加的头文件
#include <qgslabel.h>//一个用来渲染label的类,label渲染属性可以直接指定或者根据属性值动态指定
#include <qgslabelattributes.h>//此类保存了label渲染所需要的属性值,比如字大小,位置等属性
#include <qgsfield.h>//此类用于将字段包装成属性表或者是