diff --git a/scwx-qt/source/scwx/qt/model/alert_proxy_model.cpp b/scwx-qt/source/scwx/qt/model/alert_proxy_model.cpp index a2afee55..224f7400 100644 --- a/scwx-qt/source/scwx/qt/model/alert_proxy_model.cpp +++ b/scwx-qt/source/scwx/qt/model/alert_proxy_model.cpp @@ -9,21 +9,22 @@ #include -namespace scwx -{ -namespace qt -{ -namespace model +namespace scwx::qt::model { static const std::string logPrefix_ = "scwx::qt::model::alert_proxy_model"; static const auto logger_ = scwx::util::Logger::Create(logPrefix_); -class AlertProxyModelImpl +class AlertProxyModel::Impl { public: - explicit AlertProxyModelImpl(AlertProxyModel* self); - ~AlertProxyModelImpl(); + explicit Impl(AlertProxyModel* self); + ~Impl(); + + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(const Impl&&) = delete; + Impl& operator=(const Impl&&) = delete; void UpdateAlerts(); @@ -36,8 +37,7 @@ public: }; AlertProxyModel::AlertProxyModel(QObject* parent) : - QSortFilterProxyModel(parent), - p(std::make_unique(this)) + QSortFilterProxyModel(parent), p(std::make_unique(this)) { } AlertProxyModel::~AlertProxyModel() = default; @@ -77,7 +77,7 @@ bool AlertProxyModel::filterAcceptsRow(int sourceRow, QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); } -AlertProxyModelImpl::AlertProxyModelImpl(AlertProxyModel* self) : +AlertProxyModel::Impl::Impl(AlertProxyModel* self) : self_ {self}, alertActiveFilterEnabled_ {false}, alertUpdateTimer_ {scwx::util::io_context()} @@ -86,13 +86,13 @@ AlertProxyModelImpl::AlertProxyModelImpl(AlertProxyModel* self) : UpdateAlerts(); } -AlertProxyModelImpl::~AlertProxyModelImpl() +AlertProxyModel::Impl::~Impl() { std::unique_lock lock(alertMutex_); alertUpdateTimer_.cancel(); } -void AlertProxyModelImpl::UpdateAlerts() +void AlertProxyModel::Impl::UpdateAlerts() { logger_->trace("UpdateAlerts"); @@ -102,10 +102,15 @@ void AlertProxyModelImpl::UpdateAlerts() // Re-evaluate for expired alerts if (alertActiveFilterEnabled_) { - self_->invalidateRowsFilter(); + QMetaObject::invokeMethod( + self_, + static_cast( + &QSortFilterProxyModel::invalidateRowsFilter)); } using namespace std::chrono; + + // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers): Readability alertUpdateTimer_.expires_after(15s); alertUpdateTimer_.async_wait( [this](const boost::system::error_code& e) @@ -132,6 +137,4 @@ void AlertProxyModelImpl::UpdateAlerts() }); } -} // namespace model -} // namespace qt -} // namespace scwx +} // namespace scwx::qt::model diff --git a/scwx-qt/source/scwx/qt/model/alert_proxy_model.hpp b/scwx-qt/source/scwx/qt/model/alert_proxy_model.hpp index ee8b81c1..1ee6a138 100644 --- a/scwx-qt/source/scwx/qt/model/alert_proxy_model.hpp +++ b/scwx-qt/source/scwx/qt/model/alert_proxy_model.hpp @@ -4,11 +4,7 @@ #include -namespace scwx -{ -namespace qt -{ -namespace model +namespace scwx::qt::model { class AlertProxyModelImpl; @@ -16,7 +12,7 @@ class AlertProxyModelImpl; class AlertProxyModel : public QSortFilterProxyModel { private: - Q_DISABLE_COPY(AlertProxyModel) + Q_DISABLE_COPY_MOVE(AlertProxyModel) public: explicit AlertProxyModel(QObject* parent = nullptr); @@ -24,15 +20,13 @@ public: void SetAlertActiveFilter(bool enabled); - bool filterAcceptsRow(int sourceRow, - const QModelIndex& sourceParent) const override; + [[nodiscard]] bool + filterAcceptsRow(int sourceRow, + const QModelIndex& sourceParent) const override; private: - std::unique_ptr p; - - friend class AlertProxyModelImpl; + class Impl; + std::unique_ptr p; }; -} // namespace model -} // namespace qt -} // namespace scwx +} // namespace scwx::qt::model