From 992d4b4b8d3f3a630a2cf00d593ee4ce4dfa7ce8 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Thu, 9 Jan 2025 22:12:06 +0100 Subject: New upstream version 2.7.0~rc8+repack --- item_delegates/CallsignDelegate.cpp | 62 +++++----- item_delegates/CallsignDelegate.hpp | 60 ++++----- item_delegates/CandidateKeyFilter.cpp | 178 +++++++++++++-------------- item_delegates/CandidateKeyFilter.hpp | 82 ++++++------ item_delegates/ForeignKeyDelegate.cpp | 122 +++++++++--------- item_delegates/ForeignKeyDelegate.hpp | 86 ++++++------- item_delegates/FrequencyDelegate.cpp | 54 ++++---- item_delegates/FrequencyDelegate.hpp | 42 +++---- item_delegates/FrequencyDeltaDelegate.cpp | 52 ++++---- item_delegates/FrequencyDeltaDelegate.hpp | 42 +++---- item_delegates/MaidenheadLocatorDelegate.cpp | 60 ++++----- item_delegates/MaidenheadLocatorDelegate.hpp | 60 ++++----- item_delegates/MessageItemDelegate.cpp | 52 ++++---- item_delegates/MessageItemDelegate.hpp | 40 +++--- item_delegates/SQLiteDateTimeDelegate.cpp | 80 ++++++------ item_delegates/SQLiteDateTimeDelegate.hpp | 46 +++---- item_delegates/item_delegates.pri | 26 ++-- 17 files changed, 572 insertions(+), 572 deletions(-) (limited to 'item_delegates') diff --git a/item_delegates/CallsignDelegate.cpp b/item_delegates/CallsignDelegate.cpp index 074da6e2..d3b9864c 100755 --- a/item_delegates/CallsignDelegate.cpp +++ b/item_delegates/CallsignDelegate.cpp @@ -1,31 +1,31 @@ -#include "CallsignDelegate.hpp" - -#include - -#include "validators/CallsignValidator.hpp" - -CallsignDelegate::CallsignDelegate (QObject * parent) - : QStyledItemDelegate {parent} - , validator_ {new CallsignValidator} -{ -} - -QWidget * CallsignDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const& - , QModelIndex const&) const -{ - auto * editor = new QLineEdit {parent}; - editor->setFrame (false); - editor->setValidator (validator_.data ()); - return editor; -} - -void CallsignDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const -{ - static_cast (editor)->setText (index.model ()->data (index, Qt::EditRole).toString ()); -} - -void CallsignDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const -{ - model->setData (index, static_cast (editor)->text (), Qt::EditRole); -} - +#include "CallsignDelegate.hpp" + +#include + +#include "validators/CallsignValidator.hpp" + +CallsignDelegate::CallsignDelegate (QObject * parent) + : QStyledItemDelegate {parent} + , validator_ {new CallsignValidator} +{ +} + +QWidget * CallsignDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const& + , QModelIndex const&) const +{ + auto * editor = new QLineEdit {parent}; + editor->setFrame (false); + editor->setValidator (validator_.data ()); + return editor; +} + +void CallsignDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const +{ + static_cast (editor)->setText (index.model ()->data (index, Qt::EditRole).toString ()); +} + +void CallsignDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const +{ + model->setData (index, static_cast (editor)->text (), Qt::EditRole); +} + diff --git a/item_delegates/CallsignDelegate.hpp b/item_delegates/CallsignDelegate.hpp index aeecc520..b5bdce1c 100755 --- a/item_delegates/CallsignDelegate.hpp +++ b/item_delegates/CallsignDelegate.hpp @@ -1,30 +1,30 @@ -#ifndef CALLSIGN_DELEGATE_HPP_ -#define CALLSIGN_DELEGATE_HPP_ - -#include - -class QValidator; - -// -// Class CallsignDelegate -// -// Item delegate for editing a callsign -// -class CallsignDelegate final - : public QStyledItemDelegate -{ -public: - explicit CallsignDelegate (QObject * parent = nullptr); - QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; - void setEditorData (QWidget * editor, QModelIndex const&) const override; - void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override; - void updateEditorGeometry (QWidget * editor, QStyleOptionViewItem const& option, QModelIndex const&) const override - { - editor->setGeometry (option.rect); - } - -private: - QScopedPointer validator_; -}; - -#endif +#ifndef CALLSIGN_DELEGATE_HPP_ +#define CALLSIGN_DELEGATE_HPP_ + +#include + +class QValidator; + +// +// Class CallsignDelegate +// +// Item delegate for editing a callsign +// +class CallsignDelegate final + : public QStyledItemDelegate +{ +public: + explicit CallsignDelegate (QObject * parent = nullptr); + QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; + void setEditorData (QWidget * editor, QModelIndex const&) const override; + void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override; + void updateEditorGeometry (QWidget * editor, QStyleOptionViewItem const& option, QModelIndex const&) const override + { + editor->setGeometry (option.rect); + } + +private: + QScopedPointer validator_; +}; + +#endif diff --git a/item_delegates/CandidateKeyFilter.cpp b/item_delegates/CandidateKeyFilter.cpp index cf08077e..306e4102 100755 --- a/item_delegates/CandidateKeyFilter.cpp +++ b/item_delegates/CandidateKeyFilter.cpp @@ -1,89 +1,89 @@ -#include "CandidateKeyFilter.hpp" - -#include -#include - -#include "pimpl_impl.hpp" - -class CandidateKeyFilter::impl final -{ -public: - explicit impl (int referenced_key_column - , int referenced_key_role - , QAbstractItemModel const * referencing_model - , int referencing_key_column - , int referencing_key_role) - : referencing_ {referencing_model} - , referencing_key_column_ {referencing_key_column} - , referencing_key_role_ {referencing_key_role} - , referenced_key_column_ {referenced_key_column} - , referenced_key_role_ {referenced_key_role} - { - } - - QAbstractItemModel const * referencing_; - int referencing_key_column_; - int referencing_key_role_; - int referenced_key_column_; - int referenced_key_role_; - QModelIndex active_key_; -}; - -CandidateKeyFilter::CandidateKeyFilter (QAbstractItemModel const * referenced_model - , int referenced_key_column - , QObject * parent - , int referenced_key_role) - : QSortFilterProxyModel {parent} - , m_ {referenced_key_column, referenced_key_role, nullptr, 0, Qt::EditRole} -{ - setSourceModel (const_cast (referenced_model)); -} - -CandidateKeyFilter::CandidateKeyFilter (QAbstractItemModel const * referenced_model - , QAbstractItemModel const * referencing_model - , int referenced_key_column - , int referencing_key_column - , QObject * parent - , int referenced_key_role - , int referencing_key_role) - : QSortFilterProxyModel {parent} - , m_ {referenced_key_column, referenced_key_role, referencing_model, referencing_key_column, referencing_key_role} -{ - setSourceModel (const_cast (referenced_model)); -} - -CandidateKeyFilter::~CandidateKeyFilter () -{ -} - -void CandidateKeyFilter::set_active_key (QModelIndex const& index) -{ - if (m_->referencing_) - { - if (index.isValid () ) - { - Q_ASSERT (index.column () == m_->referencing_key_column_); - m_->active_key_ = index; - } - invalidateFilter (); - } -} - -bool CandidateKeyFilter::filterAcceptsRow (int candidate_row, QModelIndex const& candidate_parent) const -{ - if (!m_->referencing_) // many to many passes all - { - return true; - } - - auto candidate_key = sourceModel ()->index (candidate_row, m_->referenced_key_column_, candidate_parent).data (m_->referenced_key_role_); - - // Include the current key. - if (m_->active_key_.isValid () && candidate_key == m_->active_key_.data (m_->referencing_key_role_)) - { - return true; - } - - // Filter out any candidates already in the referencing key rows. - return m_->referencing_->match (m_->referencing_->index (0, m_->referencing_key_column_), m_->referencing_key_role_, candidate_key, 1, Qt::MatchExactly).isEmpty (); -} +#include "CandidateKeyFilter.hpp" + +#include +#include + +#include "pimpl_impl.hpp" + +class CandidateKeyFilter::impl final +{ +public: + explicit impl (int referenced_key_column + , int referenced_key_role + , QAbstractItemModel const * referencing_model + , int referencing_key_column + , int referencing_key_role) + : referencing_ {referencing_model} + , referencing_key_column_ {referencing_key_column} + , referencing_key_role_ {referencing_key_role} + , referenced_key_column_ {referenced_key_column} + , referenced_key_role_ {referenced_key_role} + { + } + + QAbstractItemModel const * referencing_; + int referencing_key_column_; + int referencing_key_role_; + int referenced_key_column_; + int referenced_key_role_; + QModelIndex active_key_; +}; + +CandidateKeyFilter::CandidateKeyFilter (QAbstractItemModel const * referenced_model + , int referenced_key_column + , QObject * parent + , int referenced_key_role) + : QSortFilterProxyModel {parent} + , m_ {referenced_key_column, referenced_key_role, nullptr, 0, Qt::EditRole} +{ + setSourceModel (const_cast (referenced_model)); +} + +CandidateKeyFilter::CandidateKeyFilter (QAbstractItemModel const * referenced_model + , QAbstractItemModel const * referencing_model + , int referenced_key_column + , int referencing_key_column + , QObject * parent + , int referenced_key_role + , int referencing_key_role) + : QSortFilterProxyModel {parent} + , m_ {referenced_key_column, referenced_key_role, referencing_model, referencing_key_column, referencing_key_role} +{ + setSourceModel (const_cast (referenced_model)); +} + +CandidateKeyFilter::~CandidateKeyFilter () +{ +} + +void CandidateKeyFilter::set_active_key (QModelIndex const& index) +{ + if (m_->referencing_) + { + if (index.isValid () ) + { + Q_ASSERT (index.column () == m_->referencing_key_column_); + m_->active_key_ = index; + } + invalidateFilter (); + } +} + +bool CandidateKeyFilter::filterAcceptsRow (int candidate_row, QModelIndex const& candidate_parent) const +{ + if (!m_->referencing_) // many to many passes all + { + return true; + } + + auto candidate_key = sourceModel ()->index (candidate_row, m_->referenced_key_column_, candidate_parent).data (m_->referenced_key_role_); + + // Include the current key. + if (m_->active_key_.isValid () && candidate_key == m_->active_key_.data (m_->referencing_key_role_)) + { + return true; + } + + // Filter out any candidates already in the referencing key rows. + return m_->referencing_->match (m_->referencing_->index (0, m_->referencing_key_column_), m_->referencing_key_role_, candidate_key, 1, Qt::MatchExactly).isEmpty (); +} diff --git a/item_delegates/CandidateKeyFilter.hpp b/item_delegates/CandidateKeyFilter.hpp index 60801350..27f1892b 100755 --- a/item_delegates/CandidateKeyFilter.hpp +++ b/item_delegates/CandidateKeyFilter.hpp @@ -1,41 +1,41 @@ -#ifndef CANDIDATE_KEY_FILTER_HPP_ -#define CANDIDATE_KEY_FILTER_HPP_ - -#include -#include - -#include "pimpl_h.hpp" - -class QAbstractItemModel; - -class CandidateKeyFilter final - : public QSortFilterProxyModel -{ -public: - explicit CandidateKeyFilter (QAbstractItemModel const * referenced_model - , int referenced_key_column - , QObject * parent = nullptr - , int referenced_key_role = Qt::EditRole); - explicit CandidateKeyFilter (QAbstractItemModel const * referenced_model - , QAbstractItemModel const * referencing_model - , int referenced_key_column - , int referencing_key_column - , QObject * parent = nullptr - , int referenced_key_role = Qt::EditRole - , int referencing_key_role = Qt::EditRole); - ~CandidateKeyFilter (); - - // this key is not to be filtered, usually because we want to allow - // it since we are editing the row that contains it this it is valid - // even though it is in use - void set_active_key (QModelIndex const& index = QModelIndex {}); - -protected: - bool filterAcceptsRow (int candidate_row, QModelIndex const& candidate_parent) const override; - -private: - class impl; - pimpl m_; -}; - -#endif +#ifndef CANDIDATE_KEY_FILTER_HPP_ +#define CANDIDATE_KEY_FILTER_HPP_ + +#include +#include + +#include "pimpl_h.hpp" + +class QAbstractItemModel; + +class CandidateKeyFilter final + : public QSortFilterProxyModel +{ +public: + explicit CandidateKeyFilter (QAbstractItemModel const * referenced_model + , int referenced_key_column + , QObject * parent = nullptr + , int referenced_key_role = Qt::EditRole); + explicit CandidateKeyFilter (QAbstractItemModel const * referenced_model + , QAbstractItemModel const * referencing_model + , int referenced_key_column + , int referencing_key_column + , QObject * parent = nullptr + , int referenced_key_role = Qt::EditRole + , int referencing_key_role = Qt::EditRole); + ~CandidateKeyFilter (); + + // this key is not to be filtered, usually because we want to allow + // it since we are editing the row that contains it this it is valid + // even though it is in use + void set_active_key (QModelIndex const& index = QModelIndex {}); + +protected: + bool filterAcceptsRow (int candidate_row, QModelIndex const& candidate_parent) const override; + +private: + class impl; + pimpl m_; +}; + +#endif diff --git a/item_delegates/ForeignKeyDelegate.cpp b/item_delegates/ForeignKeyDelegate.cpp index 2c9219d6..9ce0bd17 100755 --- a/item_delegates/ForeignKeyDelegate.cpp +++ b/item_delegates/ForeignKeyDelegate.cpp @@ -1,61 +1,61 @@ -#include "ForeignKeyDelegate.hpp" - -#include -#include -#include -#include -#include -#include "CandidateKeyFilter.hpp" - -ForeignKeyDelegate::ForeignKeyDelegate (QAbstractItemModel const * referenced_model - , int referenced_key_column - , QObject * parent - , int referenced_key_role) - : QStyledItemDelegate {parent} - , candidate_key_filter_ {new CandidateKeyFilter {referenced_model, referenced_key_column, nullptr, referenced_key_role}} -{ -} - -ForeignKeyDelegate::ForeignKeyDelegate (QAbstractItemModel const * referenced_model - , QAbstractItemModel const * referencing_model - , int referenced_key_column - , int referencing_key_column - , QObject * parent - , int referenced_key_role - , int referencing_key_role) - : QStyledItemDelegate {parent} - , candidate_key_filter_ {new CandidateKeyFilter {referenced_model, referencing_model, referenced_key_column, referencing_key_column, nullptr, referenced_key_role, referencing_key_role}} -{ -} - -ForeignKeyDelegate::~ForeignKeyDelegate () -{ -} - -QWidget * ForeignKeyDelegate::createEditor (QWidget * parent - , QStyleOptionViewItem const& /* option */ - , QModelIndex const& index) const -{ - auto editor = new QComboBox {parent}; - editor->setFrame (false); - candidate_key_filter_->set_active_key (index); - editor->setModel (candidate_key_filter_.data ()); - editor->setSizeAdjustPolicy (QComboBox::AdjustToContents); - return editor; -} - -QSize ForeignKeyDelegate::sizeHint (QStyleOptionViewItem const& option, QModelIndex const& index) const -{ - auto size_hint = QStyledItemDelegate::sizeHint (option, index); - QFontMetrics metrics {option.font}; - QStyleOptionComboBox combo_box_option; - combo_box_option.rect = option.rect; - combo_box_option.state = option.state | QStyle::State_Enabled; - for (auto row = 0; row < candidate_key_filter_->rowCount (); ++row) - { - size_hint = size_hint.expandedTo (qApp->style ()->sizeFromContents (QStyle::CT_ComboBox - , &combo_box_option - , metrics.boundingRect (candidate_key_filter_->data (candidate_key_filter_->index (row, 0)).toString ()).size ())); - } - return size_hint; -} +#include "ForeignKeyDelegate.hpp" + +#include +#include +#include +#include +#include +#include "CandidateKeyFilter.hpp" + +ForeignKeyDelegate::ForeignKeyDelegate (QAbstractItemModel const * referenced_model + , int referenced_key_column + , QObject * parent + , int referenced_key_role) + : QStyledItemDelegate {parent} + , candidate_key_filter_ {new CandidateKeyFilter {referenced_model, referenced_key_column, nullptr, referenced_key_role}} +{ +} + +ForeignKeyDelegate::ForeignKeyDelegate (QAbstractItemModel const * referenced_model + , QAbstractItemModel const * referencing_model + , int referenced_key_column + , int referencing_key_column + , QObject * parent + , int referenced_key_role + , int referencing_key_role) + : QStyledItemDelegate {parent} + , candidate_key_filter_ {new CandidateKeyFilter {referenced_model, referencing_model, referenced_key_column, referencing_key_column, nullptr, referenced_key_role, referencing_key_role}} +{ +} + +ForeignKeyDelegate::~ForeignKeyDelegate () +{ +} + +QWidget * ForeignKeyDelegate::createEditor (QWidget * parent + , QStyleOptionViewItem const& /* option */ + , QModelIndex const& index) const +{ + auto editor = new QComboBox {parent}; + editor->setFrame (false); + candidate_key_filter_->set_active_key (index); + editor->setModel (candidate_key_filter_.data ()); + editor->setSizeAdjustPolicy (QComboBox::AdjustToContents); + return editor; +} + +QSize ForeignKeyDelegate::sizeHint (QStyleOptionViewItem const& option, QModelIndex const& index) const +{ + auto size_hint = QStyledItemDelegate::sizeHint (option, index); + QFontMetrics metrics {option.font}; + QStyleOptionComboBox combo_box_option; + combo_box_option.rect = option.rect; + combo_box_option.state = option.state | QStyle::State_Enabled; + for (auto row = 0; row < candidate_key_filter_->rowCount (); ++row) + { + size_hint = size_hint.expandedTo (qApp->style ()->sizeFromContents (QStyle::CT_ComboBox + , &combo_box_option + , metrics.boundingRect (candidate_key_filter_->data (candidate_key_filter_->index (row, 0)).toString ()).size ())); + } + return size_hint; +} diff --git a/item_delegates/ForeignKeyDelegate.hpp b/item_delegates/ForeignKeyDelegate.hpp index 696fc32b..4f58f460 100755 --- a/item_delegates/ForeignKeyDelegate.hpp +++ b/item_delegates/ForeignKeyDelegate.hpp @@ -1,43 +1,43 @@ -#ifndef FOREIGN_KEY_DELEGATE_HPP_ -#define FOREIGN_KEY_DELEGATE_HPP_ - -#include -#include - -class CandidateKeyFilter; - -// -// Class ForeignKeyDelegate -// -// Item delegate for editing a foreign key item in a one or many -// to one relationship. A QComboBox is used as an item delegate -// for the edit role. -// -class ForeignKeyDelegate final - : public QStyledItemDelegate -{ -public: - // many to many relationship - explicit ForeignKeyDelegate (QAbstractItemModel const * referenced_model - , int referenced_key_column - , QObject * parent = nullptr - , int referenced_key_role = Qt::EditRole); - - // one to many (referenced to referencing) relationship - explicit ForeignKeyDelegate (QAbstractItemModel const * referenced_model - , QAbstractItemModel const * referencing_model - , int referenced_key_column - , int referencing_key_column - , QObject * parent = nullptr - , int referenced_key_role = Qt::EditRole - , int referencing_key_role = Qt::EditRole); - ~ForeignKeyDelegate (); - -private: - QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; - QSize sizeHint (QStyleOptionViewItem const&, QModelIndex const&) const override; - - QScopedPointer candidate_key_filter_; -}; - -#endif +#ifndef FOREIGN_KEY_DELEGATE_HPP_ +#define FOREIGN_KEY_DELEGATE_HPP_ + +#include +#include + +class CandidateKeyFilter; + +// +// Class ForeignKeyDelegate +// +// Item delegate for editing a foreign key item in a one or many +// to one relationship. A QComboBox is used as an item delegate +// for the edit role. +// +class ForeignKeyDelegate final + : public QStyledItemDelegate +{ +public: + // many to many relationship + explicit ForeignKeyDelegate (QAbstractItemModel const * referenced_model + , int referenced_key_column + , QObject * parent = nullptr + , int referenced_key_role = Qt::EditRole); + + // one to many (referenced to referencing) relationship + explicit ForeignKeyDelegate (QAbstractItemModel const * referenced_model + , QAbstractItemModel const * referencing_model + , int referenced_key_column + , int referencing_key_column + , QObject * parent = nullptr + , int referenced_key_role = Qt::EditRole + , int referencing_key_role = Qt::EditRole); + ~ForeignKeyDelegate (); + +private: + QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; + QSize sizeHint (QStyleOptionViewItem const&, QModelIndex const&) const override; + + QScopedPointer candidate_key_filter_; +}; + +#endif diff --git a/item_delegates/FrequencyDelegate.cpp b/item_delegates/FrequencyDelegate.cpp index da081dd0..b899c056 100755 --- a/item_delegates/FrequencyDelegate.cpp +++ b/item_delegates/FrequencyDelegate.cpp @@ -1,27 +1,27 @@ -#include "FrequencyDelegate.hpp" - -#include "widgets/FrequencyLineEdit.hpp" - -FrequencyDelegate::FrequencyDelegate (QObject * parent) - : QStyledItemDelegate {parent} -{ -} - -QWidget * FrequencyDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const& - , QModelIndex const&) const -{ - auto * editor = new FrequencyLineEdit {parent}; - editor->setFrame (false); - return editor; -} - -void FrequencyDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const -{ - static_cast (editor)->frequency (index.model ()->data (index, Qt::EditRole).value ()); -} - -void FrequencyDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const -{ - model->setData (index, static_cast (editor)->frequency (), Qt::EditRole); -} - +#include "FrequencyDelegate.hpp" + +#include "widgets/FrequencyLineEdit.hpp" + +FrequencyDelegate::FrequencyDelegate (QObject * parent) + : QStyledItemDelegate {parent} +{ +} + +QWidget * FrequencyDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const& + , QModelIndex const&) const +{ + auto * editor = new FrequencyLineEdit {parent}; + editor->setFrame (false); + return editor; +} + +void FrequencyDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const +{ + static_cast (editor)->frequency (index.model ()->data (index, Qt::EditRole).value ()); +} + +void FrequencyDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const +{ + model->setData (index, static_cast (editor)->frequency (), Qt::EditRole); +} + diff --git a/item_delegates/FrequencyDelegate.hpp b/item_delegates/FrequencyDelegate.hpp index 9278f6b4..76fc5545 100755 --- a/item_delegates/FrequencyDelegate.hpp +++ b/item_delegates/FrequencyDelegate.hpp @@ -1,21 +1,21 @@ -#ifndef FREQUENCY_DELEGATE_HPP_ -#define FREQUENCY_DELEGATE_HPP_ - -#include - -// -// Class FrequencyDelegate -// -// Item delegate for editing a frequency in Hertz but displayed in MHz -// -class FrequencyDelegate final - : public QStyledItemDelegate -{ -public: - explicit FrequencyDelegate (QObject * parent = nullptr); - QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; - void setEditorData (QWidget * editor, QModelIndex const&) const override; - void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override; -}; - -#endif +#ifndef FREQUENCY_DELEGATE_HPP_ +#define FREQUENCY_DELEGATE_HPP_ + +#include + +// +// Class FrequencyDelegate +// +// Item delegate for editing a frequency in Hertz but displayed in MHz +// +class FrequencyDelegate final + : public QStyledItemDelegate +{ +public: + explicit FrequencyDelegate (QObject * parent = nullptr); + QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; + void setEditorData (QWidget * editor, QModelIndex const&) const override; + void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override; +}; + +#endif diff --git a/item_delegates/FrequencyDeltaDelegate.cpp b/item_delegates/FrequencyDeltaDelegate.cpp index 6dc466af..40d90dc5 100755 --- a/item_delegates/FrequencyDeltaDelegate.cpp +++ b/item_delegates/FrequencyDeltaDelegate.cpp @@ -1,26 +1,26 @@ -#include "FrequencyDeltaDelegate.hpp" - -#include "widgets/FrequencyDeltaLineEdit.hpp" - -FrequencyDeltaDelegate::FrequencyDeltaDelegate (QObject * parent) - : QStyledItemDelegate {parent} -{ -} - -QWidget * FrequencyDeltaDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const& - , QModelIndex const&) const -{ - auto * editor = new FrequencyDeltaLineEdit {parent}; - editor->setFrame (false); - return editor; -} - -void FrequencyDeltaDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const -{ - static_cast (editor)->frequency_delta (index.model ()->data (index, Qt::EditRole).value ()); -} - -void FrequencyDeltaDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const -{ - model->setData (index, static_cast (editor)->frequency_delta (), Qt::EditRole); -} +#include "FrequencyDeltaDelegate.hpp" + +#include "widgets/FrequencyDeltaLineEdit.hpp" + +FrequencyDeltaDelegate::FrequencyDeltaDelegate (QObject * parent) + : QStyledItemDelegate {parent} +{ +} + +QWidget * FrequencyDeltaDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const& + , QModelIndex const&) const +{ + auto * editor = new FrequencyDeltaLineEdit {parent}; + editor->setFrame (false); + return editor; +} + +void FrequencyDeltaDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const +{ + static_cast (editor)->frequency_delta (index.model ()->data (index, Qt::EditRole).value ()); +} + +void FrequencyDeltaDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const +{ + model->setData (index, static_cast (editor)->frequency_delta (), Qt::EditRole); +} diff --git a/item_delegates/FrequencyDeltaDelegate.hpp b/item_delegates/FrequencyDeltaDelegate.hpp index 4188fd23..121bc3d9 100755 --- a/item_delegates/FrequencyDeltaDelegate.hpp +++ b/item_delegates/FrequencyDeltaDelegate.hpp @@ -1,21 +1,21 @@ -#ifndef FREQUENCY_DELTA_DELEGATE_HPP_ -#define FREQUENCY_DELTA_DELEGATE_HPP_ - -#include - -// -// Class FrequencyDeltaDelegate -// -// Item delegate for editing a frequency delta in Hertz but displayed in MHz -// -class FrequencyDeltaDelegate final - : public QStyledItemDelegate -{ -public: - explicit FrequencyDeltaDelegate (QObject * parent = nullptr); - QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; - void setEditorData (QWidget * editor, QModelIndex const&) const override; - void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override; -}; - -#endif +#ifndef FREQUENCY_DELTA_DELEGATE_HPP_ +#define FREQUENCY_DELTA_DELEGATE_HPP_ + +#include + +// +// Class FrequencyDeltaDelegate +// +// Item delegate for editing a frequency delta in Hertz but displayed in MHz +// +class FrequencyDeltaDelegate final + : public QStyledItemDelegate +{ +public: + explicit FrequencyDeltaDelegate (QObject * parent = nullptr); + QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; + void setEditorData (QWidget * editor, QModelIndex const&) const override; + void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override; +}; + +#endif diff --git a/item_delegates/MaidenheadLocatorDelegate.cpp b/item_delegates/MaidenheadLocatorDelegate.cpp index 44cc42ce..7768f2a8 100755 --- a/item_delegates/MaidenheadLocatorDelegate.cpp +++ b/item_delegates/MaidenheadLocatorDelegate.cpp @@ -1,30 +1,30 @@ -#include "MaidenheadLocatorDelegate.hpp" - -#include - -#include "validators/MaidenheadLocatorValidator.hpp" - -MaidenheadLocatorDelegate::MaidenheadLocatorDelegate (QObject * parent) - : QStyledItemDelegate {parent} - , validator_ {new MaidenheadLocatorValidator} -{ -} - -QWidget * MaidenheadLocatorDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const& - , QModelIndex const&) const -{ - auto * editor = new QLineEdit {parent}; - editor->setFrame (false); - editor->setValidator (validator_.data ()); - return editor; -} - -void MaidenheadLocatorDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const -{ - static_cast (editor)->setText (index.model ()->data (index, Qt::EditRole).toString ()); -} - -void MaidenheadLocatorDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const -{ - model->setData (index, static_cast (editor)->text (), Qt::EditRole); -} +#include "MaidenheadLocatorDelegate.hpp" + +#include + +#include "validators/MaidenheadLocatorValidator.hpp" + +MaidenheadLocatorDelegate::MaidenheadLocatorDelegate (QObject * parent) + : QStyledItemDelegate {parent} + , validator_ {new MaidenheadLocatorValidator} +{ +} + +QWidget * MaidenheadLocatorDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const& + , QModelIndex const&) const +{ + auto * editor = new QLineEdit {parent}; + editor->setFrame (false); + editor->setValidator (validator_.data ()); + return editor; +} + +void MaidenheadLocatorDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const +{ + static_cast (editor)->setText (index.model ()->data (index, Qt::EditRole).toString ()); +} + +void MaidenheadLocatorDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const +{ + model->setData (index, static_cast (editor)->text (), Qt::EditRole); +} diff --git a/item_delegates/MaidenheadLocatorDelegate.hpp b/item_delegates/MaidenheadLocatorDelegate.hpp index 9a4a7f82..39627523 100755 --- a/item_delegates/MaidenheadLocatorDelegate.hpp +++ b/item_delegates/MaidenheadLocatorDelegate.hpp @@ -1,30 +1,30 @@ -#ifndef MAIDENHEAD_LOCATOR_DELEGATE_HPP_ -#define MAIDENHEAD_LOCATOR_DELEGATE_HPP_ - -#include - -class QValidator; - -// -// Class MaidenheadLocatorDelegate -// -// Item delegate for editing a Maidenhead locator -// -class MaidenheadLocatorDelegate final - : public QStyledItemDelegate -{ -public: - explicit MaidenheadLocatorDelegate (QObject * parent = nullptr); - QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; - void setEditorData (QWidget * editor, QModelIndex const&) const override; - void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override; - void updateEditorGeometry (QWidget * editor, QStyleOptionViewItem const& option, QModelIndex const&) const override - { - editor->setGeometry (option.rect); - } - -private: - QScopedPointer validator_; -}; - -#endif +#ifndef MAIDENHEAD_LOCATOR_DELEGATE_HPP_ +#define MAIDENHEAD_LOCATOR_DELEGATE_HPP_ + +#include + +class QValidator; + +// +// Class MaidenheadLocatorDelegate +// +// Item delegate for editing a Maidenhead locator +// +class MaidenheadLocatorDelegate final + : public QStyledItemDelegate +{ +public: + explicit MaidenheadLocatorDelegate (QObject * parent = nullptr); + QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; + void setEditorData (QWidget * editor, QModelIndex const&) const override; + void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override; + void updateEditorGeometry (QWidget * editor, QStyleOptionViewItem const& option, QModelIndex const&) const override + { + editor->setGeometry (option.rect); + } + +private: + QScopedPointer validator_; +}; + +#endif diff --git a/item_delegates/MessageItemDelegate.cpp b/item_delegates/MessageItemDelegate.cpp index c1864f62..df9953e4 100755 --- a/item_delegates/MessageItemDelegate.cpp +++ b/item_delegates/MessageItemDelegate.cpp @@ -1,26 +1,26 @@ -// -// Moved from Configuration.cpp -// - -#include "MessageItemDelegate.hpp" - -#include -#include - -// -// Class MessageItemDelegate -// -// Item delegate for message entry such as free text message macros. -// -MessageItemDelegate::MessageItemDelegate(QObject *parent): QStyledItemDelegate{parent} -{ -} - -QWidget *MessageItemDelegate::createEditor(QWidget *parent, QStyleOptionViewItem const &, QModelIndex const &) const -{ - QRegularExpression message_alphabet{"[- @A-Za-z0-9+./?#<>;$]*"}; - auto editor = new QLineEdit{parent}; - editor->setFrame(false); - editor->setValidator(new QRegularExpressionValidator{message_alphabet, editor}); - return editor; -} +// +// Moved from Configuration.cpp +// + +#include "MessageItemDelegate.hpp" + +#include +#include + +// +// Class MessageItemDelegate +// +// Item delegate for message entry such as free text message macros. +// +MessageItemDelegate::MessageItemDelegate(QObject *parent): QStyledItemDelegate{parent} +{ +} + +QWidget *MessageItemDelegate::createEditor(QWidget *parent, QStyleOptionViewItem const &, QModelIndex const &) const +{ + QRegularExpression message_alphabet{"[- @A-Za-z0-9+./?#<>;$]*"}; + auto editor = new QLineEdit{parent}; + editor->setFrame(false); + editor->setValidator(new QRegularExpressionValidator{message_alphabet, editor}); + return editor; +} diff --git a/item_delegates/MessageItemDelegate.hpp b/item_delegates/MessageItemDelegate.hpp index 6058f80a..eede221c 100755 --- a/item_delegates/MessageItemDelegate.hpp +++ b/item_delegates/MessageItemDelegate.hpp @@ -1,20 +1,20 @@ -// -// -// - -#ifndef WSJTX_MESSAGEITEMDELEGATE_H -#define WSJTX_MESSAGEITEMDELEGATE_H - -#include - -class MessageItemDelegate: public QStyledItemDelegate - { - Q_OBJECT - -public: - explicit MessageItemDelegate(QObject *parent = nullptr); - QWidget *createEditor(QWidget *parent, QStyleOptionViewItem const & /* option*/ - , QModelIndex const & /* index */ - ) const override; -}; -#endif //WSJTX_MESSAGEITEMDELEGATE_H +// +// +// + +#ifndef WSJTX_MESSAGEITEMDELEGATE_H +#define WSJTX_MESSAGEITEMDELEGATE_H + +#include + +class MessageItemDelegate: public QStyledItemDelegate + { + Q_OBJECT + +public: + explicit MessageItemDelegate(QObject *parent = nullptr); + QWidget *createEditor(QWidget *parent, QStyleOptionViewItem const & /* option*/ + , QModelIndex const & /* index */ + ) const override; +}; +#endif //WSJTX_MESSAGEITEMDELEGATE_H diff --git a/item_delegates/SQLiteDateTimeDelegate.cpp b/item_delegates/SQLiteDateTimeDelegate.cpp index bd49017b..1cf8ad26 100755 --- a/item_delegates/SQLiteDateTimeDelegate.cpp +++ b/item_delegates/SQLiteDateTimeDelegate.cpp @@ -1,40 +1,40 @@ -#include "SQLiteDateTimeDelegate.hpp" - -#include -#include -#include - -SQLiteDateTimeDelegate::SQLiteDateTimeDelegate (QObject * parent) - : QStyledItemDelegate {parent} -{ -} - -QWidget * SQLiteDateTimeDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const& - , QModelIndex const&) const -{ - auto * editor = new QDateTimeEdit {parent}; - editor->setCalendarPopup (true); - editor->setDisplayFormat (QLocale {}.dateFormat (QLocale::ShortFormat) + " hh:mm:ss"); - editor->setFrame (false); - return editor; -} - -void SQLiteDateTimeDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const -{ - auto const& value = index.model ()->data (index, Qt::EditRole); - if (value.isValid () && !value.isNull ()) - { - static_cast (editor)->setDateTime (QDateTime::fromMSecsSinceEpoch (value.toULongLong () * 1000ull, Qt::UTC)); - } -} - -void SQLiteDateTimeDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const -{ - QVariant data; - auto const& value = static_cast (editor)->dateTime (); - if (value.isValid () && !value.isNull ()) - { - data = value.toMSecsSinceEpoch () / 1000ull; - } - model->setData (index, data, Qt::EditRole); -} +#include "SQLiteDateTimeDelegate.hpp" + +#include +#include +#include + +SQLiteDateTimeDelegate::SQLiteDateTimeDelegate (QObject * parent) + : QStyledItemDelegate {parent} +{ +} + +QWidget * SQLiteDateTimeDelegate::createEditor (QWidget * parent, QStyleOptionViewItem const& + , QModelIndex const&) const +{ + auto * editor = new QDateTimeEdit {parent}; + editor->setCalendarPopup (true); + editor->setDisplayFormat (QLocale {}.dateFormat (QLocale::ShortFormat) + " hh:mm:ss"); + editor->setFrame (false); + return editor; +} + +void SQLiteDateTimeDelegate::setEditorData (QWidget * editor, QModelIndex const& index) const +{ + auto const& value = index.model ()->data (index, Qt::EditRole); + if (value.isValid () && !value.isNull ()) + { + static_cast (editor)->setDateTime (QDateTime::fromMSecsSinceEpoch (value.toULongLong () * 1000ull, Qt::UTC)); + } +} + +void SQLiteDateTimeDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, QModelIndex const& index) const +{ + QVariant data; + auto const& value = static_cast (editor)->dateTime (); + if (value.isValid () && !value.isNull ()) + { + data = value.toMSecsSinceEpoch () / 1000ull; + } + model->setData (index, data, Qt::EditRole); +} diff --git a/item_delegates/SQLiteDateTimeDelegate.hpp b/item_delegates/SQLiteDateTimeDelegate.hpp index ca1983c8..183b26d7 100755 --- a/item_delegates/SQLiteDateTimeDelegate.hpp +++ b/item_delegates/SQLiteDateTimeDelegate.hpp @@ -1,23 +1,23 @@ -#ifndef SQLITE_DATE_TIME_DELEGATE_HPP_ -#define SQLITE_DATE_TIME_DELEGATE_HPP_ - -#include - -// -// Class SQLiteDateTimeDelegte -// -// Item delegate for editing a date and time stored as milliseconds -// since the Unix epoch and displayed or edited as a QDateTime -// showing UTC -// -class SQLiteDateTimeDelegate final - : public QStyledItemDelegate -{ -public: - explicit SQLiteDateTimeDelegate (QObject * parent = nullptr); - QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; - void setEditorData (QWidget * editor, QModelIndex const&) const override; - void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override; -}; - -#endif +#ifndef SQLITE_DATE_TIME_DELEGATE_HPP_ +#define SQLITE_DATE_TIME_DELEGATE_HPP_ + +#include + +// +// Class SQLiteDateTimeDelegte +// +// Item delegate for editing a date and time stored as milliseconds +// since the Unix epoch and displayed or edited as a QDateTime +// showing UTC +// +class SQLiteDateTimeDelegate final + : public QStyledItemDelegate +{ +public: + explicit SQLiteDateTimeDelegate (QObject * parent = nullptr); + QWidget * createEditor (QWidget * parent, QStyleOptionViewItem const&, QModelIndex const&) const override; + void setEditorData (QWidget * editor, QModelIndex const&) const override; + void setModelData (QWidget * editor, QAbstractItemModel *, QModelIndex const&) const override; +}; + +#endif diff --git a/item_delegates/item_delegates.pri b/item_delegates/item_delegates.pri index cca0c45f..819cb2e0 100755 --- a/item_delegates/item_delegates.pri +++ b/item_delegates/item_delegates.pri @@ -1,13 +1,13 @@ -SOURCES += \ - item_delegates/ForeignKeyDelegate.cpp \ - item_delegates/FrequencyDelegate.cpp \ - item_delegates/FrequencyDeltaDelegate.cpp \ - item_delegates/CallsignDelegate.cpp \ - item_delegates/MaidenheadLocatorItemDelegate.cpp - -HEADERS += \ - item_delegates/ForeignKeyDelegate.hpp \ - item_delegates/FrequencyDelegate.hpp \ - item_delegates/FrequencyDeltaDelegate.hpp \ - item_delegates/CallsignDelegate.hpp \ - item_delegates/MaidenheadLocatorDelegate.hpp +SOURCES += \ + item_delegates/ForeignKeyDelegate.cpp \ + item_delegates/FrequencyDelegate.cpp \ + item_delegates/FrequencyDeltaDelegate.cpp \ + item_delegates/CallsignDelegate.cpp \ + item_delegates/MaidenheadLocatorItemDelegate.cpp + +HEADERS += \ + item_delegates/ForeignKeyDelegate.hpp \ + item_delegates/FrequencyDelegate.hpp \ + item_delegates/FrequencyDeltaDelegate.hpp \ + item_delegates/CallsignDelegate.hpp \ + item_delegates/MaidenheadLocatorDelegate.hpp -- cgit v1.2.3