mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:40:06 +00:00 
			
		
		
		
	Radar Product Model functional stub
This commit is contained in:
		
							parent
							
								
									a47c13ca99
								
							
						
					
					
						commit
						1ba60f0da1
					
				
					 2 changed files with 149 additions and 22 deletions
				
			
		|  | @ -14,17 +14,18 @@ static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | |||
| class RadarProductModelItem | ||||
| { | ||||
| public: | ||||
|    explicit RadarProductModelItem(RadarProductModelItem* parent = nullptr); | ||||
|    explicit RadarProductModelItem(const std::vector<QVariant>& data, | ||||
|                                   RadarProductModelItem* parent = nullptr); | ||||
|    ~RadarProductModelItem(); | ||||
| 
 | ||||
|    void AppendChild(RadarProductModelItem* child); | ||||
| 
 | ||||
|    RadarProductModelItem* child(int row); | ||||
|    int                    child_count() const; | ||||
|    int                    column_count() const; | ||||
|    QVariant               data(int column) const; | ||||
|    int                    row() const; | ||||
|    RadarProductModelItem* parent_item(); | ||||
|    const RadarProductModelItem* child(int row) const; | ||||
|    int                          child_count() const; | ||||
|    int                          column_count() const; | ||||
|    QVariant                     data(int column) const; | ||||
|    int                          row() const; | ||||
|    const RadarProductModelItem* parent_item() const; | ||||
| 
 | ||||
| private: | ||||
|    std::vector<RadarProductModelItem*> childItems_; | ||||
|  | @ -35,8 +36,16 @@ private: | |||
| class RadarProductModelImpl | ||||
| { | ||||
| public: | ||||
|    explicit RadarProductModelImpl() {} | ||||
|    explicit RadarProductModelImpl() : | ||||
|        rootItem_ {std::make_shared<RadarProductModelItem>( | ||||
|           std::vector<QVariant> {QObject::tr("Name"), QObject::tr("Info")})} | ||||
|    { | ||||
|       rootItem_->AppendChild(new RadarProductModelItem( | ||||
|          std::vector<QVariant> {QObject::tr("MyItem"), QObject::tr("Data")})); | ||||
|    } | ||||
|    ~RadarProductModelImpl() = default; | ||||
| 
 | ||||
|    std::shared_ptr<RadarProductModelItem> rootItem_; | ||||
| }; | ||||
| 
 | ||||
| RadarProductModel::RadarProductModel(QObject* parent) : | ||||
|  | @ -45,24 +54,132 @@ RadarProductModel::RadarProductModel(QObject* parent) : | |||
| } | ||||
| RadarProductModel::~RadarProductModel() = default; | ||||
| 
 | ||||
| int RadarProductModel::rowCount(const QModelIndex& /*parent*/) const | ||||
| int RadarProductModel::rowCount(const QModelIndex& parent) const | ||||
| { | ||||
|    return 0; | ||||
|    const RadarProductModelItem* parentItem; | ||||
| 
 | ||||
|    if (parent.isValid()) | ||||
|    { | ||||
|       parentItem = static_cast<const RadarProductModelItem*>( | ||||
|          parent.constInternalPointer()); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       parentItem = p->rootItem_.get(); | ||||
|    } | ||||
| 
 | ||||
|    return parentItem->child_count(); | ||||
| } | ||||
| 
 | ||||
| int RadarProductModel::columnCount(const QModelIndex& /*parent*/) const | ||||
| int RadarProductModel::columnCount(const QModelIndex& parent) const | ||||
| { | ||||
|    return 0; | ||||
|    const RadarProductModelItem* parentItem; | ||||
| 
 | ||||
|    if (parent.isValid()) | ||||
|    { | ||||
|       parentItem = static_cast<const RadarProductModelItem*>( | ||||
|          parent.constInternalPointer()); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       parentItem = p->rootItem_.get(); | ||||
|    } | ||||
| 
 | ||||
|    return parentItem->column_count(); | ||||
| } | ||||
| 
 | ||||
| QVariant RadarProductModel::data(const QModelIndex& /*index*/, | ||||
|                                  int /*role*/) const | ||||
| QVariant RadarProductModel::data(const QModelIndex& index, int role) const | ||||
| { | ||||
|    if (!index.isValid() || role != Qt::DisplayRole) | ||||
|    { | ||||
|       return QVariant(); | ||||
|    } | ||||
| 
 | ||||
|    const RadarProductModelItem* item = | ||||
|       static_cast<const RadarProductModelItem*>(index.internalPointer()); | ||||
| 
 | ||||
|    return item->data(index.column()); | ||||
| } | ||||
| 
 | ||||
| Qt::ItemFlags RadarProductModel::flags(const QModelIndex& index) const | ||||
| { | ||||
|    Qt::ItemFlags flags; | ||||
| 
 | ||||
|    if (!index.isValid()) | ||||
|    { | ||||
|       flags = Qt::NoItemFlags; | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       flags = QAbstractItemModel::flags(index); | ||||
|    } | ||||
| 
 | ||||
|    return flags; | ||||
| } | ||||
| 
 | ||||
