MetaTaskListModel: don't remove top-level items

This commit is contained in:
Robert Haschke 2018-02-25 23:49:42 +01:00
parent 1f6bea9438
commit 3ce0bc7dee
3 changed files with 11 additions and 3 deletions

View File

@ -95,6 +95,13 @@ bool MetaTaskListModel::setData(const QModelIndex &index, const QVariant &value,
return result;
}
bool MetaTaskListModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (!parent.isValid()) // forbid removal of top-level items (displays)
return false;
TreeMergeProxyModel::removeRows(row, count, parent);
}
std::pair<TaskListModel*, TaskDisplay*>
MetaTaskListModel::getTaskListModel(const QModelIndex &index) const
{

View File

@ -69,7 +69,7 @@ class MetaTaskListModel : public utils::TreeMergeProxyModel {
// hide this, as we want to offer another API
using utils::TreeMergeProxyModel::insertModel;
private Q_SLOTS:
private Q_SLOTS:
void onRowsRemoved(const QModelIndex &parent, int first, int last);
void onDisplayNameChanged(const QString &name);
@ -80,6 +80,7 @@ public:
bool insertModel(TaskListModel* model, TaskDisplay* display);
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
bool removeRows(int row, int count, const QModelIndex &parent) override;
/// retrieve TaskListModel and TaskDisplay corresponding to given index
std::pair<TaskListModel*, TaskDisplay*> getTaskListModel(const QModelIndex &index) const;

View File

@ -245,8 +245,8 @@ void TaskView::onCurrentStageChanged(const QModelIndex &current, const QModelInd
// adding task is allowed on top-level items and sub-top-level items
d_ptr->actionAddLocalTask->setEnabled(current.isValid() &&
(!current.parent().isValid() || !current.parent().parent().isValid()));
// removing stuff is allowed if there is any selection / any curren item
d_ptr->actionRemoveTaskTreeRows->setEnabled(current.isValid());
// removing stuff is allowed any valid selection except top-level items
d_ptr->actionRemoveTaskTreeRows->setEnabled(current.isValid() && current.parent().isValid());
BaseTaskModel *task;
QModelIndex task_index;