[utilities/powerplant] src: Fix Birthdate handling, and added birthday icon

Carl Schwan <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 41a52fe9fbcb9851cbe3155011016b52edac6094 by Carl Schwan, on behalf of Michael Rostom.
Committed on 06/08/2026 at 09:09.
Pushed by carlschwan into branch 'master'.

Fix Birthdate handling, and added birthday icon

* Setting the `Value` for the `FormDateTimeDelegate` instead of `initialValue`. This makes the plant's birthdate show up when editing the page rather than the default "Today"
* Fixed birthdate handling. Because it was saved as a date object instead of dateTime, the date would be off by 1 day sometimes as it gets converted.
* Added cake icon in top left when it is the plant's birthday

![image.png](/uploads/f2e3b150d167f2856c05303ca10f4a3c/image.png){width=268 height=377}

M  +3    -3    src/planteditor.cpp
M  +2    -2    src/planteditor.h
M  +1    -1    src/plantsmodel.cpp
M  +1    -1    src/qml/PlantEditorPage.qml
M  +4    -1    src/qml/PlantsPage.qml

https://invent.kde.org/utilities/powerplant/-/commit/41a52fe9fbcb9851cbe3155011016b52edac6094

diff --git a/src/planteditor.cpp b/src/planteditor.cpp
index 82c675b..c76e76b 100644
--- a/src/planteditor.cpp
+++ b/src/planteditor.cpp
@@ -70,7 +70,7 @@ void Plant::refresh()
         m_location = plant->location;
         Q_EMIT locationChanged();
 
-        m_dateOfBirth = QDateTime::fromSecsSinceEpoch(plant->date_of_birth).date();
+        m_dateOfBirth = QDateTime::fromSecsSinceEpoch(plant->date_of_birth);
         Q_EMIT dateOfBirthChanged();
 
         m_lastWatered = QDateTime::fromSecsSinceEpoch(plant->last_watered).date();
@@ -131,7 +131,7 @@ void PlantEditor::save()
                                 m_plant->m_waterInterval,
                                 m_plant->m_fertilizerInterval,
                                 m_plant->m_location,
-                                m_plant->m_dateOfBirth.startOfDay().toSecsSinceEpoch(),
+                                m_plant->m_dateOfBirth.date().startOfDay().toSecsSinceEpoch(),
                                 m_plant->m_currentHealth);
     } else {
         m_plantsModel->editPlant(m_plant->m_plantId,
@@ -141,7 +141,7 @@ void PlantEditor::save()
                                  m_plant->m_waterInterval,
                                  m_plant->m_fertilizerInterval,
                                  m_plant->m_location,
-                                 m_plant->m_dateOfBirth.startOfDay().toSecsSinceEpoch());
+                                 m_plant->m_dateOfBirth.date().startOfDay().toSecsSinceEpoch());
     }
 }
 
diff --git a/src/planteditor.h b/src/planteditor.h
index b678f06..7279289 100644
--- a/src/planteditor.h
+++ b/src/planteditor.h
@@ -39,7 +39,7 @@ class Plant : public QObject
     Q_PROPERTY(QString location MEMBER m_location NOTIFY locationChanged)
 
     /// This property holds the date of birth of this plant
-    Q_PROPERTY(QDate dateOfBirth MEMBER m_dateOfBirth NOTIFY dateOfBirthChanged)
+    Q_PROPERTY(QDateTime dateOfBirth MEMBER m_dateOfBirth NOTIFY dateOfBirthChanged)
 
     /// This property holds the time when this plant was last watered
     Q_PROPERTY(QDate lastWatered MEMBER m_lastWatered NOTIFY lastWateredChanged)
@@ -86,7 +86,7 @@ private:
     QString m_species;
     QUrl m_imgUrl;
     QString m_location;
-    QDate m_dateOfBirth;
+    QDateTime m_dateOfBirth;
     QDate m_lastWatered;
     QDate m_lastFertilized;
     int m_waterInterval = 2;
diff --git a/src/plantsmodel.cpp b/src/plantsmodel.cpp
index cc0ee52..c7ca45e 100644
--- a/src/plantsmodel.cpp
+++ b/src/plantsmodel.cpp
@@ -96,7 +96,7 @@ QVariant PlantsModel::data(const QModelIndex &index, int role) const
     case Role::Location:
         return plant.location;
     case Role::DateOfBirth:
-        return QDateTime::fromSecsSinceEpoch(plant.date_of_birth).date();
+        return QDateTime::fromSecsSinceEpoch(plant.date_of_birth);
     case Role::LastWatered:
         return QDateTime::fromSecsSinceEpoch(plant.last_watered).date();
     case Role::WantsToBeWateredIn:
diff --git a/src/qml/PlantEditorPage.qml b/src/qml/PlantEditorPage.qml
index 54f87cf..2f5b596 100644
--- a/src/qml/PlantEditorPage.qml
+++ b/src/qml/PlantEditorPage.qml
@@ -351,7 +351,7 @@ FormCard.FormCardPage {
     FormCard.FormCard {
         FormCard.FormDateTimeDelegate {
             dateTimeDisplay: FormCard.FormDateTimeDelegate.DateTimeDisplay.Date
-            initialValue: plantEditor.plant.dateOfBirth
+            value: plantEditor.plant.dateOfBirth
             onValueChanged: plantEditor.plant.dateOfBirth = value
         }
     }
diff --git a/src/qml/PlantsPage.qml b/src/qml/PlantsPage.qml
index 8c61330..666cd37 100644
--- a/src/qml/PlantsPage.qml
+++ b/src/qml/PlantsPage.qml
@@ -377,7 +377,10 @@ Kirigami.ScrollablePage {
                 implicitHeight: grid.cellHeight - 2 * Layout.margins
                 contentItem: ColumnLayout {
                     spacing: Kirigami.Units.smallSpacing
-
+                    Kirigami.Icon {
+                        source: "food-cake"
+                        visible: root.currentDate.getDate() === dateOfBirth.getDate() && root.currentDate.getMonth() === dateOfBirth.getMonth()
+                    }
                     Item {
                         Layout.fillHeight: true
                     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.