| QVariant RadarProductModel::headerData(int             section, | ||||
|                                        Qt::Orientation orientation, | ||||
|                                        int             role) const | ||||
| { | ||||
|    if (orientation == Qt::Horizontal && role == Qt::DisplayRole) | ||||
|    { | ||||
|       return p->rootItem_->data(section); | ||||
|    } | ||||
| 
 | ||||
|    return QVariant(); | ||||
| } | ||||
| 
 | ||||
| RadarProductModelItem::RadarProductModelItem(RadarProductModelItem* parent) : | ||||
|     childItems_ {}, itemData_ {}, parentItem_ {parent} | ||||
| QModelIndex | ||||
| RadarProductModel::index(int row, int column, const QModelIndex& parent) const | ||||
| { | ||||
|    if (!hasIndex(row, column, parent)) | ||||
|    { | ||||
|       return QModelIndex(); | ||||
|    } | ||||
| 
 | ||||
|    const RadarProductModelItem* parentItem; | ||||
| 
 | ||||
|    if (!parent.isValid()) | ||||
|    { | ||||
|       parentItem = p->rootItem_.get(); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       parentItem = static_cast<const RadarProductModelItem*>( | ||||
|          parent.constInternalPointer()); | ||||
|    } | ||||
| 
 | ||||
|    const RadarProductModelItem* childItem = parentItem->child(row); | ||||
|    if (childItem) | ||||
|    { | ||||
|       return createIndex(row, column, childItem); | ||||
|    } | ||||
| 
 | ||||
|    return QModelIndex(); | ||||
| } | ||||
| 
 | ||||
| QModelIndex RadarProductModel::parent(const QModelIndex& index) const | ||||
| { | ||||
|    if (!index.isValid()) | ||||
|    { | ||||
|       return QModelIndex(); | ||||
|    } | ||||
| 
 | ||||
|    const RadarProductModelItem* childItem = | ||||
|       static_cast<const RadarProductModelItem*>(index.constInternalPointer()); | ||||
|    const RadarProductModelItem* parentItem = childItem->parent_item(); | ||||
| 
 | ||||
|    if (parentItem == p->rootItem_.get()) | ||||
|    { | ||||
|       return QModelIndex(); | ||||
|    } | ||||
| 
 | ||||
|    return createIndex(parentItem->row(), 0, parentItem); | ||||
| } | ||||
| 
 | ||||
| RadarProductModelItem::RadarProductModelItem(const std::vector<QVariant>& data, | ||||
|                                              RadarProductModelItem* parent) : | ||||
|     childItems_ {}, itemData_ {data}, parentItem_ {parent} | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  | @ -73,12 +190,13 @@ RadarProductModelItem::~RadarProductModelItem() | |||
| 
 | ||||
| void RadarProductModelItem::AppendChild(RadarProductModelItem* item) | ||||
| { | ||||
|    item->parentItem_ = this; | ||||
|    childItems_.push_back(item); | ||||
| } | ||||
| 
 | ||||
| RadarProductModelItem* RadarProductModelItem::child(int row) | ||||
| const RadarProductModelItem* RadarProductModelItem::child(int row) const | ||||
| { | ||||
|    RadarProductModelItem* item = nullptr; | ||||
|    const RadarProductModelItem* item = nullptr; | ||||
| 
 | ||||
|    if (0 <= row && row < childItems_.size()) | ||||
|    { | ||||
|  | @ -106,7 +224,7 @@ QVariant RadarProductModelItem::data(int column) const | |||
|    } | ||||
|    else | ||||
|    { | ||||
|       return QVariant(); | ||||
|       return QVariant("Hello world"); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
|  | @ -125,7 +243,7 @@ int RadarProductModelItem::row() const | |||
|    return row; | ||||
| } | ||||
| 
 | ||||
| RadarProductModelItem* RadarProductModelItem::parent_item() | ||||
| const RadarProductModelItem* RadarProductModelItem::parent_item() const | ||||
| { | ||||
|    return parentItem_; | ||||
| } | ||||
|  |  | |||
|  | @ -21,8 +21,17 @@ public: | |||
| 
 | ||||
|    int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||||
|    int columnCount(const QModelIndex& parent = QModelIndex()) const override; | ||||
|    QVariant data(const QModelIndex& index, | ||||
|                  int                role = Qt::DisplayRole) const override; | ||||
| 
 | ||||
|    QVariant      data(const QModelIndex& index, | ||||
|                       int                role = Qt::DisplayRole) const override; | ||||
|    Qt::ItemFlags flags(const QModelIndex& index) const override; | ||||
|    QVariant      headerData(int             section, | ||||
|                             Qt::Orientation orientation, | ||||
|                             int             role = Qt::DisplayRole) const override; | ||||
|    QModelIndex   index(int                row, | ||||
|                        int                column, | ||||
|                        const QModelIndex& parent = QModelIndex()) const override; | ||||
|    QModelIndex   parent(const QModelIndex& index) const override; | ||||
| 
 | ||||
| private: | ||||
|    std::unique_ptr<RadarProductModelImpl> p; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat