Add Lesson 5 Task 1
This commit is contained in:
parent
3fcab8541d
commit
70cc836f05
10 changed files with 434 additions and 0 deletions
74
Lesson_5/Task_1/.gitignore
vendored
Normal file
74
Lesson_5/Task_1/.gitignore
vendored
Normal file
|
@ -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
|
||||
|
28
Lesson_5/Task_1/Task_1.pro
Normal file
28
Lesson_5/Task_1/Task_1.pro
Normal file
|
@ -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
|
5
Lesson_5/Task_1/automobile.cpp
Normal file
5
Lesson_5/Task_1/automobile.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include "automobile.h"
|
||||
|
||||
Automobile::Automobile(QObject *parent)
|
||||
: QObject{parent}
|
||||
{}
|
27
Lesson_5/Task_1/automobile.h
Normal file
27
Lesson_5/Task_1/automobile.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef AUTOMOBILE_H
|
||||
#define AUTOMOBILE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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
|
81
Lesson_5/Task_1/autoservice.cpp
Normal file
81
Lesson_5/Task_1/autoservice.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include "autoservice.h"
|
||||
#include "ui_autoservice.h"
|
||||
#include <QDebug>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
31
Lesson_5/Task_1/autoservice.h
Normal file
31
Lesson_5/Task_1/autoservice.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef AUTOSERVICE_H
|
||||
#define AUTOSERVICE_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "childautomobile.h"
|
||||
#include <QListWidget>
|
||||
|
||||
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<ChildAutomobile *> m_automobiles;
|
||||
void addAutomobile(ChildAutomobile*);
|
||||
void select(QListWidgetItem *);
|
||||
};
|
||||
#endif // AUTOSERVICE_H
|
143
Lesson_5/Task_1/autoservice.ui
Normal file
143
Lesson_5/Task_1/autoservice.ui
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AutoService</class>
|
||||
<widget class="QMainWindow" name="AutoService">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>AutoService</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Filter:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>19</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Manufacturer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="e_manufacturer">
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>76</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="e_type"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>43</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Max price</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="e_price"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="b_filter">
|
||||
<property name="text">
|
||||
<string>Filter</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Automobile list:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="l_automobiles"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Selected automobile:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="e_selected">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
5
Lesson_5/Task_1/childautomobile.cpp
Normal file
5
Lesson_5/Task_1/childautomobile.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include "childautomobile.h"
|
||||
|
||||
ChildAutomobile::ChildAutomobile(QObject *parent)
|
||||
: Automobile{parent}
|
||||
{}
|
29
Lesson_5/Task_1/childautomobile.h
Normal file
29
Lesson_5/Task_1/childautomobile.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef CHILDAUTOMOBILE_H
|
||||
#define CHILDAUTOMOBILE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QColor>
|
||||
#include <automobile.h>
|
||||
|
||||
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
|
11
Lesson_5/Task_1/main.cpp
Normal file
11
Lesson_5/Task_1/main.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "autoservice.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
AutoService w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
Reference in a new issue