mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-04-26 17:54:40 +00:00
added pills for app
This commit is contained in:
parent
eb18b6c969
commit
3bf106665d
66
doctor.cpp
66
doctor.cpp
@ -5,13 +5,75 @@
|
||||
* of this license document, but changing it is not allowed.
|
||||
*/
|
||||
|
||||
#include <ipill.h>
|
||||
|
||||
#include "doctor.h"
|
||||
|
||||
namespace QuasarAppUtils {
|
||||
|
||||
Doctor::Doctor()
|
||||
{
|
||||
Doctor::Doctor(const QList<QSharedPointer<iPill> > &base) {
|
||||
_pillsData = base;
|
||||
}
|
||||
|
||||
void Doctor::diagnostic(bool fix) const {
|
||||
|
||||
QList<QSharedPointer<iPill> > failed;
|
||||
QList<QSharedPointer<iPill> > detected;
|
||||
QList<QSharedPointer<iPill> > fixedSuccessful;
|
||||
|
||||
for (const auto &pill: _pillsData) {
|
||||
if (pill->diagnostic()) {
|
||||
if (fix) {
|
||||
if (!pill->fix()) {
|
||||
failed.push_back(pill);
|
||||
} else {
|
||||
fixedSuccessful.push_back(pill);
|
||||
}
|
||||
} else {
|
||||
detected.push_back(pill);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (failed.size()) {
|
||||
emit sigFixesFailed(failed);
|
||||
}
|
||||
|
||||
if (detected.count()) {
|
||||
emit sigTroubleDetected(detected);
|
||||
}
|
||||
|
||||
if (fixedSuccessful.count()) {
|
||||
emit sigFixesFinishedSuccessful(fixedSuccessful);
|
||||
}
|
||||
}
|
||||
|
||||
void Doctor::fix(const QList<QSharedPointer<iPill> > &pills) const {
|
||||
|
||||
QList<QSharedPointer<iPill> > failed;
|
||||
QList<QSharedPointer<iPill> > fixedSuccessful;
|
||||
|
||||
for (const auto &pill: pills) {
|
||||
if (pill->diagnostic()) {
|
||||
if (!pill->fix()) {
|
||||
failed.push_back(pill);
|
||||
} else {
|
||||
fixedSuccessful.push_back(pill);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (failed.size()) {
|
||||
emit sigFixesFailed(failed);
|
||||
}
|
||||
|
||||
if (fixedSuccessful.count()) {
|
||||
emit sigFixesFinishedSuccessful(fixedSuccessful);
|
||||
}
|
||||
}
|
||||
|
||||
void Doctor::addPill(const QSharedPointer<iPill> &pill) {
|
||||
_pillsData.push_back(pill);
|
||||
}
|
||||
|
||||
}
|
||||
|
47
doctor.h
47
doctor.h
@ -27,44 +27,65 @@ public:
|
||||
* @brief Doctor This is base contructor of doctor calss.
|
||||
* @param base This is list of known issues.
|
||||
*/
|
||||
Doctor(const QList<QSharedPointer<iPill>>& base);
|
||||
Doctor(const QList<QSharedPointer<iPill>> &base);
|
||||
|
||||
/**
|
||||
* @brief diagnostick This method run full diagnostick of this application.
|
||||
* @brief diagnostic This method run full diagnostick of this application.
|
||||
* If the @a fix is true then doctor try fix the foundet issues.
|
||||
* If the @a fix value if false then the Doctor emit the sigTroubleDetected signal.
|
||||
* @param fix set this argument to tru if you want fix all foundet issues.
|
||||
*/
|
||||
void diagnostick(bool fix = false) const;
|
||||
* @see Doctor::fix
|
||||
* @see Doctor::addPill
|
||||
* @see Doctor::sigFixesFailed
|
||||
* @see Doctor::sigFixesFinishedSuccessful
|
||||
*/
|
||||
void diagnostic(bool fix = false) const;
|
||||
|
||||
/**
|
||||
* @brief fix
|
||||
* @param pill
|
||||
* @brief fix This method try run fixes by input pills.
|
||||
* @note All fixes will be checked before execute fix.
|
||||
* @param pills This is list of fixes that will be executed.
|
||||
* @see Doctor::diagnostick
|
||||
* @see Doctor::addPill
|
||||
* @see Doctor::sigFixesFailed
|
||||
* @see Doctor::sigFixesFinishedSuccessful
|
||||
*/
|
||||
void fix(const QList<QSharedPointer<iPill>>& pill) const;
|
||||
void fix(const QList<QSharedPointer<iPill>>& pills) const;
|
||||
|
||||
/**
|
||||
* @brief addPill This method add new pill object to doctor library
|
||||
* @param pill This is pill object.
|
||||
* @see Doctor::diagnostick
|
||||
* @see Doctor::fix
|
||||
* @see Doctor::sigFixesFailed
|
||||
* @see Doctor::sigFixesFinishedSuccessful
|
||||
*/
|
||||
void addPill(const QSharedPointer<iPill>& pill);
|
||||
signals:
|
||||
/**
|
||||
* @brief sigTroubleDetected This signal will emited when The doctor object found issues in this application.
|
||||
* @param issues
|
||||
* @param issues this is list of detected issues.
|
||||
* @see Doctor::diagnostick
|
||||
* @see Doctor::fix
|
||||
* @see Doctor::sigFixesFailed
|
||||
* @see Doctor::sigFixesFinishedSuccessful
|
||||
*/
|
||||
void sigTroubleDetected(QList<QSharedPointer<iPill>> issues);
|
||||
void sigTroubleDetected(QList<QSharedPointer<iPill>> issues) const;
|
||||
|
||||
/**
|
||||
* @brief sigFixesFailed This signal emited when the doctor can't fix foundet issues.
|
||||
* @param issues This is list of the unfixable issues.
|
||||
*/
|
||||
void sigFixesFailed(QList<QSharedPointer<iPill>> issues);
|
||||
void sigFixesFailed(QList<QSharedPointer<iPill>> issues) const;
|
||||
|
||||
/**
|
||||
* @brief sigFixesFinishedSuccessful This signal emited when the doctor fix foundet issues successfull.
|
||||
* @param issues This is list of the fixed issues.
|
||||
*/
|
||||
void sigFixesFinishedSuccessful(QList<QSharedPointer<iPill>> issues);
|
||||
|
||||
void sigFixesFinishedSuccessful(QList<QSharedPointer<iPill>> issues) const;
|
||||
|
||||
private:
|
||||
QHash<QString, QSharedPointer<iPill>> _pillsData;
|
||||
QList<QSharedPointer<iPill>> _pillsData;
|
||||
};
|
||||
|
||||
|
||||
|
30
doctortest.cpp
Normal file
30
doctortest.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2022 QuasarApp.
|
||||
* Distributed under the lgplv3 software license, see the accompanying
|
||||
* Everyone is permitted to copy and distribute verbatim copies
|
||||
* of this license document, but changing it is not allowed.
|
||||
*/
|
||||
|
||||
#include "doctortest.h"
|
||||
#include "ipill.h"
|
||||
|
||||
namespace QuasarAppUtils {
|
||||
|
||||
DoctorTest::DoctorTest() {
|
||||
}
|
||||
|
||||
bool DoctorTest::test(const QSharedPointer<iPill> &pill,
|
||||
bool appIsBroken) const {
|
||||
|
||||
if (pill->diagnostic() != appIsBroken) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (appIsBroken && !pill->fix()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return pill->diagnostic();
|
||||
}
|
||||
|
||||
}
|
46
doctortest.h
Normal file
46
doctortest.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2022 QuasarApp.
|
||||
* Distributed under the lgplv3 software license, see the accompanying
|
||||
* Everyone is permitted to copy and distribute verbatim copies
|
||||
* of this license document, but changing it is not allowed.
|
||||
*/
|
||||
|
||||
#ifndef DOCTORTEST_H
|
||||
#define DOCTORTEST_H
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace QuasarAppUtils {
|
||||
|
||||
class iPill;
|
||||
class Doctor;
|
||||
|
||||
/**
|
||||
* @brief The DoctorTest class This class contains auto tests for pills objects.
|
||||
* @see Doctor class for get more information.
|
||||
*/
|
||||
class DoctorTest
|
||||
{
|
||||
public:
|
||||
DoctorTest();
|
||||
|
||||
/**
|
||||
* @brief test This method run simple test for the pill object.
|
||||
* **Test algorithm**
|
||||
*
|
||||
* 1. Doctor run the iPill::diagnostic method.
|
||||
* 2. If an @a appIsBroken is false then diagnostic method should return true
|
||||
* 3. If an @a appIsBroken is true then diagnostic method should return true.
|
||||
* 4. Doctor run the fix and check diagnostic method again.
|
||||
* 5. The diagnostic method should return false value.
|
||||
*
|
||||
* @param pill This is checked pill for solve issue.
|
||||
* @param appIsBroken bollean variable that should be true if app is broken else false.
|
||||
* @return true if test passed elase false.
|
||||
*/
|
||||
bool test(const QSharedPointer<iPill>& pill, bool appIsBroken) const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // DOCTORTEST_H
|
5
ipill.h
5
ipill.h
@ -53,11 +53,11 @@ public:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief diagnostick This method execute action that should be check if exits issues or not.
|
||||
* @brief diagnostic This method execute action that should be check if exits issues or not.
|
||||
* @note This method will executed only on the Doctor object.
|
||||
* @return true if the issues is detected.
|
||||
*/
|
||||
virtual bool diagnostick() const = 0;
|
||||
virtual bool diagnostic() const = 0;
|
||||
|
||||
/**
|
||||
* @brief fix This method should be fix detected issue.
|
||||
@ -67,6 +67,7 @@ protected:
|
||||
|
||||
|
||||
friend class Doctor;
|
||||
friend class DoctorTest;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user