mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:00:04 +00:00 
			
		
		
		
	Alert active filter and sorting
This commit is contained in:
		
							parent
							
								
									7ef3cb8347
								
							
						
					
					
						commit
						6e5cc555f2
					
				
					 6 changed files with 208 additions and 46 deletions
				
			
		
							
								
								
									
										72
									
								
								scwx-qt/source/scwx/qt/model/alert_proxy_model.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								scwx-qt/source/scwx/qt/model/alert_proxy_model.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,72 @@ | |||
| #include <scwx/qt/model/alert_proxy_model.hpp> | ||||
| #include <scwx/qt/model/alert_model.hpp> | ||||
| #include <scwx/qt/types/qt_types.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace model | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::model::alert_proxy_model"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| class AlertProxyModelImpl | ||||
| { | ||||
| public: | ||||
|    explicit AlertProxyModelImpl(); | ||||
|    ~AlertProxyModelImpl() = default; | ||||
| 
 | ||||
|    bool alertActiveFilterEnabled_; | ||||
| }; | ||||
| 
 | ||||
| AlertProxyModel::AlertProxyModel(QObject* parent) : | ||||
|     QSortFilterProxyModel(parent), p(std::make_unique<AlertProxyModelImpl>()) | ||||
| { | ||||
| } | ||||
| AlertProxyModel::~AlertProxyModel() = default; | ||||
| 
 | ||||
| void AlertProxyModel::SetAlertActiveFilter(bool enabled) | ||||
| { | ||||
|    p->alertActiveFilterEnabled_ = enabled; | ||||
|    invalidateRowsFilter(); | ||||
| } | ||||
| 
 | ||||
| bool AlertProxyModel::filterAcceptsRow(int                sourceRow, | ||||
|                                        const QModelIndex& sourceParent) const | ||||
| { | ||||
|    bool acceptAlertActiveFilter = true; | ||||
| 
 | ||||
|    if (p->alertActiveFilterEnabled_) | ||||
|    { | ||||
|       // Get source model index
 | ||||
|       QModelIndex endTimeIndex = | ||||
|          sourceModel()->index(sourceRow, | ||||
|                               static_cast<int>(AlertModel::Column::EndTime), | ||||
|                               sourceParent); | ||||
| 
 | ||||
|       // Get source end time
 | ||||
|       auto endTime = sourceModel() | ||||
|                         ->data(endTimeIndex, qt::types::SortRole) | ||||
|                         .value<std::chrono::system_clock::time_point>(); | ||||
| 
 | ||||
|       // Compare end time to current
 | ||||
|       if (endTime < std::chrono::system_clock::now()) | ||||
|       { | ||||
|          acceptAlertActiveFilter = false; | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    return acceptAlertActiveFilter && | ||||
|           QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); | ||||
| } | ||||
| 
 | ||||
| AlertProxyModelImpl::AlertProxyModelImpl() : alertActiveFilterEnabled_ {false} | ||||
| { | ||||
| } | ||||
| 
 | ||||
| } // namespace model
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat