4
1
mirror of https://github.com/QuasarApp/DoctorPill.git synced 2025-05-09 16:09:56 +00:00

add id for pills

This commit is contained in:
Andrei Yankovich 2022-02-03 11:44:16 +03:00
parent 5e3c7ef7e7
commit b50640d166
6 changed files with 48 additions and 15 deletions
src
Core/DoctorPillCore
Example
GUI
DoctorPillGui
DoctorPillModule
tests/units

@ -40,9 +40,17 @@ class DOCTOR_PILL_EXPORT iPill
public:
iPill();
/**
* @brief id This method return unique id of this pill object.
* @return unique id of this pill object.
*/
virtual int id() const = 0;
/**
* @brief name This method should be return name of this pill.
* @note for get id use the @a iPill::id method.
* @return name of this pill.
* @see iPill::id
*/
virtual QString name() const = 0;

@ -20,6 +20,10 @@ public:
return "EmptyPill";
};
int id() const override {
return typeid (this).hash_code();
};
QString description() const override {
return "Pill For Test. This pill cant be fixed ";
};
@ -47,6 +51,10 @@ public:
return "Pill For Test. This pill cant be fixed ";
};
int id() const override {
return typeid (this).hash_code();
};
protected:
bool diagnostic() const override {
std::this_thread::sleep_for(std::chrono::seconds(1));
@ -55,6 +63,7 @@ protected:
bool fix() const override {
return true;
};
};
@ -67,6 +76,10 @@ public:
return "EmptyPill2";
};
int id() const override {
return typeid (this).hash_code();
};
QString description() const override {
return "Pill For Test. This pill cant be fixed ";
};
@ -90,6 +103,10 @@ public:
return "Long Pill ";
};
int id() const override {
return typeid (this).hash_code();
};
QString description() const override {
return "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
" Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,"

@ -49,8 +49,8 @@ QVariant DoctorModel::data(const QModelIndex &index, int role) const {
return "Internal Error";
}
if ( role == Roles::Row) {
return index.row();
if ( role == Roles::Id) {
return item._pill->id();
}
if (role == Roles::Name) {
@ -74,12 +74,12 @@ QHash<int, QByteArray> DoctorModel::roleNames() const {
roles[Roles::Name] = "issueName";
roles[Roles::Description] = "issueDescription";
roles[Roles::Status] = "issueStatus";
roles[Roles::Row] = "row";
roles[Roles::Id] = "id";
return roles;
}
void DoctorModel::usePill(QString pillName) {
void DoctorModel::usePill(int pillName) {
auto work = [this, pillName](){
auto pill = _viewData.value(pillName, {});
@ -103,10 +103,14 @@ void DoctorModel::diagnostic() {
auto val = QtConcurrent::run(work);
}
void DoctorModel::drop(int row) {
if (row < 0 || row >= rowCount()) {
void DoctorModel::drop(int id) {
auto iter = _viewData.find(id);
if (iter == _viewData.end())
return;
}
int row = std::distance(_viewData.begin(), iter);
beginRemoveRows(QModelIndex{}, row, row);
_viewData.erase(std::next(_viewData.begin(), row));
@ -121,7 +125,7 @@ void DoctorModel::handleFixFailed(QList<QSharedPointer<iPill>> failed) {
for (const auto &pill : qAsConst(failed)) {
_viewData[pill->name()]._status = static_cast<int>(IssueStatus::Failed);
_viewData[pill->id()]._status = static_cast<int>(IssueStatus::Failed);
}
emit dataChanged(index(0,0), index(rowCount() - 1, 0),
@ -133,7 +137,7 @@ void DoctorModel::handleFixSuccessful(QList<QSharedPointer<iPill>> successful) {
for (const auto &pill : qAsConst(successful)) {
_viewData[pill->name()]._status = static_cast<int>(IssueStatus::Solved);
_viewData[pill->id()]._status = static_cast<int>(IssueStatus::Solved);
}
emit dataChanged(index(0,0), index(rowCount() - 1, 0),
@ -145,7 +149,7 @@ void DoctorModel::handleDiagnostcFinished(QList<QSharedPointer<iPill> > issues)
_viewData.clear();
for (const auto &pill : qAsConst(issues)) {
_viewData[pill->name()] = Issue{0, pill};
_viewData[pill->id()] = Issue{0, pill};
}
endResetModel();

@ -38,7 +38,7 @@ class DOCTOR_PILL_GUI_EXPORT DoctorModel: public QAbstractListModel
Name = Qt::UserRole,
Description,
Status,
Row
Id
};
/**
@ -84,7 +84,7 @@ public:
* @brief usePill This method try execute fix fo @a pillName pill.
* @param pillName This is name of selected pill object.
*/
Q_INVOKABLE void usePill(QString pillName);
Q_INVOKABLE void usePill(int pillName);
/**
* @brief diagnostic This method run diagnostic f this application.
@ -134,7 +134,7 @@ private:
int _state;
Doctor _doctor;
QHash<QString, Issue> _viewData;
QHash<int, Issue> _viewData;
double _progress;
};

@ -205,7 +205,7 @@ Page {
visible: issueStatus === 0
onClicked: {
if (root.model) {
root.model.usePill(issueName);
root.model.usePill(id);
}
}
}
@ -215,7 +215,7 @@ Page {
visible: issueStatus === 1
onClicked: {
if (root.model) {
root.model.drop(row);
root.model.drop(id);
}
}
}

@ -19,6 +19,10 @@ public:
_app = app;
};
int id() const override {
return typeid (this).hash_code();
};
QString name() const override {
return "Test pill";
};