replaced raw pointers with unique_ptr
This commit is contained in:
@@ -4,18 +4,9 @@ namespace chatterino {
|
||||
|
||||
QuickSwitcherModel::QuickSwitcherModel(QWidget *parent)
|
||||
: QAbstractListModel(parent)
|
||||
, items_(INITIAL_ITEMS_SIZE)
|
||||
{
|
||||
}
|
||||
|
||||
QuickSwitcherModel::~QuickSwitcherModel()
|
||||
{
|
||||
for (AbstractSwitcherItem *item : this->items_)
|
||||
{
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
int QuickSwitcherModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return this->items_.size();
|
||||
@@ -30,29 +21,29 @@ QVariant QuickSwitcherModel::data(const QModelIndex &index,
|
||||
if (index.row() >= this->items_.size())
|
||||
return QVariant();
|
||||
|
||||
auto item = this->items_.at(index.row());
|
||||
auto item = this->items_[index.row()].get();
|
||||
// See https://stackoverflow.com/a/44503822 .
|
||||
return QVariant::fromValue(static_cast<void *>(item));
|
||||
}
|
||||
|
||||
void QuickSwitcherModel::addItem(AbstractSwitcherItem *item)
|
||||
void QuickSwitcherModel::addItem(std::unique_ptr<AbstractSwitcherItem> item)
|
||||
{
|
||||
// {begin,end}InsertRows needs to be called to notify attached views
|
||||
this->beginInsertRows(QModelIndex(), this->items_.size(),
|
||||
this->items_.size());
|
||||
this->items_.append(item);
|
||||
this->items_.push_back(std::move(item));
|
||||
this->endInsertRows();
|
||||
}
|
||||
|
||||
void QuickSwitcherModel::clear()
|
||||
{
|
||||
if (this->items_.empty())
|
||||
return;
|
||||
|
||||
// {begin,end}RemoveRows needs to be called to notify attached views
|
||||
this->beginRemoveRows(QModelIndex(), 0, this->items_.size() - 1);
|
||||
|
||||
for (AbstractSwitcherItem *item : this->items_)
|
||||
{
|
||||
delete item;
|
||||
}
|
||||
// clear
|
||||
this->items_.clear();
|
||||
|
||||
this->endRemoveRows();
|
||||
|
||||
Reference in New Issue
Block a user