diff --git a/data/bitmaps/notes_closed.png b/data/bitmaps/notes_closed.png new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ +#include +#include + +class Comment +{ +public: + Comment(); + Comment(QDateTime date, QString text, QString user, int uid); + void setDate(const QDateTime& date){m_date = date;}; + void setText(const QString& text){m_text = text;}; + void setUser(const QString& user){m_user = user;}; + void setUid(const int uid){m_uid = uid;}; + QDateTime getDate() const {return m_date;}; + QString getText() const {return m_text;}; + QString getUser() const {return m_user;}; + int getUid() const {return m_uid;}; +private: + QDateTime m_date; + QString m_text; + QString m_user; + int m_uid; + +}; namespace Marble { @@ -22,7 +45,7 @@ Q_OBJECT public: - explicit NotesItem(QObject *parent); + explicit NotesItem(QObject* parent); ~NotesItem() override; @@ -32,9 +55,33 @@ bool operator<(const AbstractDataPluginItem *other) const override; + void setAuthor(const QString &author); + + void setDateCreated(const QDateTime& dateCreated); + + void setNoteStatus(const QString& noteStatus); + + void setDateClosed(const QDateTime& dataClosed); + + void addLatestComment(const Comment& comment); + + void setComment(const Comment& comment); + + qreal width(); + + qreal height(); + private: - QPixmap m_pixmap; -}; + QPixmap m_pixmap_open; + QPixmap m_pixmap_closed; + QVector m_commentsList; + QDateTime m_dateCreated; + QString m_noteStatus; + QDateTime m_dateClosed; + QString m_labelText; + static const QFont s_font; + static const int s_labelOutlineWidth; +}; } #endif // NOTESITEM_H diff --git a/src/plugins/render/notes/NotesItem.cpp b/src/plugins/render/notes/NotesItem.cpp --- a/src/plugins/render/notes/NotesItem.cpp +++ b/src/plugins/render/notes/NotesItem.cpp @@ -7,17 +7,25 @@ #include "NotesItem.h" #include "MarbleDirs.h" +#include "MarbleDebug.h" #include #include using namespace Marble; +const QFont NotesItem::s_font = QFont( QStringLiteral( "Sans Serif" ), 10 ); +const int NotesItem::s_labelOutlineWidth = 5; + NotesItem::NotesItem(QObject *parent) : AbstractDataPluginItem(parent), - m_pixmap(MarbleDirs::path("bitmaps/waypoint.png")) + m_pixmap_open(QPixmap(MarbleDirs::path("bitmaps/notes_open.png")).scaled(30, 30)), + m_pixmap_closed(QPixmap(MarbleDirs::path("bitmaps/notes_closed.png")).scaled(30, 30)) { - setSize(m_pixmap.size()); + MarbleDebug::setEnabled(true); + + setSize(m_pixmap_open.size()); + setAlignment(Qt::AlignHCenter | Qt::AlignTop); setCacheMode(ItemCoordinateCache); } @@ -37,5 +45,89 @@ void NotesItem::paint(QPainter *painter) { - painter->drawPixmap(0, 0, m_pixmap); + painter->save(); + + painter->setFont(s_font); + const int fontAscent = painter->fontMetrics().ascent(); + QPen outlinepen( Qt::white ); + outlinepen.setWidthF( s_labelOutlineWidth ); + QBrush outlinebrush( Qt::black ); + + const QPointF baseline( s_labelOutlineWidth / 2.0, fontAscent ); + + QPainterPath outlinepath; + outlinepath.addText( baseline, painter->font(), m_labelText ); + + painter->setRenderHint( QPainter::Antialiasing, true ); + painter->setPen( outlinepen ); + painter->setBrush( outlinebrush ); + painter->drawPath( outlinepath ); + painter->setPen( Qt::NoPen ); + painter->drawPath( outlinepath ); + painter->setRenderHint( QPainter::Antialiasing, false ); + + int const y = qMax(0, int(size().width() - m_pixmap_open.width()) / 2); + + //The two pixmaps have the same dimensions, so all the logic for one works for the other + if (m_noteStatus == "open") { + painter->drawPixmap(y, 2 + painter->fontMetrics().height(), m_pixmap_open); + } else if (m_noteStatus == "closed") { + painter->drawPixmap(y, 2 + painter->fontMetrics().height(), m_pixmap_closed); + } + + painter->restore(); } + +void NotesItem::setDateCreated(const QDateTime& dateCreated) +{ + m_dateCreated = dateCreated; +} + +void NotesItem::setDateClosed(const QDateTime& dateClosed) +{ + m_dateClosed = dateClosed; +} + +void NotesItem::setNoteStatus(const QString& noteStatus) +{ + m_noteStatus = noteStatus; +} + +void NotesItem::addLatestComment(const Comment& comment) +{ + m_commentsList.push_back(comment); + std::sort(m_commentsList.begin(), m_commentsList.end(), [] (const Comment& a, const Comment& b) {return a.getDate() < b.getDate();} ); + setComment(m_commentsList.back()); +} + +void NotesItem::setComment(const Comment& comment) +{ + QFontMetrics fontmet(s_font); + m_labelText = fontmet.elidedText(comment.getText(), Qt::ElideRight, 125); + auto const width = qMax(fontmet.width(m_labelText), m_pixmap_open.width()); + setSize(QSizeF(width, fontmet.height() + 2 + m_pixmap_open.height())); +} + +qreal NotesItem::width() +{ + return m_pixmap_open.size().width(); +} + +qreal NotesItem::height() +{ + return m_pixmap_open.size().height(); +} + +Comment::Comment() +{ +} + +Comment::Comment(QDateTime date, QString text, QString user, int uid) + : m_date(date) + , m_text(text) + , m_user(user) +{ + m_uid = uid; +} + +#include "moc_NotesItem.cpp" diff --git a/src/plugins/render/notes/NotesModel.cpp b/src/plugins/render/notes/NotesModel.cpp --- a/src/plugins/render/notes/NotesModel.cpp +++ b/src/plugins/render/notes/NotesModel.cpp @@ -15,7 +15,6 @@ #include "MarbleModel.h" #include "GeoDataCoordinates.h" #include "GeoDataLatLonAltBox.h" -#include "MarbleDebug.h" #include "Planet.h" #include @@ -68,12 +67,32 @@ double longitude = coordinates.at(0).toDouble(); double latitude = coordinates.at(1).toDouble(); - GeoDataCoordinates coordinateset(longitude, latitude, 0.0, GeoDataCoordinates::Degree); - QString id = QString::number(jsonObj.value(QStringLiteral("properties")).toObject().value(QStringLiteral("id")).toInt()); + QJsonObject noteProperties = jsonObj.value(QStringLiteral("properties")).toObject(); + QJsonArray noteComments = noteProperties.value(QStringLiteral("comments")).toArray(); + + QString id = QString::number(noteProperties.value(QStringLiteral("id")).toInt()); + + QDateTime dateCreated = QDateTime::fromString(noteProperties.value(QStringLiteral("date_created")).toString(), Qt::ISODate); + QDateTime dateClosed = QDateTime::fromString(noteProperties.value(QStringLiteral("closed_at")).toString(), Qt::ISODate); + QString noteStatus = noteProperties.value(QStringLiteral("status")).toString(); NotesItem *item = new NotesItem(this); item->setId(id); + GeoDataCoordinates coordinateset(longitude, latitude, 0.0, GeoDataCoordinates::Degree); item->setCoordinate(coordinateset); + item->setDateCreated(dateCreated); + item->setNoteStatus(noteStatus); + item->setDateClosed(dateClosed); + + for (auto commentRef : noteComments) { + QJsonObject commentObj = commentRef.toObject(); + QDateTime date = QDateTime::fromString(commentObj.value("date").toString(), Qt::ISODate); + QString user = commentObj.value("user").toString(); + QString text = commentObj.value("text").toString(); + int uid = commentObj.value("uid").toInt(); + Comment comment(date, text, user, uid); + item->addLatestComment(comment); + } items << item; } diff --git a/src/plugins/render/notes/NotesPlugin.cpp b/src/plugins/render/notes/NotesPlugin.cpp --- a/src/plugins/render/notes/NotesPlugin.cpp +++ b/src/plugins/render/notes/NotesPlugin.cpp @@ -10,6 +10,7 @@ #include "NotesPlugin.h" #include "NotesModel.h" +#include "MarbleDirs.h" #include @@ -71,7 +72,7 @@ QIcon NotesPlugin::icon() const { - return QIcon(); + return QIcon(MarbleDirs::path("bitmaps/notes_open.png")); } #include "moc_NotesPlugin.cpp"