mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 02:40:05 +00:00 
			
		
		
		
	Radar Product Model population
This commit is contained in:
		
							parent
							
								
									4c4c93cad1
								
							
						
					
					
						commit
						efc6dc1413
					
				
					 5 changed files with 120 additions and 21 deletions
				
			
		|  | @ -1,6 +1,8 @@ | ||||||
| #include <scwx/qt/model/radar_product_model.hpp> | #include <scwx/qt/model/radar_product_model.hpp> | ||||||
|  | #include <scwx/qt/manager/radar_product_manager.hpp> | ||||||
| #include <scwx/qt/manager/radar_product_manager_notifier.hpp> | #include <scwx/qt/manager/radar_product_manager_notifier.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
|  | #include <scwx/util/time.hpp> | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -17,14 +19,15 @@ class RadarProductModelImpl : public QObject | ||||||
|    Q_OBJECT |    Q_OBJECT | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|    explicit RadarProductModelImpl(); |    explicit RadarProductModelImpl(RadarProductModel* self); | ||||||
|    ~RadarProductModelImpl() = default; |    ~RadarProductModelImpl() = default; | ||||||
| 
 | 
 | ||||||
|  |    RadarProductModel*        self_; | ||||||
|    std::shared_ptr<TreeItem> rootItem_; |    std::shared_ptr<TreeItem> rootItem_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| RadarProductModel::RadarProductModel(QObject* parent) : | RadarProductModel::RadarProductModel(QObject* parent) : | ||||||
|     TreeModel(parent), p(std::make_unique<RadarProductModelImpl>()) |     TreeModel(parent), p(std::make_unique<RadarProductModelImpl>(this)) | ||||||
| { | { | ||||||
| } | } | ||||||
| RadarProductModel::~RadarProductModel() = default; | RadarProductModel::~RadarProductModel() = default; | ||||||
|  | @ -34,18 +37,69 @@ const std::shared_ptr<TreeItem> RadarProductModel::root_item() const | ||||||
|    return p->rootItem_; |    return p->rootItem_; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| RadarProductModelImpl::RadarProductModelImpl() : | RadarProductModelImpl::RadarProductModelImpl(RadarProductModel* self) : | ||||||
|  |     self_ {self}, | ||||||
|     rootItem_ {std::make_shared<TreeItem>( |     rootItem_ {std::make_shared<TreeItem>( | ||||||
|        std::vector<QVariant> {QObject::tr("Name"), QObject::tr("Info")})} |        std::vector<QVariant> {QObject::tr("Name"), QObject::tr("Info")})} | ||||||
| { | { | ||||||
|    connect(&manager::RadarProductManagerNotifier::Instance(), |    connect( | ||||||
|            &manager::RadarProductManagerNotifier::RadarProductManagerCreated, |       &manager::RadarProductManagerNotifier::Instance(), | ||||||
|            this, |       &manager::RadarProductManagerNotifier::RadarProductManagerCreated, | ||||||
|            [=](const std::string& radarSite) |       this, | ||||||
|            { |       [=](const std::string& radarSite) | ||||||
|               rootItem_->AppendChild(new TreeItem( |       { | ||||||
|                  std::vector<QVariant> {QString::fromStdString(radarSite)})); |          TreeItem* radarSiteItem = | ||||||
|            }); |             new TreeItem({QString::fromStdString(radarSite)}); | ||||||
|  | 
 | ||||||
|  |          rootItem_->AppendChild(radarSiteItem); | ||||||
|  | 
 | ||||||
|  |          connect( | ||||||
|  |             manager::RadarProductManager::Instance(radarSite).get(), | ||||||
|  |             &manager::RadarProductManager::NewDataAvailable, | ||||||
|  |             this, | ||||||
|  |             [=](common::RadarProductGroup             group, | ||||||
|  |                 const std::string&                    product, | ||||||
|  |                 std::chrono::system_clock::time_point latestTime) | ||||||
|  |             { | ||||||
|  |                const QString groupName {QString::fromStdString( | ||||||
|  |                   common::GetRadarProductGroupName(group))}; | ||||||
|  | 
 | ||||||
|  |                // Find existing group item (e.g., Level 2, Level 3)
 | ||||||
|  |                TreeItem* groupItem = radarSiteItem->FindChild(0, groupName); | ||||||
|  | 
 | ||||||
|  |                if (groupItem == nullptr) | ||||||
|  |                { | ||||||
|  |                   groupItem = new TreeItem({groupName}); | ||||||
|  |                   radarSiteItem->AppendChild(groupItem); | ||||||
|  |                } | ||||||
|  | 
 | ||||||
|  |                TreeItem* productItem = nullptr; | ||||||
|  | 
 | ||||||
|  |                if (group == common::RadarProductGroup::Level2) | ||||||
|  |                { | ||||||
|  |                   // Level 2 items are not separated by product
 | ||||||
|  |                   productItem = groupItem; | ||||||
|  |                } | ||||||
|  |                else | ||||||
|  |                { | ||||||
|  |                   // Find existing product item (e.g., N0B, N0Q)
 | ||||||
|  |                   const QString productName {QString::fromStdString(product)}; | ||||||
|  |                   productItem = groupItem->FindChild(0, productName); | ||||||
|  | 
 | ||||||
|  |                   if (productItem == nullptr) | ||||||
|  |                   { | ||||||
|  |                      productItem = new TreeItem({productName}); | ||||||
|  |                      groupItem->AppendChild(productItem); | ||||||
|  |                   } | ||||||
|  |                } | ||||||
|  | 
 | ||||||
|  |                // Create leaf item for product time
 | ||||||
|  |                productItem->AppendChild(new TreeItem { | ||||||
|  |                   QString::fromStdString(util::TimeString(latestTime))}); | ||||||
|  |             }, | ||||||
|  |             Qt::QueuedConnection); | ||||||
|  |       }, | ||||||
|  |       Qt::QueuedConnection); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #include "radar_product_model.moc" | #include "radar_product_model.moc" | ||||||
|  |  | ||||||
|  | @ -28,6 +28,11 @@ TreeItem::TreeItem(const std::vector<QVariant>& data, TreeItem* parent) : | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | TreeItem::TreeItem(std::initializer_list<QVariant> data, TreeItem* parent) : | ||||||
|  |     TreeItem(std::vector<QVariant> {data}, parent) | ||||||
|  | { | ||||||
|  | } | ||||||
|  | 
 | ||||||
| TreeItem::~TreeItem() {} | TreeItem::~TreeItem() {} | ||||||
| 
 | 
 | ||||||
| TreeItem::TreeItem(TreeItem&&) noexcept            = default; | TreeItem::TreeItem(TreeItem&&) noexcept            = default; | ||||||
|  | @ -39,6 +44,24 @@ void TreeItem::AppendChild(TreeItem* item) | ||||||
|    p->childItems_.push_back(item); |    p->childItems_.push_back(item); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | TreeItem* TreeItem::FindChild(int column, const QVariant& data) | ||||||
|  | { | ||||||
|  |    auto it = std::find_if(p->childItems_.begin(), | ||||||
|  |                           p->childItems_.end(), | ||||||
|  |                           [&](auto& item) { | ||||||
|  |                              return (column < item->column_count() && | ||||||
|  |                                      item->data(column) == data); | ||||||
|  |                           }); | ||||||
|  | 
 | ||||||
|  |    TreeItem* item = nullptr; | ||||||
|  |    if (it != p->childItems_.end()) | ||||||
|  |    { | ||||||
|  |       item = *it; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    return item; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| const TreeItem* TreeItem::child(int row) const | const TreeItem* TreeItem::child(int row) const | ||||||
| { | { | ||||||
|    const TreeItem* item = nullptr; |    const TreeItem* item = nullptr; | ||||||
|  | @ -51,6 +74,23 @@ const TreeItem* TreeItem::child(int row) const | ||||||
|    return item; |    return item; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | TreeItem* TreeItem::child(int row) | ||||||
|  | { | ||||||
|  |    TreeItem* item = nullptr; | ||||||
|  | 
 | ||||||
|  |    if (0 <= row && row < p->childItems_.size()) | ||||||
|  |    { | ||||||
|  |       item = p->childItems_[row]; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    return item; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | std::vector<TreeItem*> TreeItem::children() | ||||||
|  | { | ||||||
|  |    return p->childItems_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| int TreeItem::child_count() const | int TreeItem::child_count() const | ||||||
| { | { | ||||||
|    return static_cast<int>(p->childItems_.size()); |    return static_cast<int>(p->childItems_.size()); | ||||||
|  |  | ||||||
|  | @ -17,6 +17,8 @@ class TreeItem | ||||||
| public: | public: | ||||||
|    explicit TreeItem(const std::vector<QVariant>& data, |    explicit TreeItem(const std::vector<QVariant>& data, | ||||||
|                      TreeItem*                    parent = nullptr); |                      TreeItem*                    parent = nullptr); | ||||||
|  |    explicit TreeItem(std::initializer_list<QVariant> data, | ||||||
|  |                      TreeItem*                       parent = nullptr); | ||||||
|    virtual ~TreeItem(); |    virtual ~TreeItem(); | ||||||
| 
 | 
 | ||||||
|    TreeItem(const TreeItem&)            = delete; |    TreeItem(const TreeItem&)            = delete; | ||||||
|  | @ -25,14 +27,17 @@ public: | ||||||
|    TreeItem(TreeItem&&) noexcept; |    TreeItem(TreeItem&&) noexcept; | ||||||
|    TreeItem& operator=(TreeItem&&) noexcept; |    TreeItem& operator=(TreeItem&&) noexcept; | ||||||
| 
 | 
 | ||||||
|    void AppendChild(TreeItem* child); |    void      AppendChild(TreeItem* child); | ||||||
|  |    TreeItem* FindChild(int column, const QVariant& data); | ||||||
| 
 | 
 | ||||||
|    const TreeItem* child(int row) const; |    const TreeItem*        child(int row) const; | ||||||
|    int             child_count() const; |    TreeItem*              child(int row); | ||||||
|    int             column_count() const; |    std::vector<TreeItem*> children(); | ||||||
|    QVariant        data(int column) const; |    int                    child_count() const; | ||||||
|    int             row() const; |    int                    column_count() const; | ||||||
|    const TreeItem* parent_item() const; |    QVariant               data(int column) const; | ||||||
|  |    int                    row() const; | ||||||
|  |    const TreeItem*        parent_item() const; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|    class Impl; |    class Impl; | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ public: | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| TreeModel::TreeModel(QObject* parent) : | TreeModel::TreeModel(QObject* parent) : | ||||||
|     QAbstractTableModel(parent), p(std::make_unique<TreeModelImpl>()) |     QAbstractItemModel(parent), p(std::make_unique<TreeModelImpl>()) | ||||||
| { | { | ||||||
| } | } | ||||||
| TreeModel::~TreeModel() = default; | TreeModel::~TreeModel() = default; | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| #include <scwx/qt/model/tree_item.hpp> | #include <scwx/qt/model/tree_item.hpp> | ||||||
| 
 | 
 | ||||||
| #include <QAbstractTableModel> | #include <QAbstractItemModel> | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -13,7 +13,7 @@ namespace model | ||||||
| 
 | 
 | ||||||
| class TreeModelImpl; | class TreeModelImpl; | ||||||
| 
 | 
 | ||||||
| class TreeModel : public QAbstractTableModel | class TreeModel : public QAbstractItemModel | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit TreeModel(QObject* parent = nullptr); |    explicit TreeModel(QObject* parent = nullptr); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat