From 6dcaae5b1f2ba23f9d4aff409af0d53bb776ea36 Mon Sep 17 00:00:00 2001 From: birkeh Date: Mon, 13 Feb 2017 14:00:26 +0100 Subject: [PATCH] init --- Kooky/cimportinterface.cpp | 2 -- Kooky/cingredient.h | 7 ++--- Kooky/cingredientwindow.cpp | 59 +++++++++++++++++++++++++++++++---- Kooky/cingredientwindow.h | 12 ++++++- Kooky/cingredientwindow.ui | 38 ++++++++++++++++++++++ Kooky/cmainwindow.cpp | 2 +- iBleibFit/cbleibfitplugin.cpp | 2 +- 7 files changed, 107 insertions(+), 15 deletions(-) diff --git a/Kooky/cimportinterface.cpp b/Kooky/cimportinterface.cpp index 9ba49e3..af74761 100644 --- a/Kooky/cimportinterface.cpp +++ b/Kooky/cimportinterface.cpp @@ -18,8 +18,6 @@ QString cImportInterface::valueStr(cIngredient::iIngredient i) if(i == cIngredient::iIngredientCalories) strValue = QString("%1 kcal").arg(dValue); - else if(i == cIngredient::iIngredientJoule) - strValue = QString("%1 kJ").arg(dValue); else { if(dValue < 0.001) diff --git a/Kooky/cingredient.h b/Kooky/cingredient.h index d7e7515..8cdb4b0 100644 --- a/Kooky/cingredient.h +++ b/Kooky/cingredient.h @@ -195,10 +195,9 @@ public: iIngredientBiologicalvalue = 152, iIngredientFructosefreebreadunits = 153, iIngredientaverageconsumption = 154, - iIngredientJoule = 155, - iIngredientSugar = 156, - iIngredientAspartid = 157, - iIngredientGlutamid = 158, + iIngredientSugar = 155, + iIngredientAspartid = 156, + iIngredientGlutamid = 157, iIngredientMax, }; diff --git a/Kooky/cingredientwindow.cpp b/Kooky/cingredientwindow.cpp index fd9eff6..5521693 100644 --- a/Kooky/cingredientwindow.cpp +++ b/Kooky/cingredientwindow.cpp @@ -16,6 +16,9 @@ cIngredientWindow::cIngredientWindow(QWidget *parent) : m_lpIngredientValuesModel = new QStandardItemModel(0, 2); ui->m_lpIngredientValues->setModel(m_lpIngredientValuesModel); + ui->m_lpSave->setEnabled(false); + ui->m_lpRevert->setEnabled(false); + connect(ui->m_lpIngredientValues, &QTreeView::doubleClicked, this, &cIngredientWindow::ingredientEdit); } @@ -24,16 +27,22 @@ cIngredientWindow::~cIngredientWindow() delete ui; } -void cIngredientWindow::setIngredient(qint32 iIngredient, cPlugin* lpPlugin) +void cIngredientWindow::setIngredient(QStandardItem *lpItem, cPlugin* lpPlugin) { - m_iIngredient = iIngredient; - m_lpDBPlugin = lpPlugin; - if(!m_ingredientSaved.load(m_iIngredient, m_lpDBPlugin)) - return; + if(lpPlugin) + { + m_lpItem = lpItem; + m_iIngredient = lpItem->data().toInt(); + m_lpDBPlugin = lpPlugin; + if(!m_ingredientSaved.load(m_iIngredient, m_lpDBPlugin)) + return; + } + + m_lpIngredientValuesModel->clear(); + m_lpIngredientValuesModel->setColumnCount(2); m_ingredient = m_ingredientSaved; - setWindowTitle(QString(" %1").arg(m_ingredientSaved.ingredientName())); ui->m_lpIngredientName->setText(m_ingredientSaved.ingredientName()); QStringList groups = m_ingredientSaved.groups(); @@ -61,6 +70,11 @@ void cIngredientWindow::setIngredient(qint32 iIngredient, cPlugin* lpPlugin) ui->m_lpIngredientValues->expandAll(); ui->m_lpIngredientValues->resizeColumnToContents(0); ui->m_lpIngredientValues->resizeColumnToContents(1); + + setWindowTitle(QString(" %1").arg(m_ingredientSaved.ingredientName())); + m_lpItem->setText(QString("%1").arg(m_ingredientSaved.ingredientName())); + ui->m_lpSave->setEnabled(false); + ui->m_lpRevert->setEnabled(false); } qint32 cIngredientWindow::ingredientID(void) @@ -94,9 +108,19 @@ void cIngredientWindow::ingredientEdit(const QModelIndex &modelIndex) lpValue->setText(m_ingredient.valueFormatted(iIngredient)); if(bChanged) + { setWindowTitle(QString(" %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(" %1").arg(m_ingredientSaved.ingredientName())); + m_lpItem->setText(QString("%1").arg(m_ingredientSaved.ingredientName())); + ui->m_lpSave->setEnabled(false); + ui->m_lpRevert->setEnabled(false); + } } bool cIngredientWindow::isChanged() @@ -105,3 +129,26 @@ bool cIngredientWindow::isChanged() return(true); return(false); } + +void cIngredientWindow::on_m_lpSave_clicked() +{ + +} + +void cIngredientWindow::on_m_lpRevert_clicked() +{ + setIngredient(); +} + +void cIngredientWindow::on_m_lpClose_clicked() +{ + +} + +void cIngredientWindow::closeEvent(QCloseEvent *event) +{ + if(isChanged()) + event->ignore(); + else + event->accept(); +} diff --git a/Kooky/cingredientwindow.h b/Kooky/cingredientwindow.h index 192bd10..60603ef 100644 --- a/Kooky/cingredientwindow.h +++ b/Kooky/cingredientwindow.h @@ -22,13 +22,19 @@ public: explicit cIngredientWindow(QWidget *parent = 0); ~cIngredientWindow(); - void setIngredient(qint32 iIngredient, cPlugin* lpPlugin); + void setIngredient(QStandardItem* lpItem = 0, cPlugin* lpPlugin = 0); qint32 ingredientID(void); bool isChanged(); private slots: void ingredientEdit(const QModelIndex& modelIndex); + void on_m_lpSave_clicked(); + + void on_m_lpRevert_clicked(); + + void on_m_lpClose_clicked(); + private: Ui::cIngredientWindow* ui; @@ -37,6 +43,10 @@ private: cIngredient m_ingredient; cIngredient m_ingredientSaved; QStandardItemModel* m_lpIngredientValuesModel; + QStandardItem* m_lpItem; + +protected: + void closeEvent(QCloseEvent *event); }; #endif // CINGREDIENTWINDOW_H diff --git a/Kooky/cingredientwindow.ui b/Kooky/cingredientwindow.ui index 4a6b0f7..8cc492d 100644 --- a/Kooky/cingredientwindow.ui +++ b/Kooky/cingredientwindow.ui @@ -61,6 +61,44 @@ + + + + + + Save + + + + + + + Revert + + + + + + + Close + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/Kooky/cmainwindow.cpp b/Kooky/cmainwindow.cpp index 794d5c9..49b11fe 100644 --- a/Kooky/cmainwindow.cpp +++ b/Kooky/cmainwindow.cpp @@ -497,7 +497,7 @@ void cMainWindow::ingredientsListEditTriggered() } cIngredientWindow* lpIngredientWindow = new cIngredientWindow(this); - lpIngredientWindow->setIngredient(lpItem->data().toInt(), m_lpDB); + lpIngredientWindow->setIngredient(lpItem, m_lpDB); QMdiSubWindow* lpSubWindow = ui->m_lpMDIArea->addSubWindow(lpIngredientWindow); lpSubWindow->setAttribute(Qt::WA_DeleteOnClose); lpIngredientWindow->show(); diff --git a/iBleibFit/cbleibfitplugin.cpp b/iBleibFit/cbleibfitplugin.cpp index 66e59e5..a91e469 100644 --- a/iBleibFit/cbleibfitplugin.cpp +++ b/iBleibFit/cbleibfitplugin.cpp @@ -16,7 +16,7 @@ typedef struct tagMAPPER MAPPER g_ingredientMapper[] = { { "Kilokalorien:", cIngredient::iIngredientCalories }, - { "Kilojoule:", cIngredient::iIngredientJoule }, +// { "Kilojoule:", cIngredient::iIngredientJoule }, { "Protein:", cIngredient::iIngredientProtein }, { "Fett:", cIngredient::iIngredientFat }, { "Kohlehydrate:", cIngredient::iIngredientCarbohydrates },