1 #ifndef DECODE_HIGHLIGHTING_MODEL_HPP_ 2 #define DECODE_HIGHLIGHTING_MODEL_HPP_ 3 4 #include <QAbstractListModel> 5 #include <QBrush> 6 #include <QList> 7 8 #include "qt_helpers.hpp" 9 #include "pimpl_h.hpp" 10 11 class QObject; 12 class QFont; 13 class QDataStream; 14 class QDebug; 15 16 class DecodeHighlightingModel final 17 : public QAbstractListModel 18 { 19 Q_OBJECT 20 public: 21 enum class Highlight : char {CQ, MyCall, Tx, DXCC, DXCCBand, Grid, GridBand, Call, CallBand 22 , Continent, ContinentBand, CQZone, CQZoneBand, ITUZone, ITUZoneBand 23 , LotW}; 24 Q_ENUM (Highlight) 25 static QString highlight_name (Highlight h); 26 27 struct HighlightInfo final 28 { 29 Highlight type_; 30 bool enabled_; 31 QBrush foreground_; 32 QBrush background_; 33 QString toString () const; 34 }; 35 using HighlightItems = QList<HighlightInfo>; 36 37 explicit DecodeHighlightingModel (QObject * parent = 0); 38 ~DecodeHighlightingModel(); 39 40 // access to raw items nd default items 41 static HighlightItems const& default_items (); 42 HighlightItems const& items () const; 43 void items (HighlightItems const&); 44 45 void set_font (QFont const&); 46 47 enum DefaultRoles {TypeRole = Qt::UserRole, EnabledDefaultRole, ForegroundDefaultRole, BackgroundDefaultRole}; 48 49 private: 50 // implement the QAbstractListModel interface 51 int rowCount (QModelIndex const& parent = QModelIndex()) const override; 52 QVariant data (QModelIndex const&, int role) const override; 53 QVariant headerData (int section, Qt::Orientation, int role = Qt::DisplayRole) const override; 54 Qt::ItemFlags flags (QModelIndex const&) const override; 55 bool setData (QModelIndex const& index, QVariant const& value, int role) override; 56 Qt::DropActions supportedDropActions () const override; 57 bool insertRows (int row, int count, QModelIndex const& parent = QModelIndex {}) override; 58 bool removeRows (int row, int count, QModelIndex const& parent = QModelIndex {}) override; 59 QMap<int, QVariant> itemData (QModelIndex const&) const override; 60 61 class impl; 62 pimpl<impl> m_; 63 }; 64 65 bool operator == (DecodeHighlightingModel::HighlightInfo const&, DecodeHighlightingModel::HighlightInfo const&); 66 67 QDataStream& operator << (QDataStream&, DecodeHighlightingModel::HighlightInfo const&); 68 QDataStream& operator >> (QDataStream&, DecodeHighlightingModel::HighlightInfo&); 69 70 #if !defined (QT_NO_DEBUG_STREAM) 71 QDebug operator << (QDebug, DecodeHighlightingModel::HighlightInfo const&); 72 #endif 73 74 ENUM_QDATASTREAM_OPS_DECL (DecodeHighlightingModel, Highlight); 75 ENUM_CONVERSION_OPS_DECL (DecodeHighlightingModel, Highlight); 76 77 Q_DECLARE_METATYPE (DecodeHighlightingModel::HighlightInfo); 78 Q_DECLARE_METATYPE (DecodeHighlightingModel::HighlightItems); 79 80 #endif 81