本文记录在QGIS中集成MxDraw控件的方法。
一、安装MxDraw
参见笔者博文“FreeCAD二次开发:集成二维CAD控件MxDraw”所述的安装方法。
二、编译安装QGIS
参见笔者博文"Windows 10下编译安装QGIS"所述的编译安装方法。
二、集成方法
2.1 添加MxDrawView.ui文件
按照QGIS的管理,Qt ui文件可放到src/ui目录及其子目录下。因此,可将MxDrawView.ui拷贝到src/ui/gd目录下,并修改src/ui/CMakeLists.txt,
# ...
if (BUILD_GDGIS)
file(GLOB GD_UIS "${CMAKE_CURRENT_SOURCE_DIR}/gd/*.ui")
endif()
if (BUILD_WITH_QT6)
QT6_WRAP_UI(QGIS_UIS_H
${QGIS_UIS}
${SYMBOLLAYER_UIS}
${EDITORWIDGET_UIS}
${PAINTEFFECT_UIS}
${PROCESSING_UIS}
${AUTH_UIS}
${RASTER_UIS}
${STYLEDOCK_UIS}
${LAYOUT_UIS}
${MESH_UIS}
${POINTCLOUD_UIS}
${_3D_UIS}
${CALLOUT_UIS}
${LABELING_UIS}
${NUMERICFORMAT_UIS}
${ATTRIBUTEFORMCONFIG_UIS}
${GEOREFERENCER_UIS}
${ANNOTATION_UIS}
${SENSOR_UIS}
${GD_UIS}
)
else()
QT5_WRAP_UI(QGIS_UIS_H
${QGIS_UIS}
${SYMBOLLAYER_UIS}
${EDITORWIDGET_UIS}
${PAINTEFFECT_UIS}
${PROCESSING_UIS}
${AUTH_UIS}
${RASTER_UIS}
${STYLEDOCK_UIS}
${LAYOUT_UIS}
${MESH_UIS}
${POINTCLOUD_UIS}
${_3D_UIS}
${CALLOUT_UIS}
${LABELING_UIS}
${NUMERICFORMAT_UIS}
${ATTRIBUTEFORMCONFIG_UIS}
${GEOREFERENCER_UIS}
${ANNOTATION_UIS}
${SENSOR_UIS}
${GD_UIS}
)
endif()
# ...
2.2 添加MxDrawView类
界面相关的代码放到src/gui目录下,将MxDrawView.h、MxDrawView.cpp拷贝到src/gui/gd目录下,并修改CMakeLists.txt文件
# ...
# sources for GDGIS
if (BUILD_GDGIS)
set(GD_HDR_FILES
gd/MxDrawview.h
)
set(GD_SRC_FILES
gd/MxDrawview.cpp
)
SOURCE_GROUP("gd" FILES ${GD_HDR_FILES} ${GD_SRC_FILES})
set(QGIS_GUI_HDRS
${QGIS_GUI_HDRS}
${GD_HDR_FILES}
)
set(QGIS_GUI_SRCS
${QGIS_GUI_SRCS}
${GD_SRC_FILES}
)
endif()
# ...
# Link AxBase,AxContainer for GDGIS
if (BUILD_GDGIS)
find_package(${QT_VERSION_BASE} COMPONENTS AxBase AxContainer REQUIRED)
target_link_libraries(qgis_gui
${QT_VERSION_BASE}::AxBase
${QT_VERSION_BASE}::AxContainer
)
endif()
2.3 实现MxDrawView类
仿照MxDrwa自带例子TestQtMxDraw,实现MxDrawView
#ifndef gd_MxDrawView_H
#define gd_MxDrawView_H
#include "qgis_gui.h"
#include <QMainWindow>
namespace gd
{
class Ui_MxDrawView;
class GUI_EXPORT MxDrawView : public QMainWindow
{
Q_OBJECT
public:
MxDrawView(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
~MxDrawView();
protected Q_SLOTS:
private slots:
void on_pushButton_clicked();
void on_axWidget_ImplementCommandEvent(int iCommandId);
protected:
Ui_MxDrawView* ui;
};
} // namespace gd
#endif // gd_MxDrawView_H
#include "MxDrawView.h"
#include "ui_MxDrawView.h"
using namespace gd;
MxDrawView::MxDrawView(QWidget* parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags),
ui(new Ui_MxDrawView)
{
// Set up ui
ui->setupUi(this);
connect(ui->axWidget, SIGNAL(ImplementCommandEvent(int)), this, SLOT(on_axWidget_ImplementCommandEvent(int)));
}
MxDrawView::~MxDrawView()
{
}
void MxDrawView::on_pushButton_clicked()
{
// 执行控件自定义命令函数,命令的id为2,这个id用户可以自己取任意数,可以理解为是给执行的命令一个编号.
ui->axWidget->dynamicCall("DoCommand(const qint32&)", 2);
}
void MxDrawView::on_axWidget_ImplementCommandEvent(int iCommandId)
{
if (iCommandId == 2)
{
// 调用控件打开函数,打开H:盘的1.dwg文件。
std::string filename = "H:\\1.dwg";
//ui->axWidget->dynamicCall("OpenDwgFile(const QString&)", "H:\\1.dwg");
ui->axWidget->dynamicCall("OpenDwgFile(const QString&)", QString::fromUtf8(filename.c_str()));
}
2.4 嵌入MxDrawView窗体
修改src/app/qgisapp.cpp,创建并嵌入MxFrawView窗体,
QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers, bool skipVersionCheck, const QString &rootProfileLocation, const QString &activeProfile, QWidget *parent, Qt::WindowFlags fl )
: QMainWindow( parent, fl )
, mSplash( splash )
{
//...
mCentralContainer = new QStackedWidget;
mCentralContainer->insertWidget(0, mMapCanvas);
#ifdef GDGIS
QTabWidget* tabWidget = new QTabWidget;
tabWidget->addTab(mCentralContainer, "Map");
tabWidget->addTab(new gd::MxDrawView(), "CAD");
centralLayout->addWidget(tabWidget, 0, 0, 2, 1);
#else
mCentralContainer->insertWidget(1, mWelcomePage);
centralLayout->addWidget(mCentralContainer, 0, 0, 2, 1);
#endif
mInfoBar->raise();
//...
}
网络资料
FreeCAD二次开发:集成二维CAD控件MxDrawhttps://blog.csdn.net/qq_26221775/article/details/121192465?spm=1001.2014.3001.5502
Windows 10下编译安装QGIShttps://blog.csdn.net/qq_26221775/article/details/122792445?spm=1001.2014.3001.5502MxDrawhttps://www.mxdraw.com/文章来源:https://www.toymoban.com/news/detail-610775.html
QGIShttps://www.qgis.org/en/site/文章来源地址https://www.toymoban.com/news/detail-610775.html
到了这里,关于QGIS二次开发:集成二维CAD控件MxDraw的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!