Commit f1177eaa authored by Matthieu Bruel's avatar Matthieu Bruel
Browse files

return bool on deletion (check if the id exists)

parent 8e199adb
......@@ -167,10 +167,13 @@ void FamilyService::updateVarietyIsDefault(int srcRow, int crop_id, int variety_
qrp::Variety::r_isDefault, oldV, newV));
}
void FamilyService::deleteVariety(int crop_id, int variety_id)
bool FamilyService::deleteVariety(int crop_id, int variety_id)
{
if (!m_varieties.contains(variety_id))
return false;
qDebug() << "[FamilyService::deleteVariety] crop_id: " << crop_id << ", variety_id: " << variety_id;
Qrop::instance()->pushCommand(new CmdVarietyAddDel(crop_id, variety_id));
return true;
}
int FamilyService::addNewVariety(int crop_id, const QString &name, int seedCompanyId)
......@@ -182,10 +185,13 @@ int FamilyService::addNewVariety(int crop_id, const QString &name, int seedCompa
return cmd->varietyId();
}
void FamilyService::deleteCrop(int familyId, int cropId)
bool FamilyService::deleteCrop(int familyId, int cropId)
{
if (!m_crops.contains(cropId))
return false;
qDebug() << "[FamilyService::deleteCrop] familyId: " << familyId << ", cropId: " << cropId;
Qrop::instance()->pushCommand(new CmdCropAddDel(familyId, cropId));
return true;
}
int FamilyService::addNewCrop(int familyId, const QString &name, const QString &color)
......@@ -198,10 +204,13 @@ int FamilyService::addNewCrop(int familyId, const QString &name, const QString &
return cmd->cropId();
}
void FamilyService::deleteFamily(int familyId)
bool FamilyService::deleteFamily(int familyId)
{
if (!m_families.contains(familyId))
return false;
qDebug() << "[FamilyService::deleteFamily] familyId: " << familyId;
Qrop::instance()->pushCommand(new CmdFamilyAddDel(familyId));
return true;
}
int FamilyService::addNewFamily(const QString &name, const QString &color)
......
......@@ -93,13 +93,13 @@ public:
Q_INVOKABLE void updateVarietyIsDefault(int srcRow, int crop_id, int variety_id, bool oldV,
bool newV);
Q_INVOKABLE void deleteVariety(int crop_id, int variety_id);
Q_INVOKABLE bool deleteVariety(int crop_id, int variety_id);
Q_INVOKABLE int addNewVariety(int crop_id, const QString &name, int seedCompanyId);
Q_INVOKABLE void deleteCrop(int familyId, int cropId);
Q_INVOKABLE bool deleteCrop(int familyId, int cropId);
Q_INVOKABLE int addNewCrop(int familyId, const QString &name, const QString &color);
Q_INVOKABLE void deleteFamily(int familyId);
Q_INVOKABLE bool deleteFamily(int familyId);
Q_INVOKABLE int addNewFamily(const QString &name, const QString &color);
signals:
......
......@@ -163,7 +163,7 @@ void TstFamilyService::testUndoRedoOnCreationThenDeletion()
QVERIFY(m_familySvc->m_familyProxyModel->rowCount() == 1);
// delete fam1
m_familySvc->deleteFamily(fam1->id);
QVERIFY(m_familySvc->deleteFamily(fam1->id));
QVERIFY(fam1->deleted == true);
QVERIFY(m_familySvc->m_familyProxyModel->rowCount() == 0);
......@@ -177,6 +177,9 @@ void TstFamilyService::testUndoRedoOnCreationThenDeletion()
QVERIFY(fam1->deleted == true);
QVERIFY(m_familySvc->m_familyProxyModel->rowCount() == 0);
// test deleting non existing family
QVERIFY(!m_familySvc->deleteFamily(666));
_cleanupTestCase();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment