Edit Lesson 5 Task 2

This commit is contained in:
Stanislav Mykhailenko 2024-07-22 18:45:54 +03:00
parent 4c94b72e20
commit 571578b022
GPG key ID: 1E95E66A9C9D6A36

View file

@ -1,6 +1,5 @@
#include "autoservice.h" #include "autoservice.h"
#include "ui_autoservice.h" #include "ui_autoservice.h"
#include <QDebug>
AutoService::AutoService(QWidget *parent) AutoService::AutoService(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
@ -26,10 +25,13 @@ void AutoService::filter()
bool typeEmpty = ui->e_type->text().isEmpty(); bool typeEmpty = ui->e_type->text().isEmpty();
bool priceEmpty = ui->e_price->text().isEmpty(); bool priceEmpty = ui->e_price->text().isEmpty();
for (int automobile = 0; automobile < m_automobiles.size(); ++automobile) { for (int automobile = 0; automobile < m_automobiles.size(); ++automobile) {
bool manufacturerMatch = m_automobiles[automobile]->getManufacturer() == ui->e_manufacturer->text();
bool typeMatch = m_automobiles[automobile]->getType().contains(ui->e_type->text());
bool priceMatch = m_automobiles[automobile]->getPrice() <= ui->e_price->text().toInt();
if ( if (
(manufacturerEmpty || m_automobiles[automobile]->getManufacturer() == ui->e_manufacturer->text()) (manufacturerEmpty || manufacturerMatch)
&& (typeEmpty || (m_automobiles[automobile]->getType().contains(ui->e_type->text()))) && (typeEmpty || typeMatch)
&& (priceEmpty || (m_automobiles[automobile]->getPrice() <= ui->e_price->text().toInt())) && (priceEmpty || priceMatch)
) )
addAutomobile(m_automobiles[automobile]); addAutomobile(m_automobiles[automobile]);