From f86062a15d5f8f83ac008bddb907dc3ff24c2fad Mon Sep 17 00:00:00 2001 From: tsl115 Date: Wed, 22 Nov 2023 13:21:03 +0800 Subject: [PATCH] feat: DTK changed-template and DTK changed-symbol Replacing Qt controls with DTK --- src/plugins/symbol/mainframe/symbolkeeper.cpp | 2 +- .../symbol/mainframe/symboltreeview.cpp | 39 +++++++++++-------- src/plugins/symbol/mainframe/symboltreeview.h | 9 +++-- src/plugins/symbol/symbol.cpp | 2 +- .../symbol/transceiver/symbolreceiver.h | 2 +- src/plugins/template/wizard/detailwidget.cpp | 5 ++- src/plugins/template/wizard/detailwidget.h | 5 ++- src/plugins/template/wizard/maindialog.cpp | 2 +- src/plugins/template/wizard/maindialog.h | 4 +- 9 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/plugins/symbol/mainframe/symbolkeeper.cpp b/src/plugins/symbol/mainframe/symbolkeeper.cpp index 716d12f65..3cb091676 100644 --- a/src/plugins/symbol/mainframe/symbolkeeper.cpp +++ b/src/plugins/symbol/mainframe/symbolkeeper.cpp @@ -7,7 +7,7 @@ #include "common/common.h" #include "services/builder/builderservice.h" -#include +#include namespace { static SymbolTreeView *tree{nullptr}; diff --git a/src/plugins/symbol/mainframe/symboltreeview.cpp b/src/plugins/symbol/mainframe/symboltreeview.cpp index b6cdf360e..ce1084ae4 100644 --- a/src/plugins/symbol/mainframe/symboltreeview.cpp +++ b/src/plugins/symbol/mainframe/symboltreeview.cpp @@ -10,40 +10,45 @@ #include "symboldelegate.h" +#include +#include +#include + #include #include #include +DWIDGET_USE_NAMESPACE class SymbolTreeViewPrivate { friend class SymbolTreeView; SymbolTreeView *const q; QModelIndex selIndex; QFileSystemModel *model {nullptr}; - SymbolDelegate *delegate; - QMenu *getFileLineMenu(const QString &filePath); + SymbolDelegate *delegate = {nullptr}; + DMenu *getFileLineMenu(const QString &filePath); SymbolTreeViewPrivate(SymbolTreeView *qq): q(qq){} }; -SymbolTreeView::SymbolTreeView(QWidget *parent) - : QTreeView(parent) +SymbolTreeView::SymbolTreeView(DWidget *parent) + : DTreeView(parent) , d (new SymbolTreeViewPrivate(this)) { d->model = new SymbolModel(); d->delegate = new SymbolDelegate; - QTreeView::setModel(d->model); - QTreeView::setItemDelegate(d->delegate); + DTreeView::setModel(d->model); + DTreeView::setItemDelegate(d->delegate); setContextMenuPolicy(Qt::CustomContextMenu); - setEditTriggers(QTreeView::NoEditTriggers); //节点不能编辑 - setSelectionBehavior(QTreeView::SelectRows); //一次选中整行 - setSelectionMode(QTreeView::SingleSelection); //单选,配合上面的整行就是一次选单行 + setEditTriggers(DTreeView::NoEditTriggers); //节点不能编辑 + setSelectionBehavior(DTreeView::SelectRows); //一次选中整行 + setSelectionMode(DTreeView::SingleSelection); //单选,配合上面的整行就是一次选单行 setFocusPolicy(Qt::NoFocus); //去掉鼠标移到节点上时的虚线框 header()->setVisible(false); - QObject::connect(this, &QTreeView::doubleClicked, + QObject::connect(this, &DTreeView::doubleClicked, this, &SymbolTreeView::doDoubleClieked, Qt::UniqueConnection); - QObject::connect(this, &QTreeView::customContextMenuRequested, + QObject::connect(this, &DTreeView::customContextMenuRequested, this, &SymbolTreeView::doContextMenu, Qt::UniqueConnection); } @@ -74,7 +79,7 @@ void SymbolTreeView::doContextMenu(const QPoint &point) setCurrentIndex(index); - QMenu *contextMenu{nullptr}; + DMenu *contextMenu{nullptr}; if (d->model->isDir(index)) { QString filePath = d->model->filePath(index); QDir currDir(filePath); @@ -85,7 +90,7 @@ void SymbolTreeView::doContextMenu(const QPoint &point) if (files.contains(SymbolPri::definitionsFileName) || files.contains(SymbolPri::declaredFileName)) { - contextMenu = new QMenu(this); + contextMenu = new DMenu(this); } if (files.contains(SymbolPri::definitionsFileName)) { @@ -108,23 +113,23 @@ void SymbolTreeView::doContextMenu(const QPoint &point) } if (contextMenu) { - contextMenu->exec(QWidget::mapToGlobal(point)); + contextMenu->exec(DWidget::mapToGlobal(point)); delete contextMenu; } } -QMenu *SymbolTreeViewPrivate::getFileLineMenu(const QString &filePath) +DMenu *SymbolTreeViewPrivate::getFileLineMenu(const QString &filePath) { QFile file(filePath); if (!file.open(QFile::ReadOnly)) { qCritical() << file.errorString(); } - QMenu *defMenu = nullptr; + DMenu *defMenu = nullptr; QStringList lines = QString(file.readAll()).split('\n'); for (auto line : lines) { if (!line.isEmpty()) { if (!defMenu) { - defMenu = new QMenu(); + defMenu = new DMenu(); } QAction *action = new QAction(defMenu); QObject::connect(action, &QAction::triggered, [=](){ diff --git a/src/plugins/symbol/mainframe/symboltreeview.h b/src/plugins/symbol/mainframe/symboltreeview.h index 4a186f691..e7df64981 100644 --- a/src/plugins/symbol/mainframe/symboltreeview.h +++ b/src/plugins/symbol/mainframe/symboltreeview.h @@ -7,16 +7,17 @@ #include "services/project/projectservice.h" -#include +#include -class QStandardItem; +DWIDGET_USE_NAMESPACE +class DStandardItem; class SymbolTreeViewPrivate; -class SymbolTreeView : public QTreeView +class SymbolTreeView : public DTreeView { Q_OBJECT SymbolTreeViewPrivate *const d; public: - explicit SymbolTreeView(QWidget *parent = nullptr); + explicit SymbolTreeView(DWidget *parent = nullptr); virtual ~SymbolTreeView(); void setRootPath(const QString &filePath); diff --git a/src/plugins/symbol/symbol.cpp b/src/plugins/symbol/symbol.cpp index 69ab17c7c..a2282177d 100644 --- a/src/plugins/symbol/symbol.cpp +++ b/src/plugins/symbol/symbol.cpp @@ -12,11 +12,11 @@ #include "base/abstractwidget.h" #include "services/window/windowservice.h" #include "services/symbol/symbolservice.h" +#include #include #include #include -#include using namespace dpfservice; void Symbol::initialize() diff --git a/src/plugins/symbol/transceiver/symbolreceiver.h b/src/plugins/symbol/transceiver/symbolreceiver.h index 51d169447..53bb10102 100644 --- a/src/plugins/symbol/transceiver/symbolreceiver.h +++ b/src/plugins/symbol/transceiver/symbolreceiver.h @@ -9,7 +9,7 @@ #include -class QStandardItem; +class DStandardItem; class SymbolReceiver : public dpf::EventHandler, dpf::AutoEventHandlerRegister { diff --git a/src/plugins/template/wizard/detailwidget.cpp b/src/plugins/template/wizard/detailwidget.cpp index f0b4ad063..ef68d3df2 100644 --- a/src/plugins/template/wizard/detailwidget.cpp +++ b/src/plugins/template/wizard/detailwidget.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -29,14 +30,14 @@ class DetailWidgetPrivate WizardInfo wizardInfo; }; -DetailWidget::DetailWidget(QWidget *parent) +DetailWidget::DetailWidget(DWidget *parent) : DScrollArea(parent) , d(new DetailWidgetPrivate()) { } -DetailWidget::DetailWidget(const QString &templatePath, QWidget *parent) +DetailWidget::DetailWidget(const QString &templatePath, DWidget *parent) : DScrollArea(parent) , d(new DetailWidgetPrivate()) { diff --git a/src/plugins/template/wizard/detailwidget.h b/src/plugins/template/wizard/detailwidget.h index 22d75db89..5f6153998 100644 --- a/src/plugins/template/wizard/detailwidget.h +++ b/src/plugins/template/wizard/detailwidget.h @@ -9,6 +9,7 @@ #include +DWIDGET_USE_NAMESPACE using namespace templateMgr; class DetailWidgetPrivate; @@ -16,8 +17,8 @@ class DetailWidget : public DTK_WIDGET_NAMESPACE::DScrollArea { Q_OBJECT public: - explicit DetailWidget(QWidget *parent = nullptr); - DetailWidget(const QString &templatePath, QWidget *parent = nullptr); + explicit DetailWidget(DWidget *parent = nullptr); + DetailWidget(const QString &templatePath, DWidget *parent = nullptr); ~DetailWidget() override; bool getGenParams(PojectGenParam ¶m); diff --git a/src/plugins/template/wizard/maindialog.cpp b/src/plugins/template/wizard/maindialog.cpp index 3f76cc02b..39f84c4b4 100644 --- a/src/plugins/template/wizard/maindialog.cpp +++ b/src/plugins/template/wizard/maindialog.cpp @@ -33,7 +33,7 @@ class MainDialogPrivate DWidget *blankWidget = nullptr; }; -MainDialog::MainDialog(QWidget *parent) +MainDialog::MainDialog(DWidget *parent) : DAbstractDialog(parent) , d(new MainDialogPrivate()) { diff --git a/src/plugins/template/wizard/maindialog.h b/src/plugins/template/wizard/maindialog.h index 5123b41b8..30f5e845b 100644 --- a/src/plugins/template/wizard/maindialog.h +++ b/src/plugins/template/wizard/maindialog.h @@ -7,7 +7,9 @@ #include "projectgenerate.h" #include +#include +DWIDGET_USE_NAMESPACE using namespace templateMgr; class MainDialogPrivate; @@ -15,7 +17,7 @@ class MainDialog : public DTK_WIDGET_NAMESPACE::DAbstractDialog { Q_OBJECT public: - explicit MainDialog(QWidget *parent = nullptr); + explicit MainDialog(DWidget *parent = nullptr); ~MainDialog(); signals: