-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathfiletypesview.cpp
102 lines (82 loc) · 2.57 KB
/
filetypesview.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Created on: 4.4.2013
* Author: Antti Kamppi
* File name: filetypesview.cpp
* Project: Kactus 2
*/
#include "filetypesview.h"
#include <IPXACTmodels/common/FileType.h>
#include <QMenu>
FileTypesView::FileTypesView(QWidget *parent):
EditableTableView(parent) {
// user can only select one item at a time
setSelectionMode(QAbstractItemView::SingleSelection);
}
void FileTypesView::contextMenuEvent( QContextMenuEvent* event ) {
pressedPoint_ = event->pos();
QModelIndex index = indexAt(pressedPoint_);
QMenu menu(this);
menu.addAction(&addAction_);
// if at least one valid item is selected
if (index.isValid()) {
// find the index for the file type column, this is in case the user clicked some
// other column than file type
QModelIndex fileTypeIndex = index.model()->index(index.row(), 0, QModelIndex());
QString selectedFileType = fileTypeIndex.model()->data(fileTypeIndex, Qt::DisplayRole).toString();
// if the file type is user defined and not one of the file types specified
// by IP-XACT standard
if (!FileTypes::isIpXactFileType(selectedFileType, Document::Revision::Std22))
{
menu.addAction(&removeAction_);
menu.addAction(&clearAction_);
}
// if the file type was defined by IP-XACT standard
else {
// if user selected some other column than the file type column, it can be cleared
if (index.column() != 0) {
menu.addAction(&clearAction_);
}
}
menu.addAction(©Action_);
}
menu.addAction(&pasteAction_);
if (importExportAllowed())
{
menu.addSeparator();
menu.addAction(&importAction_);
menu.addAction(&exportAction_);
}
menu.exec(event->globalPos());
event->accept();
}
void FileTypesView::keyPressEvent( QKeyEvent* event ) {
// call the base class implementation
QTableView::keyPressEvent(event);
QModelIndex selected = currentIndex();
if (event->matches(QKeySequence::Copy))
{
onCopyAction();
}
if (event->matches(QKeySequence::Paste))
{
onPasteAction();
}
if (event->matches(QKeySequence::Delete))
{
// if user had selected the file type column
if (selected.column() == 0)
{
// if the file type is one of the standard ones, it can't be cleared
QString selectedFileType = selected.model()->data(selected, Qt::DisplayRole).toString();
if (FileTypes::isIpXactFileType(selectedFileType, Document::Revision::Std22))
{
return;
}
}
onClearAction();
}
if (event->matches(QKeySequence::InsertLineSeparator))
{
onAddAction();
}
}