diff --git a/Lesson_5/Task_1/.gitignore b/Lesson_5/Task_1/.gitignore new file mode 100644 index 0000000..4a0b530 --- /dev/null +++ b/Lesson_5/Task_1/.gitignore @@ -0,0 +1,74 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* +CMakeLists.txt.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/Lesson_5/Task_1/Task_1.pro b/Lesson_5/Task_1/Task_1.pro new file mode 100644 index 0000000..53cd580 --- /dev/null +++ b/Lesson_5/Task_1/Task_1.pro @@ -0,0 +1,28 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++17 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + automobile.cpp \ + childautomobile.cpp \ + main.cpp \ + autoservice.cpp + +HEADERS += \ + automobile.h \ + autoservice.h \ + childautomobile.h + +FORMS += \ + autoservice.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/Lesson_5/Task_1/automobile.cpp b/Lesson_5/Task_1/automobile.cpp new file mode 100644 index 0000000..86a8734 --- /dev/null +++ b/Lesson_5/Task_1/automobile.cpp @@ -0,0 +1,5 @@ +#include "automobile.h" + +Automobile::Automobile(QObject *parent) + : QObject{parent} +{} diff --git a/Lesson_5/Task_1/automobile.h b/Lesson_5/Task_1/automobile.h new file mode 100644 index 0000000..3781821 --- /dev/null +++ b/Lesson_5/Task_1/automobile.h @@ -0,0 +1,27 @@ +#ifndef AUTOMOBILE_H +#define AUTOMOBILE_H + +#include + +class Automobile : public QObject +{ + Q_OBJECT +public: + explicit Automobile(QObject *parent = nullptr); + QString getManufacturer() { return m_manufacturer; } + void setManufacturer(QString manufacturer) { m_manufacturer = manufacturer; } + float getPrice() { return m_price; } + void setPrice(int price) { m_price = price; } + QString getType() { return m_type; } + void setType(QString type) { m_type = type; } + +signals: + +protected: + float m_price; + QString m_type; +private: + QString m_manufacturer; +}; + +#endif // AUTOMOBILE_H diff --git a/Lesson_5/Task_1/autoservice.cpp b/Lesson_5/Task_1/autoservice.cpp new file mode 100644 index 0000000..2f30b1e --- /dev/null +++ b/Lesson_5/Task_1/autoservice.cpp @@ -0,0 +1,81 @@ +#include "autoservice.h" +#include "ui_autoservice.h" +#include + +AutoService::AutoService(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::AutoService) +{ + ui->setupUi(this); + connect(ui->b_filter, &QPushButton::clicked, this, &AutoService::filter); + connect(ui->l_automobiles, &QListWidget::itemClicked, this, &AutoService::select); + + ChildAutomobile* automobile1 = new ChildAutomobile(); + ChildAutomobile* automobile2 = new ChildAutomobile(); + ChildAutomobile* automobile3 = new ChildAutomobile(); + + automobile1->setManufacturer("Rolls-Royce"); + automobile1->setModel((QString)"Wraith"); + automobile1->setType("Coupé"); + automobile1->setPrice(343350); + automobile1->setSeats(4); + automobile1->setColor(QColor(19, 25, 98)); + + automobile2->setManufacturer("Hyundai"); + automobile2->setModel((QString)"Santa Cruz"); + automobile2->setType("Pickup truck"); + automobile2->setPrice(26900); + automobile2->setSeats(5); + automobile2->setColor(QColor(143, 144, 139)); + + automobile3->setManufacturer("JAC"); + automobile3->setModel((QString)"Shuailing T6"); + automobile3->setType("Pickup truck"); + automobile3->setPrice(13778); + automobile3->setSeats(5); + automobile3->setColor(QColor(221, 225, 228)); + + m_automobiles.append(automobile1); + m_automobiles.append(automobile2); + m_automobiles.append(automobile3); +} + +AutoService::~AutoService() +{ + delete ui; +} + +void AutoService::filter() +{ + ui->l_automobiles->clear(); + ui->e_selected->clear(); + for (int automobile = 0; automobile < m_automobiles.size(); ++automobile) { + if ( + ((ui->e_manufacturer->text().isEmpty()) || m_automobiles[automobile]->getManufacturer() == ui->e_manufacturer->text()) + && ((ui->e_type->text().isEmpty()) || (m_automobiles[automobile]->getType() == ui->e_type->text())) + && ((ui->e_price->text().isEmpty()) || (m_automobiles[automobile]->getPrice() >= ui->e_price->text().toInt())) + ) + addAutomobile(m_automobiles[automobile]); + + } +} + +void AutoService::addAutomobile(ChildAutomobile * automobile) +{ + ui->l_automobiles->addItem(automobile->getManufacturer() + " " + automobile->getModel()); +} + +void AutoService::select(QListWidgetItem * item) +{ + for (int automobile = 0; automobile < m_automobiles.size(); ++automobile) { + if (item->text() == (m_automobiles[automobile]->getManufacturer() + " " + m_automobiles[automobile]->getModel())) { + ui->e_selected->setText("Manufacturer: " + m_automobiles[automobile]->getManufacturer() + "\n" + + "Model: " + m_automobiles[automobile]->getModel() + "\n" + + "Type: " + m_automobiles[automobile]->getType() + "\n" + + "Seats: " + QString::number(m_automobiles[automobile]->getSeats()) + "\n" + + "Color: " + m_automobiles[automobile]->getColor().name() + "\n" + + "Price: " + QString::number(m_automobiles[automobile]->getPrice())); + break; + } + } +} diff --git a/Lesson_5/Task_1/autoservice.h b/Lesson_5/Task_1/autoservice.h new file mode 100644 index 0000000..383e975 --- /dev/null +++ b/Lesson_5/Task_1/autoservice.h @@ -0,0 +1,31 @@ +#ifndef AUTOSERVICE_H +#define AUTOSERVICE_H + +#include +#include "childautomobile.h" +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class AutoService; +} +QT_END_NAMESPACE + +class AutoService : public QMainWindow +{ + Q_OBJECT + +public: + AutoService(QWidget *parent = nullptr); + ~AutoService(); + +private slots: + void filter(); + +private: + Ui::AutoService *ui; + QVector m_automobiles; + void addAutomobile(ChildAutomobile*); + void select(QListWidgetItem *); +}; +#endif // AUTOSERVICE_H diff --git a/Lesson_5/Task_1/autoservice.ui b/Lesson_5/Task_1/autoservice.ui new file mode 100644 index 0000000..1fc02fb --- /dev/null +++ b/Lesson_5/Task_1/autoservice.ui @@ -0,0 +1,143 @@ + + + AutoService + + + + 0 + 0 + 800 + 600 + + + + AutoService + + + + + + + Filter: + + + + + + + + + + + 19 + + + + + Manufacturer + + + + + + + false + + + + + + + + + 76 + + + + + Type + + + + + + + + + + + + 43 + + + + + Max price + + + + + + + + + + + + + + Filter + + + + + + + + + + + Automobile list: + + + + + + + + + + + + + + Selected automobile: + + + + + + + true + + + + + + + + + + + 0 + 0 + 800 + 25 + + + + + + + + diff --git a/Lesson_5/Task_1/childautomobile.cpp b/Lesson_5/Task_1/childautomobile.cpp new file mode 100644 index 0000000..4f99bf4 --- /dev/null +++ b/Lesson_5/Task_1/childautomobile.cpp @@ -0,0 +1,5 @@ +#include "childautomobile.h" + +ChildAutomobile::ChildAutomobile(QObject *parent) + : Automobile{parent} +{} diff --git a/Lesson_5/Task_1/childautomobile.h b/Lesson_5/Task_1/childautomobile.h new file mode 100644 index 0000000..f203de4 --- /dev/null +++ b/Lesson_5/Task_1/childautomobile.h @@ -0,0 +1,29 @@ +#ifndef CHILDAUTOMOBILE_H +#define CHILDAUTOMOBILE_H + +#include +#include +#include + +class ChildAutomobile : public Automobile +{ + Q_OBJECT +public: + explicit ChildAutomobile(QObject *parent = nullptr); + QString getModel() { return m_model; } + void setModel(QString model) { m_model = model; } + int getSeats() { return m_seats; } + void setSeats(int seats) { m_seats = seats; } + QColor getColor() { return m_color; } + void setColor(QColor color) { m_color = color; } + + void setModel(const char *); +signals: + +private: + QString m_model; + int m_seats; + QColor m_color; +}; + +#endif // CHILDAUTOMOBILE_H diff --git a/Lesson_5/Task_1/main.cpp b/Lesson_5/Task_1/main.cpp new file mode 100644 index 0000000..26645e1 --- /dev/null +++ b/Lesson_5/Task_1/main.cpp @@ -0,0 +1,11 @@ +#include "autoservice.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + AutoService w; + w.show(); + return a.exec(); +}