Commit 13c49262a6c372a38b7093283544008fadd85706
1 parent
1a00617f
Building the GUI
Showing
7 changed files
with
172 additions
and
2 deletions
CMakeLists.txt
| ... | ... | @@ -23,12 +23,20 @@ include_directories( SYSTEM |
| 23 | 23 | include(compiler) |
| 24 | 24 | |
| 25 | 25 | set(SRC_LIST |
| 26 | + ${CMAKE_SOURCE_DIR}/src/calcprime.cpp | |
| 27 | + ${CMAKE_SOURCE_DIR}/src/calcprime_form.cpp | |
| 26 | 28 | ${CMAKE_SOURCE_DIR}/src/main.cpp |
| 27 | 29 | ) |
| 28 | 30 | |
| 31 | +include(qtuic) | |
| 32 | +create_ui( SRC_LIST UIC_LIST | |
| 33 | + ${CMAKE_SOURCE_DIR}/src/calcprime_form.ui | |
| 34 | +) | |
| 35 | + | |
| 29 | 36 | include(qtmoc) |
| 30 | 37 | create_mocs( SRC_LIST MOC_LIST |
| 31 | - # ${CMAKE_SOURCE_DIR}/<moc_header.h> | |
| 38 | + ${CMAKE_SOURCE_DIR}/src/calcprime.h | |
| 39 | + ${CMAKE_SOURCE_DIR}/src/calcprime_form.h | |
| 32 | 40 | ) |
| 33 | 41 | |
| 34 | 42 | add_executable( ${PROJECT_NAME} | ... | ... |
src/calcprime.h
| 1 | +#pragma once | |
| 2 | + | |
| 3 | +#include "calcprime_form.h" | |
| 4 | +#include <QObject> | |
| 5 | + | |
| 6 | +class CalcPrime : public QObject | |
| 7 | +{ | |
| 8 | + Q_OBJECT | |
| 9 | + | |
| 10 | +public: | |
| 11 | + explicit CalcPrime(QObject *parent = nullptr); | |
| 12 | + | |
| 13 | +private: | |
| 14 | + bool m_bCalculate; | |
| 15 | + uint64_t m_curValue; | |
| 16 | + | |
| 17 | +signals: | |
| 18 | + void signalCurrentValue( uint64_t current_value ); | |
| 19 | + void signalPrimeNumberFound( uint64_t prime_number ); | |
| 20 | + | |
| 21 | +private slots: | |
| 22 | + void slotStartCalculation(); | |
| 23 | + void slotStopCalculation(); | |
| 24 | +}; | ... | ... |
src/calcprime_form.cpp
| 1 | +#include "calcprime_form.h" | |
| 2 | + | |
| 3 | +#include <string> | |
| 4 | +#include <QString> | |
| 5 | + | |
| 6 | +CalcPrimeForm::CalcPrimeForm(QWidget *parent) | |
| 7 | + : QWidget(parent) | |
| 8 | +{ | |
| 9 | + setupUi(this); | |
| 10 | + connectSignalsAndSlots(); | |
| 11 | +} | |
| 12 | + | |
| 13 | +void CalcPrimeForm::connectSignalsAndSlots() | |
| 14 | +{ | |
| 15 | + connect( this->cmdStartButton, &QPushButton::clicked, this, &CalcPrimeForm::slotStartButtonClicked ); | |
| 16 | + connect( this->cmdStopButton, &QPushButton::clicked, this, &CalcPrimeForm::slotStopButtonClicked ); | |
| 17 | +} | |
| 18 | + | |
| 19 | +void CalcPrimeForm::slotUpdateCurrentValue( uint64_t value ) | |
| 20 | +{ | |
| 21 | + this->currentValue->display( QString( std::to_string( value ).c_str() ) ); | |
| 22 | +} | |
| 23 | + | |
| 24 | +void CalcPrimeForm::slotAddNewPrime( uint64_t new_prime ) | |
| 25 | +{ | |
| 26 | + this->listPrimes->addItem(QString( std::to_string( new_prime ).c_str() )); | |
| 27 | +} | |
| 28 | + | |
| 29 | +void CalcPrimeForm::slotStartButtonClicked() | |
| 30 | +{ | |
| 31 | + this->cmdStartButton->setDisabled(true); | |
| 32 | + this->cmdStopButton->setDisabled(false); | |
| 33 | + emit signalStartButtonClicked(); | |
| 34 | +} | |
| 35 | + | |
| 36 | +void CalcPrimeForm::slotStopButtonClicked() | |
| 37 | +{ | |
| 38 | + this->cmdStopButton->setDisabled(true); | |
| 39 | + this->cmdStartButton->setDisabled(false); | |
| 40 | + emit signalStopButtonClicked(); | |
| 41 | +} | ... | ... |
src/calcprime_form.h
| 1 | + | |
| 2 | +#pragma once | |
| 3 | + | |
| 4 | +#include "ui_calcprime_form.h" | |
| 5 | + | |
| 6 | +class CalcPrimeForm : public QWidget, private Ui::wdgPrimeGui | |
| 7 | +{ | |
| 8 | + Q_OBJECT | |
| 9 | + | |
| 10 | +public: | |
| 11 | + explicit CalcPrimeForm(QWidget *parent = nullptr); | |
| 12 | + | |
| 13 | +private: | |
| 14 | + void connectSignalsAndSlots(); | |
| 15 | + | |
| 16 | +signals: | |
| 17 | + void signalStartButtonClicked(); | |
| 18 | + void signalStopButtonClicked(); | |
| 19 | + | |
| 20 | +public slots: | |
| 21 | + void slotUpdateCurrentValue( uint64_t value ); | |
| 22 | + void slotAddNewPrime( uint64_t new_prime ); | |
| 23 | + | |
| 24 | +private slots: | |
| 25 | + void slotStartButtonClicked(); | |
| 26 | + void slotStopButtonClicked(); | |
| 27 | +}; | ... | ... |
src/calcprime_form.ui
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<ui version="4.0"> | |
| 3 | + <class>wdgPrimeGui</class> | |
| 4 | + <widget class="QWidget" name="wdgPrimeGui"> | |
| 5 | + <property name="geometry"> | |
| 6 | + <rect> | |
| 7 | + <x>0</x> | |
| 8 | + <y>0</y> | |
| 9 | + <width>1373</width> | |
| 10 | + <height>393</height> | |
| 11 | + </rect> | |
| 12 | + </property> | |
| 13 | + <property name="windowTitle"> | |
| 14 | + <string>Calculate Primenumbers</string> | |
| 15 | + </property> | |
| 16 | + <layout class="QGridLayout" name="gridLayout"> | |
| 17 | + <item row="0" column="0"> | |
| 18 | + <layout class="QVBoxLayout" name="verticalLayout"> | |
| 19 | + <item> | |
| 20 | + <widget class="QLCDNumber" name="currentValue"> | |
| 21 | + <property name="digitCount"> | |
| 22 | + <number>30</number> | |
| 23 | + </property> | |
| 24 | + </widget> | |
| 25 | + </item> | |
| 26 | + <item> | |
| 27 | + <widget class="QListWidget" name="listPrimes"/> | |
| 28 | + </item> | |
| 29 | + <item> | |
| 30 | + <layout class="QHBoxLayout" name="horizontalLayout"> | |
| 31 | + <item> | |
| 32 | + <widget class="QPushButton" name="cmdStartButton"> | |
| 33 | + <property name="text"> | |
| 34 | + <string>Start</string> | |
| 35 | + </property> | |
| 36 | + </widget> | |
| 37 | + </item> | |
| 38 | + <item> | |
| 39 | + <spacer name="horizontalSpacer"> | |
| 40 | + <property name="orientation"> | |
| 41 | + <enum>Qt::Horizontal</enum> | |
| 42 | + </property> | |
| 43 | + <property name="sizeHint" stdset="0"> | |
| 44 | + <size> | |
| 45 | + <width>40</width> | |
| 46 | + <height>20</height> | |
| 47 | + </size> | |
| 48 | + </property> | |
| 49 | + </spacer> | |
| 50 | + </item> | |
| 51 | + <item> | |
| 52 | + <widget class="QPushButton" name="cmdStopButton"> | |
| 53 | + <property name="text"> | |
| 54 | + <string>Stop</string> | |
| 55 | + </property> | |
| 56 | + </widget> | |
| 57 | + </item> | |
| 58 | + </layout> | |
| 59 | + </item> | |
| 60 | + </layout> | |
| 61 | + </item> | |
| 62 | + </layout> | |
| 63 | + </widget> | |
| 64 | + <resources/> | |
| 65 | + <connections/> | |
| 66 | +</ui> | ... | ... |