-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.cpp
More file actions
101 lines (81 loc) · 2.79 KB
/
Copy pathactions.cpp
File metadata and controls
101 lines (81 loc) · 2.79 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "actions.h"
QString Actions::m_separators = QLatin1String("|:+<");
Actions* Actions::instance()
{
static Actions acts;
return &acts;
}
Actions::Actions()
{
}
QAction* Actions::get(TActionString id, bool createIfNo)
{
const QString strId = QString::fromStdString(id);
if (createIfNo && !m_actions.contains(strId))
if (add(id) == NULL)
return NULL;
return m_actions[strId];
}
Actions* Actions::add(TActionString id, QAction* action)
{
bool isCheckable = false;
std::string idName = id;
if (idName.at(0) == '+')
{
isCheckable = true;
idName.erase(0, 1);
}
if (idName.empty() || !_checkSeporators(idName))
return NULL;
const QString strId = QString::fromStdString(idName);
if (m_actions.contains(strId))
return NULL;
action->setParent(this);
if (!action->isCheckable() && isCheckable)
action->setCheckable(isCheckable);
m_actions.insert(strId, action);
return this;
}
Actions* Actions::add(TActionString id, TActionString text) { return add(id, new QAction(tr(text.c_str()), this)); }
Actions* Actions::add(TActionString id, const QIcon& icon, TActionString text) { return add(id, new QAction(icon, tr(text.c_str()), this)); }
Actions* Actions::add(QAction* action) { return add(action->text().toStdString(), action); }
Actions* Actions::add(TActionString text) { return add(text, text); }
Actions* Actions::add(const QIcon& icon, TActionString text) { return add(text, icon, text); }
QActionGroup* Actions::getGroup(TActionString id, bool createIfNo)
{
const QString strId = QString::fromStdString(id);
if (createIfNo && !m_groups.contains(strId))
if (addGroup(id) == NULL)
return NULL;
return m_groups[strId];
}
Actions* Actions::addGroup(TActionString id)
{
const QString strId = QString::fromStdString(id);
if (id.empty() || !m_groups.contains(strId))
return NULL;
QActionGroup* newGroup = new QActionGroup(this);
m_groups.insert(strId, newGroup);
return this;
}
Actions* Actions::addGroup(TActionString id, TActionString actions)
{
QActionGroup* newGroup = getGroup(id, true);
QStringList actionsList = QString::fromStdString(actions).split(QRegExp("\\s+"));
for (QStringList::iterator it = actionsList.begin(); it != actionsList.end(); ++it)
{
QAction* action = get(it->toStdString(), true);
if (action != NULL)
newGroup->addAction(action);
}
return this;
}
bool Actions::_checkSeporators(TActionString text)
{
const QString strText = QString::fromStdString(text);
const QRegExp re("\\s");
for (QString::iterator it = m_separators.begin(); it != m_separators.end(); ++it)
if (strText.contains(*it) || re.indexIn(*it) != -1)
return false;
return true;
}