init
This commit is contained in:
@@ -83,6 +83,8 @@ public:
|
||||
virtual qint32 create(const QString& szName, const QString& szGroup) = 0;
|
||||
virtual qint32 createGroup(const QString& szGroup) = 0;
|
||||
virtual bool set(qint32 id, qint16 ingredientNumber, qreal value) = 0;
|
||||
virtual bool setName(qint32 id, const QString& szName) = 0;
|
||||
virtual bool setGroup(qint32 id, const QString& szGroup) = 0;
|
||||
virtual QString name(qint32 id) = 0;
|
||||
virtual QString group(qint32 id) = 0;
|
||||
virtual qreal get(qint32 id, qint16 ingredientNumber) = 0;
|
||||
|
||||
+27
-8
@@ -225,16 +225,35 @@ bool cIngredient::save(cPlugin* lpDB)
|
||||
|
||||
lpInterface->beginTransaction();
|
||||
|
||||
qint32 id = lpInterface->create(m_szIngredientName, m_szIngredientGroup);
|
||||
if(id == -1)
|
||||
return(false);
|
||||
|
||||
for(int z = 0;z < cIngredient::iIngredientMax;z++)
|
||||
if(m_iID == -1)
|
||||
{
|
||||
if(m_dValue[z] != -1)
|
||||
qint32 id = lpInterface->create(m_szIngredientName, m_szIngredientGroup);
|
||||
if(id == -1)
|
||||
return(false);
|
||||
|
||||
for(int z = 0;z < cIngredient::iIngredientMax;z++)
|
||||
{
|
||||
if(!lpInterface->set(id, z, m_dValue[z]))
|
||||
return(false);
|
||||
if(m_dValue[z] != -1)
|
||||
{
|
||||
if(!lpInterface->set(id, z, m_dValue[z]))
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
m_iID = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
lpInterface->setName(m_iID, m_szIngredientName);
|
||||
lpInterface->setGroup(m_iID, m_szIngredientGroup);
|
||||
|
||||
for(int z = 0;z < cIngredient::iIngredientMax;z++)
|
||||
{
|
||||
if(m_dValue[z] != -1)
|
||||
{
|
||||
if(!lpInterface->set(m_iID, z, m_dValue[z]))
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+25
-15
@@ -101,26 +101,13 @@ void cIngredientWindow::ingredientEdit(const QModelIndex &modelIndex)
|
||||
value = ingredientValue.value();
|
||||
m_ingredient.setValue(iIngredient, value);
|
||||
|
||||
bool bChanged = isChanged(); // may not be later as it seems to be buggy ...
|
||||
//bool bChanged = isChanged(); // may not be later as it seems to be buggy ...
|
||||
|
||||
QStandardItem* lpParent = lpCurrentItem->parent();
|
||||
QStandardItem* lpValue = lpParent->child(modelIndex.row(), 1);
|
||||
lpValue->setText(m_ingredient.valueFormatted(iIngredient));
|
||||
|
||||
if(bChanged)
|
||||
{
|
||||
setWindowTitle(QString("<Ingredient> %1*").arg(m_ingredientSaved.ingredientName()));
|
||||
m_lpItem->setText(QString("%1*").arg(m_ingredientSaved.ingredientName()));
|
||||
ui->m_lpSave->setEnabled(true);
|
||||
ui->m_lpRevert->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindowTitle(QString("<Ingredient> %1").arg(m_ingredientSaved.ingredientName()));
|
||||
m_lpItem->setText(QString("%1").arg(m_ingredientSaved.ingredientName()));
|
||||
ui->m_lpSave->setEnabled(false);
|
||||
ui->m_lpRevert->setEnabled(false);
|
||||
}
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
bool cIngredientWindow::isChanged()
|
||||
@@ -132,12 +119,17 @@ bool cIngredientWindow::isChanged()
|
||||
|
||||
void cIngredientWindow::on_m_lpSave_clicked()
|
||||
{
|
||||
m_ingredient.save(m_lpDBPlugin);
|
||||
m_ingredientSaved = m_ingredient;
|
||||
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
void cIngredientWindow::on_m_lpRevert_clicked()
|
||||
{
|
||||
setIngredient();
|
||||
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
void cIngredientWindow::on_m_lpClose_clicked()
|
||||
@@ -152,3 +144,21 @@ void cIngredientWindow::closeEvent(QCloseEvent *event)
|
||||
else
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void cIngredientWindow::updateTitle()
|
||||
{
|
||||
if(isChanged())
|
||||
{
|
||||
setWindowTitle(QString("<Ingredient> %1*").arg(m_ingredientSaved.ingredientName()));
|
||||
m_lpItem->setText(QString("%1*").arg(m_ingredientSaved.ingredientName()));
|
||||
ui->m_lpSave->setEnabled(true);
|
||||
ui->m_lpRevert->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindowTitle(QString("<Ingredient> %1").arg(m_ingredientSaved.ingredientName()));
|
||||
m_lpItem->setText(QString("%1").arg(m_ingredientSaved.ingredientName()));
|
||||
ui->m_lpSave->setEnabled(false);
|
||||
ui->m_lpRevert->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ private:
|
||||
QStandardItemModel* m_lpIngredientValuesModel;
|
||||
QStandardItem* m_lpItem;
|
||||
|
||||
void updateTitle();
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
};
|
||||
|
||||
@@ -269,6 +269,16 @@ bool cMySQLPlugin::set(qint32 id, qint16 ingredientNumber, qreal value)
|
||||
return(existsIngredient(id, ingredientNumber));
|
||||
}
|
||||
|
||||
bool cMySQLPlugin::setName(qint32 id, const QString& szName)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool cMySQLPlugin::setGroup(qint32 id, const QString& szGroup)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
QString cMySQLPlugin::name(qint32 id)
|
||||
{
|
||||
if(!m_bConnected)
|
||||
|
||||
@@ -117,6 +117,8 @@ public:
|
||||
qint32 create(const QString& szName, const QString& szGroup);
|
||||
qint32 createGroup(const QString& szGroup);
|
||||
bool set(qint32 id, qint16 ingredientNumber, qreal value);
|
||||
bool setName(qint32 id, const QString& szName);
|
||||
bool setGroup(qint32 id, const QString& szGroup);
|
||||
QString name(qint32 id);
|
||||
QString group(qint32 id);
|
||||
qreal get(qint32 id, qint16 ingredientNumber);
|
||||
|
||||
@@ -243,11 +243,14 @@ bool cSQLitePlugin::set(qint32 id, qint16 ingredientNumber, qreal value)
|
||||
if(!m_bConnected)
|
||||
return(-1);
|
||||
|
||||
if(existsIngredient(id, ingredientNumber) != -1)
|
||||
return(-1);
|
||||
|
||||
QSqlQuery query(m_db);
|
||||
if(!query.exec(QString("INSERT INTO ingredient_values (ingredient_id, ingredient_number, value) VALUES (%1, %2, %3)").arg(id).arg(ingredientNumber).arg(value)))
|
||||
|
||||
if(existsIngredient(id, ingredientNumber) != -1)
|
||||
query.prepare(QString("UPDATE ingredient_values SET value=%1 WHERE ingredient_id=%2 AND ingredient_number=%3").arg(value).arg(id).arg(ingredientNumber));
|
||||
else
|
||||
query.prepare(QString("INSERT INTO ingredient_values (ingredient_id, ingredient_number, value) VALUES (%1, %2, %3)").arg(id).arg(ingredientNumber).arg(value));
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
m_szLastError = query.lastError().text();
|
||||
return(-1);
|
||||
@@ -255,6 +258,44 @@ bool cSQLitePlugin::set(qint32 id, qint16 ingredientNumber, qreal value)
|
||||
return(existsIngredient(id, ingredientNumber));
|
||||
}
|
||||
|
||||
bool cSQLitePlugin::setName(qint32 id, const QString& szName)
|
||||
{
|
||||
if(!m_bConnected)
|
||||
return(false);
|
||||
|
||||
QSqlQuery query(m_db);
|
||||
if(!query.exec(QString("UPDATE ingredient SET name=\"%1\" WHERE id=%2").arg(szName).arg(id)))
|
||||
{
|
||||
m_szLastError = query.lastError().text();
|
||||
return("");
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool cSQLitePlugin::setGroup(qint32 id, const QString& szGroup)
|
||||
{
|
||||
if(!m_bConnected)
|
||||
return(false);
|
||||
|
||||
qint32 groupID = existsGroup(szGroup);
|
||||
|
||||
if(groupID == -1)
|
||||
groupID = createGroup(szGroup);
|
||||
|
||||
if(groupID == -1)
|
||||
return(false);
|
||||
|
||||
QSqlQuery query(m_db);
|
||||
if(!query.exec(QString("UPDATE ingredient SET ingredient_group=%1 WHERE id=%2").arg(groupID).arg(id)))
|
||||
{
|
||||
m_szLastError = query.lastError().text();
|
||||
return("");
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
QString cSQLitePlugin::name(qint32 id)
|
||||
{
|
||||
if(!m_bConnected)
|
||||
|
||||
@@ -78,6 +78,8 @@ public:
|
||||
qint32 create(const QString& szName, const QString &szGroup);
|
||||
qint32 createGroup(const QString& szGroup);
|
||||
bool set(qint32 id, qint16 ingredientNumber, qreal value);
|
||||
bool setName(qint32 id, const QString& szName);
|
||||
bool setGroup(qint32 id, const QString& szGroup);
|
||||
QString name(qint32 id);
|
||||
QString group(qint32 id);
|
||||
qreal get(qint32 id, qint16 ingredientNumber);
|
||||
|
||||
Reference in New Issue
Block a user