Radar Product Model Item class

This commit is contained in:
Dan Paulat 2022-09-17 00:38:40 -05:00
parent b917e1a818
commit a47c13ca99

View file

@ -11,6 +11,27 @@ namespace model
static const std::string logPrefix_ = "scwx::qt::model::radar_product_model";
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
class RadarProductModelItem
{
public:
explicit RadarProductModelItem(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();
private:
std::vector<RadarProductModelItem*> childItems_;
std::vector<QVariant> itemData_;
RadarProductModelItem* parentItem_;
};
class RadarProductModelImpl
{
public:
@ -40,6 +61,75 @@ QVariant RadarProductModel::data(const QModelIndex& /*index*/,
return QVariant();
}
RadarProductModelItem::RadarProductModelItem(RadarProductModelItem* parent) :
childItems_ {}, itemData_ {}, parentItem_ {parent}
{
}
RadarProductModelItem::~RadarProductModelItem()
{
qDeleteAll(childItems_);
}
void RadarProductModelItem::AppendChild(RadarProductModelItem* item)
{
childItems_.push_back(item);
}
RadarProductModelItem* RadarProductModelItem::child(int row)
{
RadarProductModelItem* item = nullptr;
if (0 <= row && row < childItems_.size())
{
item = childItems_[row];
}
return item;
}
int RadarProductModelItem::child_count() const
{
return static_cast<int>(childItems_.size());
}
int RadarProductModelItem::column_count() const
{
return static_cast<int>(itemData_.size());
}
QVariant RadarProductModelItem::data(int column) const
{
if (0 <= column && column < itemData_.size())
{
return itemData_[column];
}
else
{
return QVariant();
}
}
int RadarProductModelItem::row() const
{
int row = 0;
if (parentItem_ != nullptr)
{
const auto& childItems = parentItem_->childItems_;
row =
std::distance(childItems.cbegin(),
std::find(childItems.cbegin(), childItems.cend(), this));
}
return row;
}
RadarProductModelItem* RadarProductModelItem::parent_item()
{
return parentItem_;
}
} // namespace model
} // namespace qt
} // namespace scwx