[niepce] libraryclient: use option<> to get label colours
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] libraryclient: use option<> to get label colours
- Date: Thu, 11 May 2017 02:06:33 +0000 (UTC)
commit 12178ad0eb8fa0581b1b7288021ab2a7ec9711d7
Author: Hubert Figuière <hub figuiere net>
Date: Tue Mar 14 01:10:25 2017 -0400
libraryclient: use option<> to get label colours
src/libraryclient/uidataprovider.cpp | 8 ++++----
src/libraryclient/uidataprovider.hpp | 5 +++--
src/niepce/ui/librarycellrenderer.cpp | 13 ++++++-------
3 files changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/src/libraryclient/uidataprovider.cpp b/src/libraryclient/uidataprovider.cpp
index 9e02fff..466df21 100644
--- a/src/libraryclient/uidataprovider.cpp
+++ b/src/libraryclient/uidataprovider.cpp
@@ -1,7 +1,7 @@
/*
* niepce - libraryclient/uidataprovider.cpp
*
- * Copyright (C) 2011-2013 Hub Figuiere
+ * Copyright (C) 2011-2017 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -62,14 +62,14 @@ void UIDataProvider::deleteLabel(int id)
}
}
-const fwk::RgbColour * UIDataProvider::colourForLabel(int id) const
+fwk::Option<fwk::RgbColour> UIDataProvider::colourForLabel(int id) const
{
for(auto iter : m_labels) {
if(iter->id() == id) {
- return &(iter->colour());
+ return fwk::Option<fwk::RgbColour>(iter->colour());
}
}
- return nullptr;
+ return fwk::Option<fwk::RgbColour>();
}
diff --git a/src/libraryclient/uidataprovider.hpp b/src/libraryclient/uidataprovider.hpp
index a828ac5..4d85dfd 100644
--- a/src/libraryclient/uidataprovider.hpp
+++ b/src/libraryclient/uidataprovider.hpp
@@ -1,7 +1,7 @@
/*
* niepce - libraryclient/uidataprovider.hpp
*
- * Copyright (C) 2011 Hub Figuiere
+ * Copyright (C) 2011-2017 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
#include <stdint.h>
+#include "fwk/base/option.hpp"
#include "engine/db/label.hpp"
namespace fwk {
@@ -38,7 +39,7 @@ public:
void updateLabel(const eng::Label::Ptr &);
void addLabels(const eng::Label::ListPtr & l);
void deleteLabel(int id);
- const fwk::RgbColour * colourForLabel(int id) const;
+ fwk::Option<fwk::RgbColour> colourForLabel(int id) const;
const eng::Label::List & getLabels() const
{ return m_labels; }
private:
diff --git a/src/niepce/ui/librarycellrenderer.cpp b/src/niepce/ui/librarycellrenderer.cpp
index f76f755..1aa7061 100644
--- a/src/niepce/ui/librarycellrenderer.cpp
+++ b/src/niepce/ui/librarycellrenderer.cpp
@@ -164,10 +164,9 @@ int drawFormatEmblem(const Cairo::RefPtr<Cairo::Context> & cr,
}
void drawLabel(const Cairo::RefPtr<Cairo::Context> & cr,
- int right, const fwk::RgbColour * colour,
+ int right, const fwk::RgbColour & colour,
const GdkRectangle & r)
{
- DBG_ASSERT(colour, "colour is NULL");
const int label_size = 15;
double x, y;
x = r.x + r.width - CELL_PADDING - right - CELL_PADDING - label_size;
@@ -177,7 +176,7 @@ void drawLabel(const Cairo::RefPtr<Cairo::Context> & cr,
cr->set_source_rgb(1.0, 1.0, 1.0);
cr->stroke();
cr->rectangle(x, y, label_size, label_size);
- Gdk::Cairo::set_source_rgba(cr, fwk::rgbcolour_to_gdkcolor(*colour));
+ Gdk::Cairo::set_source_rgba(cr, fwk::rgbcolour_to_gdkcolor(colour));
cr->fill();
}
@@ -279,10 +278,10 @@ LibraryCellRenderer::render_vfunc(const Cairo::RefPtr<Cairo::Context>& cr,
DBG_ASSERT(m_uiDataProvider, "no UIDataProvider");
uint32_t label_id = file->label();
if(label_id != 0) {
- const fwk::RgbColour * label_colour = m_uiDataProvider->colourForLabel(label_id);
- DBG_ASSERT(label_colour, "colour not found");
- if(label_colour) {
- drawLabel(cr, left, label_colour, r);
+ auto result = m_uiDataProvider->colourForLabel(label_id);
+ DBG_ASSERT(!result.empty(), "colour not found");
+ if (!result.empty()) {
+ drawLabel(cr, left, result.unwrap(), r);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]