LocalTaskModel: allow removing of stages

This commit is contained in:
Robert Haschke 2017-11-07 22:35:07 +01:00
parent 953224eba1
commit fc9ca1b624
4 changed files with 30 additions and 0 deletions

View File

@ -20,6 +20,7 @@ public:
bool traverseRecursively(const StageCallback &processor) const;
virtual bool insert(Stage::pointer&& stage, int before = -1);
virtual bool remove(int pos);
virtual void clear();
void reset() override;

View File

@ -96,6 +96,13 @@ bool ContainerBase::insert(Stage::pointer &&stage, int before)
return true;
}
bool ContainerBase::remove(int pos)
{
ContainerBasePrivate::const_iterator it = pimpl()->position(pos);
pimpl()->children_.erase(it);
return true;
}
void ContainerBase::clear()
{
pimpl()->children_.clear();

View File

@ -169,6 +169,26 @@ bool LocalTaskModel::setData(const QModelIndex &index, const QVariant &value, in
return true;
}
bool LocalTaskModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (!parent.isValid())
return false; // cannot remove top-level container
if (flags_ & IS_RUNNING)
return false; // cannot modify running task
Q_ASSERT(dynamic_cast<ContainerBase*>(node(parent)->me()));
ContainerBasePrivate *cp = static_cast<ContainerBasePrivate*>(node(parent));
ContainerBase *c = static_cast<ContainerBase*>(cp->me());
if (row < 0 || (size_t)row + count > cp->children().size())
return false;
beginRemoveRows(parent, row, row+count-1);
for (; count > 0; --count)
c->remove(row);
endRemoveRows();
return true;
}
void LocalTaskModel::setStageFactory(const StageFactoryPtr &factory)
{
stage_factory_ = factory;

View File

@ -65,6 +65,8 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
bool removeRows(int row, int count, const QModelIndex &parent) override;
/// providing a StageFactory makes the model accepting drops
void setStageFactory(const StageFactoryPtr &factory);
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;