mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 02:00:05 +00:00 
			
		
		
		
	invalidateRowsFilter must be called from UI thread
This commit is contained in:
		
							parent
							
								
									490989ac2a
								
							
						
					
					
						commit
						1fdefe83de
					
				
					 2 changed files with 28 additions and 31 deletions
				
			
		|  | @ -9,21 +9,22 @@ | ||||||
| 
 | 
 | ||||||
| #include <boost/asio/steady_timer.hpp> | #include <boost/asio/steady_timer.hpp> | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx::qt::model | ||||||
| { |  | ||||||
| namespace qt |  | ||||||
| { |  | ||||||
| namespace model |  | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| static const std::string logPrefix_ = "scwx::qt::model::alert_proxy_model"; | static const std::string logPrefix_ = "scwx::qt::model::alert_proxy_model"; | ||||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||||
| 
 | 
 | ||||||
| class AlertProxyModelImpl | class AlertProxyModel::Impl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit AlertProxyModelImpl(AlertProxyModel* self); |    explicit Impl(AlertProxyModel* self); | ||||||
|    ~AlertProxyModelImpl(); |    ~Impl(); | ||||||
|  | 
 | ||||||
|  |    Impl(const Impl&)             = delete; | ||||||
|  |    Impl& operator=(const Impl&)  = delete; | ||||||
|  |    Impl(const Impl&&)            = delete; | ||||||
|  |    Impl& operator=(const Impl&&) = delete; | ||||||
| 
 | 
 | ||||||
|    void UpdateAlerts(); |    void UpdateAlerts(); | ||||||
| 
 | 
 | ||||||
|  | @ -36,8 +37,7 @@ public: | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| AlertProxyModel::AlertProxyModel(QObject* parent) : | AlertProxyModel::AlertProxyModel(QObject* parent) : | ||||||
|     QSortFilterProxyModel(parent), |     QSortFilterProxyModel(parent), p(std::make_unique<Impl>(this)) | ||||||
|     p(std::make_unique<AlertProxyModelImpl>(this)) |  | ||||||
| { | { | ||||||
| } | } | ||||||
| AlertProxyModel::~AlertProxyModel() = default; | AlertProxyModel::~AlertProxyModel() = default; | ||||||
|  | @ -77,7 +77,7 @@ bool AlertProxyModel::filterAcceptsRow(int                sourceRow, | ||||||
|           QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); |           QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| AlertProxyModelImpl::AlertProxyModelImpl(AlertProxyModel* self) : | AlertProxyModel::Impl::Impl(AlertProxyModel* self) : | ||||||
|     self_ {self}, |     self_ {self}, | ||||||
|     alertActiveFilterEnabled_ {false}, |     alertActiveFilterEnabled_ {false}, | ||||||
|     alertUpdateTimer_ {scwx::util::io_context()} |     alertUpdateTimer_ {scwx::util::io_context()} | ||||||
|  | @ -86,13 +86,13 @@ AlertProxyModelImpl::AlertProxyModelImpl(AlertProxyModel* self) : | ||||||
|    UpdateAlerts(); |    UpdateAlerts(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| AlertProxyModelImpl::~AlertProxyModelImpl() | AlertProxyModel::Impl::~Impl() | ||||||
| { | { | ||||||
|    std::unique_lock lock(alertMutex_); |    std::unique_lock lock(alertMutex_); | ||||||
|    alertUpdateTimer_.cancel(); |    alertUpdateTimer_.cancel(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AlertProxyModelImpl::UpdateAlerts() | void AlertProxyModel::Impl::UpdateAlerts() | ||||||
| { | { | ||||||
|    logger_->trace("UpdateAlerts"); |    logger_->trace("UpdateAlerts"); | ||||||
| 
 | 
 | ||||||
|  | @ -102,10 +102,15 @@ void AlertProxyModelImpl::UpdateAlerts() | ||||||
|    // Re-evaluate for expired alerts
 |    // Re-evaluate for expired alerts
 | ||||||
|    if (alertActiveFilterEnabled_) |    if (alertActiveFilterEnabled_) | ||||||
|    { |    { | ||||||
|       self_->invalidateRowsFilter(); |       QMetaObject::invokeMethod( | ||||||
|  |          self_, | ||||||
|  |          static_cast<void (QSortFilterProxyModel::*)()>( | ||||||
|  |             &QSortFilterProxyModel::invalidateRowsFilter)); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    using namespace std::chrono; |    using namespace std::chrono; | ||||||
|  | 
 | ||||||
|  |    // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers): Readability
 | ||||||
|    alertUpdateTimer_.expires_after(15s); |    alertUpdateTimer_.expires_after(15s); | ||||||
|    alertUpdateTimer_.async_wait( |    alertUpdateTimer_.async_wait( | ||||||
|       [this](const boost::system::error_code& e) |       [this](const boost::system::error_code& e) | ||||||
|  | @ -132,6 +137,4 @@ void AlertProxyModelImpl::UpdateAlerts() | ||||||
|       }); |       }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| } // namespace model
 | } // namespace scwx::qt::model
 | ||||||
| } // namespace qt
 |  | ||||||
| } // namespace scwx
 |  | ||||||
|  |  | ||||||
|  | @ -4,11 +4,7 @@ | ||||||
| 
 | 
 | ||||||
| #include <QSortFilterProxyModel> | #include <QSortFilterProxyModel> | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx::qt::model | ||||||
| { |  | ||||||
| namespace qt |  | ||||||
| { |  | ||||||
| namespace model |  | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| class AlertProxyModelImpl; | class AlertProxyModelImpl; | ||||||
|  | @ -16,7 +12,7 @@ class AlertProxyModelImpl; | ||||||
| class AlertProxyModel : public QSortFilterProxyModel | class AlertProxyModel : public QSortFilterProxyModel | ||||||
| { | { | ||||||
| private: | private: | ||||||
|    Q_DISABLE_COPY(AlertProxyModel) |    Q_DISABLE_COPY_MOVE(AlertProxyModel) | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|    explicit AlertProxyModel(QObject* parent = nullptr); |    explicit AlertProxyModel(QObject* parent = nullptr); | ||||||
|  | @ -24,15 +20,13 @@ public: | ||||||
| 
 | 
 | ||||||
|    void SetAlertActiveFilter(bool enabled); |    void SetAlertActiveFilter(bool enabled); | ||||||
| 
 | 
 | ||||||
|    bool filterAcceptsRow(int                sourceRow, |    [[nodiscard]] bool | ||||||
|  |    filterAcceptsRow(int                sourceRow, | ||||||
|                     const QModelIndex& sourceParent) const override; |                     const QModelIndex& sourceParent) const override; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|    std::unique_ptr<AlertProxyModelImpl> p; |    class Impl; | ||||||
| 
 |    std::unique_ptr<Impl> p; | ||||||
|    friend class AlertProxyModelImpl; |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } // namespace model
 | } // namespace scwx::qt::model
 | ||||||
| } // namespace qt
 |  | ||||||
| } // namespace scwx
 |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat