-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveitemcommand.cpp
More file actions
40 lines (35 loc) · 1.02 KB
/
removeitemcommand.cpp
File metadata and controls
40 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "dictionarymodel.h"
#include "removeitemcommand.h"
#include <QTreeView>
#include <QSortFilterProxyModel>
RemoveItemCommand::RemoveItemCommand(QAbstractItemView *view, const QModelIndex &index) :
ItemCommand(view, index), isExpanded(false)
{
pItem = new DictionaryItem(sourceModel->itemForIndex(mIndex));
}
RemoveItemCommand::~RemoveItemCommand()
{
delete pItem;
}
void RemoveItemCommand::undo()
{
reinitializeIndexes();
bool lastItem = !mIndex.isValid();
mIndex = mIndex.isValid() ? mIndex : mParentIndex;
mIndex = sourceModel->insertItem(new DictionaryItem(pItem), mIndex);
if (!lastItem)
{
mIndex = sourceModel->upItem(mIndex.row(), mParentIndex);
}
pView->scrollTo(proxyModel->mapFromSource(mIndex));
if (isExpanded)
{
qobject_cast<QTreeView*>(pView)->expand(proxyModel->mapFromSource(mIndex));
}
}
void RemoveItemCommand::redo()
{
reinitializeIndexes();
isExpanded = qobject_cast<QTreeView*>(pView)->isExpanded(proxyModel->mapFromSource(mIndex));
sourceModel->removeRow(mIndex.row(), mParentIndex);
}