Skip to content

Commit

Permalink
feat: DTK changed-template and DTK changed-symbol
Browse files Browse the repository at this point in the history
Replacing Qt controls with DTK
  • Loading branch information
JWWTSL committed Nov 22, 2023
1 parent 871fede commit f86062a
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/plugins/symbol/mainframe/symbolkeeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "common/common.h"
#include "services/builder/builderservice.h"

#include <QStandardItem>
#include <DStandardItem>

namespace {
static SymbolTreeView *tree{nullptr};
Expand Down
39 changes: 22 additions & 17 deletions src/plugins/symbol/mainframe/symboltreeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,45 @@

#include "symboldelegate.h"

#include <DMenu>
#include <DTreeView>
#include <DWidget>

#include <QHeaderView>
#include <QDirIterator>
#include <QStandardItemModel>

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){}

Check warning on line 30 in src/plugins/symbol/mainframe/symboltreeview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'SymbolTreeViewPrivate' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
};

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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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)) {
Expand All @@ -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, [=](){
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/symbol/mainframe/symboltreeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

#include "services/project/projectservice.h"

#include <QTreeView>
#include <DTreeView>

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);

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/symbol/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#include "base/abstractwidget.h"
#include "services/window/windowservice.h"
#include "services/symbol/symbolservice.h"
#include <DTreeView>

#include <QProcess>
#include <QAction>
#include <QLabel>
#include <QTreeView>

using namespace dpfservice;
void Symbol::initialize()
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/symbol/transceiver/symbolreceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <framework/framework.h>

class QStandardItem;
class DStandardItem;
class SymbolReceiver : public dpf::EventHandler,
dpf::AutoEventHandlerRegister<SymbolReceiver>
{
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/template/wizard/detailwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <DMessageBox>
#include <DFileDialog>
#include <DLineEdit>
#include <DWidget>

#include <QVBoxLayout>
#include <QPainter>
Expand All @@ -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())
{
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/template/wizard/detailwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@

#include <DScrollArea>

DWIDGET_USE_NAMESPACE
using namespace templateMgr;

class DetailWidgetPrivate;
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);

Check warning on line 21 in src/plugins/template/wizard/detailwidget.h

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'DetailWidget' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
~DetailWidget() override;

bool getGenParams(PojectGenParam &param);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/template/wizard/maindialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MainDialogPrivate
DWidget *blankWidget = nullptr;
};

MainDialog::MainDialog(QWidget *parent)
MainDialog::MainDialog(DWidget *parent)
: DAbstractDialog(parent)
, d(new MainDialogPrivate())
{
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/template/wizard/maindialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

#include "projectgenerate.h"
#include <DAbstractDialog>
#include <DWidget>

DWIDGET_USE_NAMESPACE
using namespace templateMgr;

class MainDialogPrivate;
class MainDialog : public DTK_WIDGET_NAMESPACE::DAbstractDialog
{
Q_OBJECT
public:
explicit MainDialog(QWidget *parent = nullptr);
explicit MainDialog(DWidget *parent = nullptr);
~MainDialog();

signals:
Expand Down

0 comments on commit f86062a

Please sign in to comment.