summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-07-11 12:41:50 +0300
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-07-11 12:41:50 +0300
commit127cd211375ff68c45d18eaab8954627ac8932fe (patch)
tree588c7fabeea9da3724bb6ba13f6531b2dc0e05e2
parentadb7dc6fac214dd150208c573a2db9838fbed78d (diff)
downloadsubsurface-127cd211375ff68c45d18eaab8954627ac8932fe.tar.gz
Models: add the DiveItem::displayDate() helper
Add this helper so that we can easily wrap the required memory release after calling get_dive_date_string() (fixes a small memory leak). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
-rw-r--r--qt-ui/models.cpp10
-rw-r--r--qt-ui/models.h1
2 files changed, 10 insertions, 1 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index ba325e149..80ccf0e73 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -971,7 +971,7 @@ QVariant DiveItem::data(int column, int role) const
case Qt::DisplayRole:
switch (column) {
case NR: retVal = dive->number; break;
- case DATE: retVal = QString(get_dive_date_string(dive->when)); break;
+ case DATE: retVal = displayDate(); break;
case DEPTH: retVal = displayDepth(); break;
case DURATION: retVal = displayDuration(); break;
case TEMPERATURE: retVal = displayTemperature(); break;
@@ -996,6 +996,14 @@ QVariant DiveItem::data(int column, int role) const
return retVal;
}
+QString DiveItem::displayDate() const
+{
+ char *buf = get_dive_date_string(dive->when);
+ QString date(buf);
+ free(buf);
+ return date;
+}
+
QString DiveItem::displayDepth() const
{
const int scale = 1000;
diff --git a/qt-ui/models.h b/qt-ui/models.h
index 439ff05df..bd1e60c0f 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -142,6 +142,7 @@ struct DiveItem : public TreeItem {
virtual QVariant data(int column, int role) const;
struct dive* dive;
+ QString displayDate() const;
QString displayDuration() const;
QString displayDepth() const;
QString displayTemperature() const;