Menu

[r16]: / TreeView.cpp  Maximize  Restore  History

Download this file

88 lines (79 with data), 2.5 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "treeview.h"
#include <QAction>
#include <QInputDialog>
#include "TreeModel.h"
TreeView::TreeView(QMenu* menu, QWidget *parent)
: QTreeView(parent)
, menu_(menu)
{
createContextMenu();
this->setDragEnabled(true);
this->setAcceptDrops(true);
this->setDropIndicatorShown(true);
this->setHeaderHidden(true);
}
void TreeView::createContextMenu()
{
mnuAdd = new QAction(tr("Add"), this);
mnuRemove = new QAction(tr("Remove"), this);
mnuExpand = new QAction(tr("Expand all"), this);
mnuCollapse = new QAction(tr("Collapse all"), this);
connect(mnuAdd, SIGNAL(triggered()), this, SLOT(mnuAddClick()));
connect(mnuRemove, SIGNAL(triggered()), this, SLOT(mnuRemoveClick()));
connect(mnuExpand, SIGNAL(triggered()), this, SLOT(mnuExpandClick()));
connect(mnuCollapse, SIGNAL(triggered()), this, SLOT(mnuCollapseClick()));
}
QModelIndexList TreeView::selectedIndexes() const
{
return QTreeView::selectedIndexes();
}
void TreeView::mnuAddClick()
{
bool ok;
QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
tr("Group name:"), QLineEdit::Normal,
"", &ok);
if (ok && !text.isEmpty())
{
TreeModel* mm = (TreeModel*)this->model();
mm->addNewGroup(text);
}
}
void TreeView::mnuRemoveClick()
{
QModelIndex idx = currentIndex();
if( !idx.isValid() )
return;
TreeItem* ti = static_cast<TreeItem*>(idx.internalPointer());
GroupTreeItem* gti = dynamic_cast<GroupTreeItem*>(ti);
if( !gti )
return;
if( gti->childCount() > 0 )
{
QMessageBox::warning(this,"Cannot remove group","Group cannot be removed, because it contain other groups or PuTTY sessions.");
}else{
const Group* g = gti->getGroupInfo();
TreeModel* mm = (TreeModel*)this->model();
mm->removeGroup(g->groupId());
}
}
void TreeView::mnuExpandClick()
{
expandAll();
}
void TreeView::mnuCollapseClick()
{
collapseAll();
}
void TreeView::contextMenuEvent(QContextMenuEvent *event)
{
QMenu menu(this);
menu.addActions( menu_->actions() );
menu.addSeparator();
menu.addAction(mnuExpand);
menu.addAction(mnuCollapse);
menu.addSeparator();
menu.addAction(mnuAdd);
menu.addAction(mnuRemove);
menu.exec(event->globalPos());
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.