From 722906212fc388aa112ecba8776391e4553ad96f Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Fri, 27 Sep 2019 00:27:15 +0200 Subject: [PATCH 1/2] Remove forward declarations of Qt classes and fix formatting --- src/library/tableitemdelegate.cpp | 12 +++++------- src/library/tableitemdelegate.h | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/library/tableitemdelegate.cpp b/src/library/tableitemdelegate.cpp index 3d1b2a31e6d4..0eefbbb1c78d 100644 --- a/src/library/tableitemdelegate.cpp +++ b/src/library/tableitemdelegate.cpp @@ -1,20 +1,18 @@ +#include "library/tableitemdelegate.h" #include #include -#include "library/tableitemdelegate.h" - TableItemDelegate::TableItemDelegate(QTableView* pTableView) : QStyledItemDelegate(pTableView), m_pTableView(pTableView) { } -TableItemDelegate::~TableItemDelegate() { -} - -void TableItemDelegate::paint(QPainter* painter,const QStyleOptionViewItem& option, - const QModelIndex& index) const { +void TableItemDelegate::paint( + QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index) const { painter->save(); diff --git a/src/library/tableitemdelegate.h b/src/library/tableitemdelegate.h index a39071aac319..5a63960ce92f 100644 --- a/src/library/tableitemdelegate.h +++ b/src/library/tableitemdelegate.h @@ -1,25 +1,25 @@ -#ifndef TABLEITEMDELEGATE_H -#define TABLEITEMDELEGATE_H +#pragma once #include +#include -class QTableView; -class QStyleOptionViewItem; class TableItemDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit TableItemDelegate(QTableView* pTableView); - virtual ~TableItemDelegate(); + ~TableItemDelegate() override = default; - void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; + void paint( + QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const override; - virtual void paintItem(QPainter *painter, const QStyleOptionViewItem &option, + virtual void paintItem( + QPainter *painter, + const QStyleOptionViewItem &option, const QModelIndex &index) const = 0; private: QTableView* m_pTableView; }; - -#endif // TABLEITEMDELEGATE_H From cf9b09e26bc18626b7fb670472af333f7d3a193a Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Fri, 27 Sep 2019 00:30:59 +0200 Subject: [PATCH 2/2] Fix inheritance of LocationDelegate --- src/library/locationdelegate.cpp | 21 ++++++++++----------- src/library/locationdelegate.h | 23 +++++++++-------------- src/library/tableitemdelegate.cpp | 4 ++++ src/library/tableitemdelegate.h | 3 +++ 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/library/locationdelegate.cpp b/src/library/locationdelegate.cpp index 7e1f07bb1c27..51611616f6fe 100644 --- a/src/library/locationdelegate.cpp +++ b/src/library/locationdelegate.cpp @@ -1,20 +1,19 @@ -#include +#include "library/locationdelegate.h" -#include #include -#include "library/locationdelegate.h" LocationDelegate::LocationDelegate(QTableView* pTableView) - : QStyledItemDelegate(pTableView), - m_pTableView(pTableView) { + : TableItemDelegate(pTableView) { } -void LocationDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const { - QString elidedLocation = - option.fontMetrics.elidedText(index.data().toString(), - Qt::ElideLeft, - m_pTableView->columnWidth(index.column())); +void LocationDelegate::paintItem( + QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index) const { + QString elidedLocation = option.fontMetrics.elidedText( + index.data().toString(), + Qt::ElideLeft, + columnWidth(index)); painter->drawText(option.rect, Qt::AlignVCenter, elidedLocation); } diff --git a/src/library/locationdelegate.h b/src/library/locationdelegate.h index 1f20dcc8e22f..9fb698dab21a 100644 --- a/src/library/locationdelegate.h +++ b/src/library/locationdelegate.h @@ -1,21 +1,16 @@ -#ifndef LOCATIONDELEGATE_H -#define LOCATIONDELEGATE_H +#pragma once -#include +#include "library/tableitemdelegate.h" -class QTableView; -class QStyleOptionViewItem; -class LocationDelegate : public QStyledItemDelegate { +class LocationDelegate : public TableItemDelegate { Q_OBJECT public: - LocationDelegate(QTableView* pTrackTable); + explicit LocationDelegate(QTableView* pTrackTable); + ~LocationDelegate() override = default; - void paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const; - - private: - QTableView* m_pTableView; + void paintItem( + QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index) const override; }; - -#endif /* LOCATIONDELEGATE_H */ diff --git a/src/library/tableitemdelegate.cpp b/src/library/tableitemdelegate.cpp index 0eefbbb1c78d..79d2e1272537 100644 --- a/src/library/tableitemdelegate.cpp +++ b/src/library/tableitemdelegate.cpp @@ -44,3 +44,7 @@ void TableItemDelegate::paint( painter->restore(); } + +int TableItemDelegate::columnWidth(const QModelIndex &index) const { + return m_pTableView->columnWidth(index.column()); +} diff --git a/src/library/tableitemdelegate.h b/src/library/tableitemdelegate.h index 5a63960ce92f..117796599616 100644 --- a/src/library/tableitemdelegate.h +++ b/src/library/tableitemdelegate.h @@ -20,6 +20,9 @@ class TableItemDelegate : public QStyledItemDelegate { const QStyleOptionViewItem &option, const QModelIndex &index) const = 0; + protected: + int columnWidth(const QModelIndex &index) const; + private: QTableView* m_pTableView; };