mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 07:00:06 +00:00 
			
		
		
		
	Add begin/endInsertRows calls to notify view of changes
This commit is contained in:
		
							parent
							
								
									efc6dc1413
								
							
						
					
					
						commit
						1e58cc29e5
					
				
					 2 changed files with 39 additions and 1 deletions
				
			
		|  | @ -48,11 +48,18 @@ RadarProductModelImpl::RadarProductModelImpl(RadarProductModel* self) : | ||||||
|       this, |       this, | ||||||
|       [=](const std::string& radarSite) |       [=](const std::string& radarSite) | ||||||
|       { |       { | ||||||
|  |          const QModelIndex rootIndex = | ||||||
|  |             self_->createIndex(rootItem_->row(), 0, rootItem_.get()); | ||||||
|  |          const int rootChildren = rootItem_->child_count(); | ||||||
|  | 
 | ||||||
|  |          self_->beginInsertRows(rootIndex, rootChildren, rootChildren); | ||||||
|  | 
 | ||||||
|          TreeItem* radarSiteItem = |          TreeItem* radarSiteItem = | ||||||
|             new TreeItem({QString::fromStdString(radarSite)}); |             new TreeItem({QString::fromStdString(radarSite)}); | ||||||
| 
 |  | ||||||
|          rootItem_->AppendChild(radarSiteItem); |          rootItem_->AppendChild(radarSiteItem); | ||||||
| 
 | 
 | ||||||
|  |          self_->endInsertRows(); | ||||||
|  | 
 | ||||||
|          connect( |          connect( | ||||||
|             manager::RadarProductManager::Instance(radarSite).get(), |             manager::RadarProductManager::Instance(radarSite).get(), | ||||||
|             &manager::RadarProductManager::NewDataAvailable, |             &manager::RadarProductManager::NewDataAvailable, | ||||||
|  | @ -69,8 +76,18 @@ RadarProductModelImpl::RadarProductModelImpl(RadarProductModel* self) : | ||||||
| 
 | 
 | ||||||
|                if (groupItem == nullptr) |                if (groupItem == nullptr) | ||||||
|                { |                { | ||||||
|  |                   // Existing group item was not found, create it
 | ||||||
|  |                   const QModelIndex radarSiteIndex = | ||||||
|  |                      self_->createIndex(radarSiteItem->row(), 0, radarSiteItem); | ||||||
|  |                   const int radarSiteChildren = radarSiteItem->child_count(); | ||||||
|  | 
 | ||||||
|  |                   self_->beginInsertRows( | ||||||
|  |                      radarSiteIndex, radarSiteChildren, radarSiteChildren); | ||||||
|  | 
 | ||||||
|                   groupItem = new TreeItem({groupName}); |                   groupItem = new TreeItem({groupName}); | ||||||
|                   radarSiteItem->AppendChild(groupItem); |                   radarSiteItem->AppendChild(groupItem); | ||||||
|  | 
 | ||||||
|  |                   self_->endInsertRows(); | ||||||
|                } |                } | ||||||
| 
 | 
 | ||||||
|                TreeItem* productItem = nullptr; |                TreeItem* productItem = nullptr; | ||||||
|  | @ -88,14 +105,33 @@ RadarProductModelImpl::RadarProductModelImpl(RadarProductModel* self) : | ||||||
| 
 | 
 | ||||||
|                   if (productItem == nullptr) |                   if (productItem == nullptr) | ||||||
|                   { |                   { | ||||||
|  |                      // Existing product item was not found, create it
 | ||||||
|  |                      const QModelIndex groupItemIndex = | ||||||
|  |                         self_->createIndex(groupItem->row(), 0, groupItem); | ||||||
|  |                      const int groupItemChildren = groupItem->child_count(); | ||||||
|  | 
 | ||||||
|  |                      self_->beginInsertRows( | ||||||
|  |                         groupItemIndex, groupItemChildren, groupItemChildren); | ||||||
|  | 
 | ||||||
|                      productItem = new TreeItem({productName}); |                      productItem = new TreeItem({productName}); | ||||||
|                      groupItem->AppendChild(productItem); |                      groupItem->AppendChild(productItem); | ||||||
|  | 
 | ||||||
|  |                      self_->endInsertRows(); | ||||||
|                   } |                   } | ||||||
|                } |                } | ||||||
| 
 | 
 | ||||||
|                // Create leaf item for product time
 |                // Create leaf item for product time
 | ||||||
|  |                const QModelIndex productItemIndex = | ||||||
|  |                   self_->createIndex(productItem->row(), 0, productItem); | ||||||
|  |                const int productItemChildren = productItem->child_count(); | ||||||
|  | 
 | ||||||
|  |                self_->beginInsertRows( | ||||||
|  |                   productItemIndex, productItemChildren, productItemChildren); | ||||||
|  | 
 | ||||||
|                productItem->AppendChild(new TreeItem { |                productItem->AppendChild(new TreeItem { | ||||||
|                   QString::fromStdString(util::TimeString(latestTime))}); |                   QString::fromStdString(util::TimeString(latestTime))}); | ||||||
|  | 
 | ||||||
|  |                self_->endInsertRows(); | ||||||
|             }, |             }, | ||||||
|             Qt::QueuedConnection); |             Qt::QueuedConnection); | ||||||
|       }, |       }, | ||||||
|  |  | ||||||
|  | @ -22,6 +22,8 @@ protected: | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|    std::unique_ptr<RadarProductModelImpl> p; |    std::unique_ptr<RadarProductModelImpl> p; | ||||||
|  | 
 | ||||||
|  |    friend class RadarProductModelImpl; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } // namespace model
 | } // namespace model
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat