Skip to content

Commit

Permalink
Use actions and menus instead of buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
BugLight committed Nov 16, 2020
1 parent 31e182d commit a08d96c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
30 changes: 17 additions & 13 deletions src/candiagnostictool.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#include "candiagnostictool.h"

#include "deviceerrorview.h"
#include <QMenuBar>

#include <deviceerrorview.h>

CanDiagnosticTool::CanDiagnosticTool(QWidget* parent) : QMainWindow(parent) {
setFont(QFont("Arial", 12));
setLocale(QLocale(QLocale::Russian, QLocale::Russia));

searchAction = new QAction(u8"Обнаружить устройство", this);
readAction = new QAction(u8"Прочитать ошибки", this);
resetAction = new QAction(u8"Очистить ошибки", this);

fileMenu = menuBar()->addMenu(u8"Файл");

diagnosticMenu = menuBar()->addMenu(u8"Диагностика");
diagnosticMenu->addAction(searchAction);
diagnosticMenu->addAction(readAction);
diagnosticMenu->addAction(resetAction);

central = new QWidget(this);
setCentralWidget(central);

Expand All @@ -19,24 +32,15 @@ CanDiagnosticTool::CanDiagnosticTool(QWidget* parent) : QMainWindow(parent) {
canBusView = new CanBusView(leftColumn);
leftColumnLayout->addWidget(canBusView);

buttonSearch = new QPushButton(u8"Обнаружить устройство", leftColumn);
leftColumnLayout->addWidget(buttonSearch);

buttonRead = new QPushButton(u8"Прочитать ошибки", leftColumn);
leftColumnLayout->addWidget(buttonRead);

buttonReset = new QPushButton(u8"Очистить ошибки", leftColumn);
leftColumnLayout->addWidget(buttonReset);

diagnosticView = new DiagnosticView(central);
mainLayout->addWidget(diagnosticView, 0, 1);

connect(canBusView, &CanBusView::BusConnected, diagnosticView,
&DiagnosticView::SetCanBusDevice);
connect(buttonSearch, &QPushButton::clicked, diagnosticView,
connect(searchAction, &QAction::triggered, diagnosticView,
&DiagnosticView::SearchDevice);
connect(buttonRead, &QPushButton::clicked, diagnosticView,
connect(readAction, &QAction::triggered, diagnosticView,
&DiagnosticView::ReadErrors);
connect(buttonReset, &QPushButton::clicked, diagnosticView,
connect(resetAction, &QAction::triggered, diagnosticView,
&DiagnosticView::ResetErrors);
}
11 changes: 7 additions & 4 deletions src/candiagnostictool.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include <QAction>
#include <QGridLayout>
#include <QPushButton>
#include <QMenu>
#include <QVBoxLayout>
#include <QtWidgets/QMainWindow>
#include <QWidget>
Expand All @@ -16,12 +17,14 @@ class CanDiagnosticTool : public QMainWindow {
CanDiagnosticTool(QWidget* parent = Q_NULLPTR);

private:
QAction* readAction;
QAction* resetAction;
QAction* searchAction;
CanBusView* canBusView;
DiagnosticView* diagnosticView;
QGridLayout* mainLayout;
QPushButton* buttonRead;
QPushButton* buttonReset;
QPushButton* buttonSearch;
QMenu* fileMenu;
QMenu* diagnosticMenu;
QVBoxLayout* leftColumnLayout;
QWidget* central;
QWidget* leftColumn;
Expand Down

0 comments on commit a08d96c

Please sign in to comment.