Skip to content

Commit b014dad

Browse files
committed
some cleanup;
1 parent 5129b5a commit b014dad

File tree

7 files changed

+58
-62
lines changed

7 files changed

+58
-62
lines changed

MPSEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void MPSEngine::select_master_token (const std::wstring& file_name)
8787
} else {
8888

8989
// create new entry and add it into the internal map
90-
m_master_token = new MPSToken (0, file_name, m_default_separators, false);
90+
m_master_token = new MPSToken (NULL, file_name, m_default_separators, false);
9191

9292
// remove list of expressions
9393
std::wstring fn_clean = remove_strings_from_text(file_name);

MPSEngine.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <QVector>
1010
#include <QString>
1111

12-
class MPSEngine;
13-
1412
struct MPSFilesMapStruct {
1513
MPSToken* root;
1614
std::wstring rename_to;

MPSMainWindow.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,7 @@ void MPSMainWindow::update_renames_list ()
573573
m_gui_obj.lstRenames->clear();
574574

575575
QModelIndex modelIndex = m_files_model->index(m_files_model->rootPath());
576-
for (int idx = 0; idx < m_files_model->rowCount(modelIndex); ++idx) {
577-
// OLD: QModelIndex child = modelIndex.child(idx, modelIndex.column());
576+
for (int idx = 0; idx < m_files_model->rowCount(modelIndex); ++idx) {
578577
QModelIndex child = m_files_model->index(idx, modelIndex.column(), modelIndex);
579578

580579
// get the file name
@@ -716,7 +715,7 @@ void MPSMainWindow::update_shift_buttons ()
716715
return;
717716

718717
if (!token->parent()->sub_tokens_empty()) {
719-
bool is_first_subtoken = (*token->parent()->sub_tokens_const_begin()) == token;
718+
bool is_first_subtoken = (*token->parent()->subtokens_const_begin()) == token;
720719
m_gui_obj.btnShiftTokenLeft->setEnabled(!is_first_subtoken);
721720

722721
bool is_last_subtoken = token == token->parent()->last_subtoken();
@@ -976,8 +975,8 @@ void MPSMainWindow::construct_scene (
976975
QPointF last_subtoken_pos;
977976

978977
// iterate subtokens
979-
MPSTokensContainer::const_iterator iter = token->sub_tokens_const_begin();
980-
for ( ; iter != token->sub_tokens_const_end(); ++iter) {
978+
MPSTokensContainer::const_iterator iter = token->subtokens_const_begin();
979+
for ( ; iter != token->subtokens_const_end(); ++iter) {
981980
construct_scene(
982981
scene,
983982
(*iter), //iter->second,
@@ -997,7 +996,7 @@ void MPSMainWindow::construct_scene (
997996
);
998997

999998
// store first subtoken's pos for connector line
1000-
if (iter == token->sub_tokens_const_begin()) {
999+
if (iter == token->subtokens_const_begin()) {
10011000
first_subtoken_pos.setX(x_offset + subtoken_width / 2);
10021001
first_subtoken_pos.setY(y_offset - KInterTokenVerticalSpace / 2);
10031002
}
@@ -1834,6 +1833,9 @@ void MPSMainWindow::on_btnListRenames_clicked()
18341833
int rowCount = m_files_model->rowCount(modelIndex);
18351834
QString fileName; // child fileName
18361835

1836+
QModelIndex jx = m_gui_obj.tvFolders->currentIndex();
1837+
QString rupa = m_folders_model->rootPath();
1838+
int a = 3;
18371839
/*
18381840
QVector<QString> vec;
18391841
for (int row = 0; row < rowCount; ++row)

MPSToken.cpp

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#include "MPSToken.hpp"
22
#include "MPSCommon.hpp"
3-
#include <regex>
3+
4+
MPSToken::MPSToken( MPSToken* parent,
5+
const std::wstring& text,
6+
const std::wstring& separators,
7+
bool discard) :
8+
m_parent(parent),
9+
m_text(text),
10+
m_separators(separators),
11+
m_discard(discard)
12+
{}
413

514
MPSToken::~MPSToken ()
615
{
@@ -21,14 +30,14 @@ void MPSToken::shift_subtoken (MPSToken* sub_token, EMPSDirection direction)
2130
if (!sub_token)
2231
return;
2332

24-
if (m_sub_tokens.empty())
33+
if (m_subtokens.empty())
2534
return;
2635

27-
MPSTokensContainer::iterator iter = m_sub_tokens.begin();
28-
for ( ; iter != m_sub_tokens.end(); ++iter) {
36+
MPSTokensContainer::iterator iter = m_subtokens.begin();
37+
for ( ; iter != m_subtokens.end(); ++iter) {
2938
if (*iter == sub_token) {
3039
if (ELeft == direction) {
31-
if (iter == m_sub_tokens.begin())
40+
if (iter == m_subtokens.begin())
3241
return; // shift left requested on first subtoken, do nothing
3342

3443
MPSTokensContainer::iterator left = iter;
@@ -40,7 +49,7 @@ void MPSToken::shift_subtoken (MPSToken* sub_token, EMPSDirection direction)
4049
} else if (ERight == direction) {
4150
MPSTokensContainer::iterator right = iter;
4251
++right;
43-
if (right == m_sub_tokens.end())
52+
if (right == m_subtokens.end())
4453
return; // shift right requested on last subtoken, do nothing
4554

4655
std::swap (*iter, *right);
@@ -56,9 +65,6 @@ void MPSToken::split()
5665
if (m_separators.empty())
5766
return;
5867

59-
// check https://www.journaldev.com/37223/tokenize-string-c-plus-plus
60-
61-
6268
BoostSeparator separ (m_separators.c_str());
6369
BoostTokenizer tokenizer (m_text, separ);
6470

@@ -82,7 +88,7 @@ void MPSToken::split()
8288
for ( ; iter != tokenizer.end(); ++iter) {
8389
// create sub-tokens
8490
MPSToken* sub_token = new MPSToken (this, *iter, L"", m_discard);
85-
m_sub_tokens.push_back(sub_token);
91+
m_subtokens.push_back(sub_token);
8692
++count;
8793
}
8894
}
@@ -96,15 +102,15 @@ void MPSToken::insert_subtoken (const std::wstring& text, size_t pos)
96102
{
97103
if (pos == KLastSubtokenPosition) {
98104
// add on last position
99-
m_sub_tokens.push_back(new MPSToken (this, text));
105+
m_subtokens.push_back(new MPSToken (this, text));
100106
} else {
101107
size_t idx = 0;
102-
MPSTokensContainer::iterator iter = m_sub_tokens.begin();
103-
for ( ; (iter != m_sub_tokens.end()) && (idx != pos); ++iter, ++idx);
104-
if (iter == m_sub_tokens.end())
105-
m_sub_tokens.push_back(new MPSToken (this, text));
108+
MPSTokensContainer::iterator iter = m_subtokens.begin();
109+
for ( ; (iter != m_subtokens.end()) && (idx != pos); ++iter, ++idx);
110+
if (iter == m_subtokens.end())
111+
m_subtokens.push_back(new MPSToken (this, text));
106112
else
107-
m_sub_tokens.insert(iter, new MPSToken (this, text));
113+
m_subtokens.insert(iter, new MPSToken (this, text));
108114
}
109115
}
110116

@@ -128,16 +134,16 @@ void MPSToken::set_discard (bool discard)
128134

129135
void MPSToken::cleanup_token (MPSToken& token)
130136
{
131-
if (!token.m_sub_tokens.empty()) {
137+
if (!token.m_subtokens.empty()) {
132138
// we have some sub-tokens, need to delete them
133-
for (MPSTokensContainer::iterator iter = token.m_sub_tokens.begin(); iter != token.m_sub_tokens.end(); ++iter) {
139+
for (MPSTokensContainer::iterator iter = token.m_subtokens.begin(); iter != token.m_subtokens.end(); ++iter) {
134140
if (*iter != 0) {
135141
cleanup_token (*(*iter));
136142
delete (*iter);
137143
*iter = 0;
138144
}
139145
}
140-
token.m_sub_tokens.clear();
146+
token.m_subtokens.clear();
141147
}
142148
}
143149

@@ -154,18 +160,18 @@ void MPSToken::discard_token (MPSToken& token, bool discard)
154160
bool MPSToken::is_subtoken (const MPSToken* token) const
155161
{
156162
MPSTokensContainer::const_iterator pos;
157-
pos = std::find(m_sub_tokens.begin(), m_sub_tokens.end(), token);
158-
return (pos != m_sub_tokens.end());
163+
pos = std::find(m_subtokens.begin(), m_subtokens.end(), token);
164+
return (pos != m_subtokens.end());
159165
}
160166

161167
const MPSToken* MPSToken::last_subtoken () const
162168
{
163-
if (m_sub_tokens.empty())
169+
if (m_subtokens.empty())
164170
return 0;
165171

166172
const MPSToken* last = 0;
167-
MPSTokensContainer::const_iterator iter = m_sub_tokens.begin();
168-
for ( ; iter != m_sub_tokens.end();) {
173+
MPSTokensContainer::const_iterator iter = m_subtokens.begin();
174+
for ( ; iter != m_subtokens.end();) {
169175
last = (*iter);
170176
++iter;
171177
}
@@ -191,8 +197,8 @@ const MPSToken* MPSToken::find_last_leaf_subtoken (const MPSToken* token, bool i
191197
return token;
192198

193199
const MPSToken* last = 0;
194-
MPSTokensContainer::const_iterator iter = token->sub_tokens_const_begin();
195-
for ( ; iter != token->sub_tokens_const_end(); ) {
200+
MPSTokensContainer::const_iterator iter = token->subtokens_const_begin();
201+
for ( ; iter != token->subtokens_const_end(); ) {
196202

197203
// find only tokens which are not discarded
198204
bool discard_cond = (include_discarded) || (!include_discarded && !(*iter)->is_discard());
@@ -203,7 +209,7 @@ const MPSToken* MPSToken::find_last_leaf_subtoken (const MPSToken* token, bool i
203209
++iter;
204210

205211
// was it the last subttoken?
206-
if (iter == token->sub_tokens_const_end()) {
212+
if (iter == token->subtokens_const_end()) {
207213
if (last != 0 && !last->sub_tokens_empty()) {
208214
last = find_last_leaf_subtoken(last, include_discarded);
209215
}
@@ -223,8 +229,8 @@ const MPSToken* MPSToken::find_first_leaf_subtoken (const MPSToken* token, bool
223229
const MPSToken* first = 0;
224230

225231
// find first token which is not discarded
226-
MPSTokensContainer::const_iterator iter = token->sub_tokens_const_begin();
227-
for ( ; iter != token->sub_tokens_const_end(); ++ iter) {
232+
MPSTokensContainer::const_iterator iter = token->subtokens_const_begin();
233+
for ( ; iter != token->subtokens_const_end(); ++ iter) {
228234
bool discard_cond = (include_discarded) || (!include_discarded && !(*iter)->is_discard());
229235
if (*iter && discard_cond) {
230236
first = *iter;
@@ -233,7 +239,7 @@ const MPSToken* MPSToken::find_first_leaf_subtoken (const MPSToken* token, bool
233239
}
234240

235241
// if it has subtokens, find first undiscarded token in that group
236-
if (iter != token->sub_tokens_const_end() &&
242+
if (iter != token->subtokens_const_end() &&
237243
*iter &&
238244
!(*iter)->sub_tokens_empty())
239245
{

MPSToken.hpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ enum EMPSDirection {
1919
class MPSToken {
2020

2121
public:
22-
MPSToken ( MPSToken* parent,
23-
const std::wstring& text = L"",
24-
const std::wstring& separators = L"",
25-
bool discard = false ) :
26-
m_parent (parent),
27-
m_text (text),
28-
m_separators (separators),
29-
m_discard (discard)
30-
{}
22+
explicit MPSToken(MPSToken* parent = NULL,
23+
const std::wstring& text = L"",
24+
const std::wstring& separators = L"",
25+
bool discard = false);
3126

3227
~MPSToken ();
3328

@@ -46,12 +41,12 @@ class MPSToken {
4641
bool is_discard () const { return m_discard; }
4742

4843
// access to subtokens
49-
MPSTokensContainer::const_iterator sub_tokens_const_begin () const { return m_sub_tokens.begin(); }
50-
MPSTokensContainer::const_iterator sub_tokens_const_end () const { return m_sub_tokens.end(); }
51-
MPSTokensContainer::iterator sub_tokens_begin () { return m_sub_tokens.begin(); }
52-
MPSTokensContainer::iterator sub_tokens_end () { return m_sub_tokens.end(); }
53-
bool sub_tokens_empty () const { return m_sub_tokens.empty(); }
54-
size_t count_subtokens () const { return m_sub_tokens.size(); }
44+
MPSTokensContainer::const_iterator subtokens_const_begin () const { return m_subtokens.begin(); }
45+
MPSTokensContainer::const_iterator subtokens_const_end () const { return m_subtokens.end(); }
46+
MPSTokensContainer::iterator sub_tokens_begin () { return m_subtokens.begin(); }
47+
MPSTokensContainer::iterator sub_tokens_end () { return m_subtokens.end(); }
48+
bool sub_tokens_empty () const { return m_subtokens.empty(); }
49+
size_t count_subtokens () const { return m_subtokens.size(); }
5550
void clear_subtokens ();
5651

5752
/* checks if token is in the list of subtokens */
@@ -76,10 +71,7 @@ class MPSToken {
7671
*/
7772
void shift_subtoken (MPSToken* sub_token, EMPSDirection direction);
7873

79-
// counts the number of siblings left or right
80-
int count_siblings (EMPSDirection direction) const;
81-
82-
// splits the root token into subtokens based on the current separators
74+
// splits this token into subtokens based on current separators
8375
void split ();
8476

8577
private:
@@ -95,7 +87,7 @@ class MPSToken {
9587
std::wstring m_text; // original text
9688
std::wstring m_separators; // current separators
9789
bool m_discard; // flag to indicate if we're discarding this one or not
98-
MPSTokensContainer m_sub_tokens; // result after split into tokens using current separators
90+
MPSTokensContainer m_subtokens; // result after split into tokens using current separators
9991
};
10092

10193
#endif // MPSHEADER_HPP

MPSTokenWidget.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ void MPSTokenWidget::paint(QPainter* painter,
5151
QFontMetrics fm = painter->fontMetrics();
5252
QString text = QString::fromStdWString(m_token->text());
5353

54-
//OLD: QPoint center = QPoint( ( rect().width() - fm.lineWidth(text)) / 2,
55-
//( rect().height() + fm.height()) / 2 - 5);
5654
QPoint center = QPoint((rect().width() - fm.horizontalAdvance(text)) / 2,
5755
(rect().height() + fm.height()) / 2 - 5);
5856

MPSTransformsContainer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ MPSTransformInfo MPSTransformsContainer::get_transform_information_at (int idx)
111111

112112
if (idx < 0 || idx >= static_cast<int> (m_transforms.size()))
113113
{
114-
#pragma message (FixReminder "On invalid index, maybe should return some default dummy MPSTransformInfo")
114+
// return dummy info, check for action and condition index to be both -1
115115
return info;
116116
}
117117

0 commit comments

Comments
 (0)