do not draw showmap button for event is there is no map for its room
authorkirilma <kirilma@localhost>
Wed, 5 May 2010 13:58:23 +0000 (13:58 +0000)
committerkirilma <kirilma@localhost>
Wed, 5 May 2010 13:58:23 +0000 (13:58 +0000)
src/mvc/delegate.cpp
src/mvc/room.h

index 403795e..dac1bdf 100644 (file)
@@ -23,6 +23,8 @@
 #include <QDebug>
 #include <QPainter>
 
+#include "room.h"
+
 const int RADIUS = 10;
 const int SPACER = 10;
 
@@ -60,6 +62,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
     if(hasParent(index))
     {
         int aux = option.rect.height() - mControls[FavouriteControlOn]->drawPoint().y() - mControls[FavouriteControlOn]->image()->height();
+        Event *event = static_cast<Event*>(index.internalPointer());
         // font SMALL
         QFont fontSmall = option.font;
         fontSmall.setBold(false);
@@ -83,7 +86,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         //int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width();
 
         //Time conflicts are colored differently
-        if(static_cast<Event*>(index.internalPointer())->hasTimeConflict())
+        if(event->hasTimeConflict())
             bkgrColor = conflictColor;
 
         QLinearGradient itemGradient(option.rect.topLeft(), option.rect.bottomLeft());
@@ -129,25 +132,26 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
 
         // draw Controls
         // favourite
-        if(static_cast<Event*>(index.internalPointer())->isFavourite())
+        if(event->isFavourite())
             painter->drawImage(mControls[FavouriteControlOn]->drawPoint(option.rect),*mControls[FavouriteControlOn]->image());
         else
             painter->drawImage(mControls[FavouriteControlOff]->drawPoint(option.rect),*mControls[FavouriteControlOff]->image());
 #ifdef MAEMO
         // alarm
-        if(static_cast<Event*>(index.internalPointer())->hasAlarm())
+        if(event->hasAlarm())
             painter->drawImage(mControls[AlarmControlOn]->drawPoint(option.rect),*mControls[AlarmControlOn]->image());
         else
             painter->drawImage(mControls[AlarmControlOff]->drawPoint(option.rect),*mControls[AlarmControlOff]->image());
 #endif
         // map
-        painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image());
+        if (event->room()->hasMap()) {
+            painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image());
+        }
         // Time conflict
-        if(static_cast<Event*>(index.internalPointer())->hasTimeConflict())
+        if(event->hasTimeConflict())
             painter->drawImage(mControls[WarningControl]->drawPoint(option.rect),*mControls[WarningControl]->image());
 
         // draw texts
-        Event *event = static_cast<Event*>(index.internalPointer());
         QPointF titlePointF(mControls[FavouriteControlOn]->drawPoint(option.rect));
         titlePointF.setX(option.rect.x()+SPACER);
         titlePointF.setY(titlePointF.y()+mControls[FavouriteControlOn]->image()->height());
index 11544a2..b961458 100644 (file)
@@ -35,7 +35,13 @@ public:
     QString name() const { return value("name").toString(); }
     void setName(const QString & type) { setValue("name", type); }
     // TODO: make naming consistent - either "picture" or "map"
-     QVariant map() const { return value("picture"); }
+    QVariant map() const { return value("picture"); }
+    bool hasMap() const
+    {
+        // empty strings also treasted as NULL,
+        // as storing NULLs requires rewrite of storing code and DB scheme
+        return !isNull("picture") and !value("picture").toString().isEmpty();
+    }
     int insert();
 public:
     static QList<Room> getAll();