Mercurial > hg > forks > UniversalIndentGUI
comparison src/IndentHandler.cpp @ 751:ac165b6ae67e
Done some refactoring:
- Moved includes into the cpp files where possible and using class pre-declarations if possible
- Made class member variable names begin with an underscore
- Made by uic created header files be used as class members instead of inherting them
- Renamed some variables to reflect their purpose better
- Added some NULL initializations and added some comments
- Rearranged some include and declaration code parts to be consistent and better readable
- Updated for QScintilla 2.4.5
- Made UiGuiSettings be accessed via a shared pointer only
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@1028 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Thu, 14 Oct 2010 19:52:47 +0000 |
parents | a884b5861e93 |
children | f3631db17328 |
comparison
equal
deleted
inserted
replaced
750:a884b5861e93 | 751:ac165b6ae67e |
---|---|
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | 17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 ***************************************************************************/ | 18 ***************************************************************************/ |
19 | 19 |
20 #include "IndentHandler.h" | 20 #include "IndentHandler.h" |
21 | 21 |
22 | 22 #include "UiGuiSettings.h" |
23 #include "UiGuiErrorMessage.h" | |
24 #include "TemplateBatchScript.h" | |
25 #include "UiGuiIniFileParser.h" | |
26 #include "SettingsPaths.h" | |
27 | |
28 #include <QToolBox> | |
29 #include <QVBoxLayout> | |
30 #include <QApplication> | |
31 #include <QCheckBox> | |
32 #include <QComboBox> | |
33 #include <QToolButton> | |
34 #include <QFile> | |
35 #include <QProcess> | |
36 #include <QSettings> | |
37 #include <QStringList> | |
38 #include <QLineEdit> | |
39 #include <QSpinBox> | |
40 #include <QLabel> | |
41 #include <QByteArray> | |
42 #include <QDir> | |
43 #include <QMessageBox> | |
44 #include <QMainWindow> | |
45 #include <QTextStream> | |
46 #include <QTextCodec> | |
47 #include <QtScript> | |
48 #include <QDesktopServices> | |
49 #include <QMenu> | |
50 #include <QAction> | |
51 #include <QContextMenuEvent> | |
52 #include <QFileDialog> | |
23 #include <QtDebug> | 53 #include <QtDebug> |
24 | |
25 #include "UiGuiSettings.h" | |
26 | 54 |
27 #ifdef Q_OS_WIN32 | 55 #ifdef Q_OS_WIN32 |
28 #include <Windows.h> | 56 #include <Windows.h> |
29 #endif | 57 #endif |
30 | 58 |
47 | 75 |
48 By calling this constructor the indenter to be loaded, can be selected by setting | 76 By calling this constructor the indenter to be loaded, can be selected by setting |
49 its \a indenterID, which is the number of found indenter ini files in alphabetic | 77 its \a indenterID, which is the number of found indenter ini files in alphabetic |
50 order starting at index 0. | 78 order starting at index 0. |
51 */ | 79 */ |
52 IndentHandler::IndentHandler(int indenterID, QWidget *mainWindow, QWidget *parent) : QWidget(parent) { | 80 IndentHandler::IndentHandler(int indenterID, QWidget *mainWindow, QWidget *parent) : QWidget(parent) |
81 , _indenterSelectionCombobox(NULL) | |
82 , _indenterParameterHelpButton(NULL) | |
83 , _toolBoxContainerLayout(NULL) | |
84 , _indenterParameterCategoriesToolBox(NULL) | |
85 , _indenterSettings(NULL) | |
86 , _mainWindow(NULL) | |
87 , _errorMessageDialog(NULL) | |
88 , _menuIndenter(NULL) | |
89 , _actionLoadIndenterConfigFile(NULL) | |
90 , _actionSaveIndenterConfigFile(NULL) | |
91 , _actionCreateShellScript(NULL) | |
92 , _actionResetIndenterParameters(NULL) | |
93 , _parameterChangedCallback(NULL) | |
94 , _windowClosedCallback(NULL) | |
95 { | |
53 Q_ASSERT_X( indenterID >= 0, "IndentHandler", "the selected indenterID is < 0" ); | 96 Q_ASSERT_X( indenterID >= 0, "IndentHandler", "the selected indenterID is < 0" ); |
54 | 97 |
55 setObjectName(QString::fromUtf8("indentHandler")); | 98 setObjectName(QString::fromUtf8("indentHandler")); |
56 | 99 |
57 this->mainWindow = mainWindow; | 100 _mainWindow = mainWindow; |
58 | 101 |
59 parameterChangedCallback = NULL; | |
60 windowClosedCallback = NULL; | |
61 indenterSettings = NULL; | |
62 menuIndenter = NULL; | |
63 actionLoad_Indenter_Config_File = NULL; | |
64 actionSave_Indenter_Config_File = NULL; | |
65 actionCreateShellScript = NULL; | |
66 initIndenterMenu(); | 102 initIndenterMenu(); |
67 | 103 |
68 connect( actionLoad_Indenter_Config_File, SIGNAL(triggered()), this, SLOT(openConfigFileDialog()) ); | 104 connect( _actionLoadIndenterConfigFile, SIGNAL(triggered()), this, SLOT(openConfigFileDialog()) ); |
69 connect( actionSave_Indenter_Config_File, SIGNAL(triggered()), this, SLOT(saveasIndentCfgFileDialog()) ); | 105 connect( _actionSaveIndenterConfigFile, SIGNAL(triggered()), this, SLOT(saveasIndentCfgFileDialog()) ); |
70 connect( actionCreateShellScript, SIGNAL(triggered()), this, SLOT(createIndenterCallShellScript()) ); | 106 connect( _actionCreateShellScript, SIGNAL(triggered()), this, SLOT(createIndenterCallShellScript()) ); |
71 connect( actionResetIndenterParameters, SIGNAL(triggered()), this, SLOT(resetIndenterParameter()) ); | 107 connect( _actionResetIndenterParameters, SIGNAL(triggered()), this, SLOT(resetIndenterParameter()) ); |
72 | 108 |
73 // define this widgets size and resize behavior | 109 // define this widgets resize behavior |
74 //this->setMaximumWidth(263); | 110 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); |
75 this->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); | |
76 | 111 |
77 // create vertical layout box, into which the toolbox will be added | 112 // create vertical layout box, into which the toolbox will be added |
78 vboxLayout = new QVBoxLayout(this); | 113 _toolBoxContainerLayout = new QVBoxLayout(this); |
79 vboxLayout->setMargin(2); | 114 _toolBoxContainerLayout->setMargin(2); |
80 | 115 |
81 // Create horizontal layout for indenter selector and help button. | 116 // Create horizontal layout for indenter selector and help button. |
82 QHBoxLayout *hboxLayout = new QHBoxLayout(); | 117 QHBoxLayout *hboxLayout = new QHBoxLayout(); |
83 //hboxLayout->setMargin(2); | 118 //hboxLayout->setMargin(2); |
84 vboxLayout->addLayout( hboxLayout ); | 119 _toolBoxContainerLayout->addLayout( hboxLayout ); |
85 | 120 |
86 // Create the indenter selection combo box. | 121 // Create the indenter selection combo box. |
87 indenterSelectionCombobox = new QComboBox(this); | 122 _indenterSelectionCombobox = new QComboBox(this); |
88 indenterSelectionCombobox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); | 123 _indenterSelectionCombobox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); |
89 indenterSelectionCombobox->setMinimumContentsLength(20); | 124 _indenterSelectionCombobox->setMinimumContentsLength(20); |
90 connect( indenterSelectionCombobox, SIGNAL(activated(int)), this, SLOT(setIndenter(int)) ); | 125 connect( _indenterSelectionCombobox, SIGNAL(activated(int)), this, SLOT(setIndenter(int)) ); |
91 UiGuiSettings::getInstance()->registerObjectProperty(indenterSelectionCombobox, "currentIndex", "selectedIndenter"); | 126 UiGuiSettings::getInstance()->registerObjectProperty(_indenterSelectionCombobox, "currentIndex", "selectedIndenter"); |
92 hboxLayout->addWidget( indenterSelectionCombobox ); | 127 hboxLayout->addWidget( _indenterSelectionCombobox ); |
93 | 128 |
94 // Create the indenter parameter help button. | 129 // Create the indenter parameter help button. |
95 indenterParameterHelpButton = new QToolButton(this); | 130 _indenterParameterHelpButton = new QToolButton(this); |
96 indenterParameterHelpButton->setObjectName(QString::fromUtf8("indenterParameterHelpButton")); | 131 _indenterParameterHelpButton->setObjectName(QString::fromUtf8("indenterParameterHelpButton")); |
97 indenterParameterHelpButton->setIcon(QIcon(QString::fromUtf8(":/mainWindow/help.png"))); | 132 _indenterParameterHelpButton->setIcon(QIcon(QString::fromUtf8(":/mainWindow/help.png"))); |
98 hboxLayout->addWidget( indenterParameterHelpButton ); | 133 hboxLayout->addWidget( _indenterParameterHelpButton ); |
99 // Handle if the indenter parameter help button is pressed. | 134 // Handle if the indenter parameter help button is pressed. |
100 connect( indenterParameterHelpButton, SIGNAL(clicked()), this, SLOT(showIndenterManual()) ); | 135 connect( _indenterParameterHelpButton, SIGNAL(clicked()), this, SLOT(showIndenterManual()) ); |
101 | 136 |
102 // create a toolbox and set its resize behavior | 137 // create a toolbox and set its resize behavior |
103 toolBox = new QToolBox(this); | 138 _indenterParameterCategoriesToolBox = new QToolBox(this); |
104 toolBox->setObjectName(QString::fromUtf8("toolBox")); | 139 _indenterParameterCategoriesToolBox->setObjectName(QString::fromUtf8("_indenterParameterCategoriesToolBox")); |
105 | 140 |
106 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS | 141 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS |
107 connect( toolBox, SIGNAL(currentChanged(int)), this, SLOT(updateDrawing()) ); | 142 connect( _indenterParameterCategoriesToolBox, SIGNAL(currentChanged(int)), this, SLOT(updateDrawing()) ); |
108 #endif // UNIVERSALINDENTGUI_NPP_EXPORTS | 143 #endif // UNIVERSALINDENTGUI_NPP_EXPORTS |
109 | 144 |
110 //toolBox->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); | 145 //_indenterParameterCategoriesToolBox->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); |
111 //toolBox->setMaximumSize(QSize(16777215, 16777215)); | 146 //_indenterParameterCategoriesToolBox->setMaximumSize(QSize(16777215, 16777215)); |
112 // insert the toolbox into the vlayout | 147 // insert the toolbox into the vlayout |
113 vboxLayout->addWidget(toolBox); | 148 _toolBoxContainerLayout->addWidget(_indenterParameterCategoriesToolBox); |
114 | 149 |
115 indenterExecutableCallString = ""; | 150 _indenterExecutableCallString = ""; |
116 indenterExecutableSuffix = ""; | 151 _indenterExecutableSuffix = ""; |
117 | 152 |
118 indenterDirctoryStr = SettingsPaths::getIndenterPath(); | 153 _indenterDirctoryStr = SettingsPaths::getIndenterPath(); |
119 tempDirctoryStr = SettingsPaths::getTempPath(); | 154 _tempDirctoryStr = SettingsPaths::getTempPath(); |
120 settingsDirctoryStr = SettingsPaths::getSettingsPath(); | 155 _settingsDirctoryStr = SettingsPaths::getSettingsPath(); |
121 QDir indenterDirctory = QDir(indenterDirctoryStr); | 156 QDir indenterDirctory = QDir(_indenterDirctoryStr); |
122 | 157 |
123 if ( mainWindow != NULL ) { | 158 if ( _mainWindow != NULL ) { |
124 errorMessageDialog = new UiGuiErrorMessage(mainWindow); | 159 _errorMessageDialog = new UiGuiErrorMessage(_mainWindow); |
125 } | 160 } |
126 else { | 161 else { |
127 errorMessageDialog = new UiGuiErrorMessage(this); | 162 _errorMessageDialog = new UiGuiErrorMessage(this); |
128 } | 163 } |
129 | 164 |
130 indenterIniFileList = indenterDirctory.entryList( QStringList("uigui_*.ini") ); | 165 _indenterIniFileList = indenterDirctory.entryList( QStringList("uigui_*.ini") ); |
131 if ( indenterIniFileList.count() > 0 ) { | 166 if ( _indenterIniFileList.count() > 0 ) { |
132 // Take care if the selected indenterID is smaller or greater than the number of existing indenters | 167 // Take care if the selected indenterID is smaller or greater than the number of existing indenters |
133 if ( indenterID < 0 ) { | 168 if ( indenterID < 0 ) { |
134 indenterID = 0; | 169 indenterID = 0; |
135 } | 170 } |
136 if ( indenterID >= indenterIniFileList.count() ) { | 171 if ( indenterID >= _indenterIniFileList.count() ) { |
137 indenterID = indenterIniFileList.count() - 1; | 172 indenterID = _indenterIniFileList.count() - 1; |
138 } | 173 } |
139 | 174 |
140 // Reads and parses the by indenterID defined indent ini file and creates toolbox entries | 175 // Reads and parses the by indenterID defined indent ini file and creates toolbox entries |
141 readIndentIniFile( indenterDirctoryStr + "/" + indenterIniFileList.at(indenterID) ); | 176 readIndentIniFile( _indenterDirctoryStr + "/" + _indenterIniFileList.at(indenterID) ); |
142 | 177 |
143 // Find out how the indenter can be executed. | 178 // Find out how the indenter can be executed. |
144 createIndenterCallString(); | 179 createIndenterCallString(); |
145 | 180 |
146 // Load the users last settings made for this indenter. | 181 // Load the users last settings made for this indenter. |
147 loadConfigFile( settingsDirctoryStr + "/" + indenterFileName + ".cfg" ); | 182 loadConfigFile( _settingsDirctoryStr + "/" + _indenterFileName + ".cfg" ); |
148 | 183 |
149 // Fill the indenter selection combo box with the list of available indenters. | 184 // Fill the indenter selection combo box with the list of available indenters. |
150 if ( !getAvailableIndenters().isEmpty() ) { | 185 if ( !getAvailableIndenters().isEmpty() ) { |
151 indenterSelectionCombobox->addItems( getAvailableIndenters() ); | 186 _indenterSelectionCombobox->addItems( getAvailableIndenters() ); |
152 indenterSelectionCombobox->setCurrentIndex( indenterID ); | 187 _indenterSelectionCombobox->setCurrentIndex( indenterID ); |
153 connect( indenterSelectionCombobox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(selectedIndenterIndexChanged(int)) ); | 188 connect( _indenterSelectionCombobox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(selectedIndenterIndexChanged(int)) ); |
154 } | 189 } |
155 } | 190 } |
156 else { | 191 else { |
157 errorMessageDialog->showMessage(tr("No indenter ini files"), tr("There exists no indenter ini files in the directory \"") + QDir(indenterDirctoryStr).absolutePath() + "\"."); | 192 _errorMessageDialog->showMessage(tr("No indenter ini files"), tr("There exists no indenter ini files in the directory \"") + QDir(_indenterDirctoryStr).absolutePath() + "\"."); |
158 } | 193 } |
159 | 194 |
160 retranslateUi(); | 195 retranslateUi(); |
161 } | 196 } |
162 | 197 |
165 \brief Implicitly writes the current indenter parameters to the indenters config file. | 200 \brief Implicitly writes the current indenter parameters to the indenters config file. |
166 */ | 201 */ |
167 IndentHandler::~IndentHandler() { | 202 IndentHandler::~IndentHandler() { |
168 // Generate the parameter string that will be saved to the indenters config file. | 203 // Generate the parameter string that will be saved to the indenters config file. |
169 QString parameterString = getParameterString(); | 204 QString parameterString = getParameterString(); |
170 if ( !indenterFileName.isEmpty() ) { | 205 if ( !_indenterFileName.isEmpty() ) { |
171 saveConfigFile( settingsDirctoryStr + "/" + indenterFileName + ".cfg", parameterString ); | 206 saveConfigFile( _settingsDirctoryStr + "/" + _indenterFileName + ".cfg", parameterString ); |
172 } | 207 } |
173 | 208 |
174 delete errorMessageDialog; | 209 delete _errorMessageDialog; |
175 } | 210 } |
176 | 211 |
177 | 212 |
178 /*! | 213 /*! |
179 \brief Initializes the context menu used for some actions like saving the indenter config file. | 214 \brief Initializes the context menu used for some actions like saving the indenter config file. |
180 */ | 215 */ |
181 void IndentHandler::initIndenterMenu() { | 216 void IndentHandler::initIndenterMenu() { |
182 if ( menuIndenter == NULL ) { | 217 if ( _menuIndenter == NULL ) { |
183 actionLoad_Indenter_Config_File = new QAction(this); | 218 _actionLoadIndenterConfigFile = new QAction(this); |
184 actionLoad_Indenter_Config_File->setObjectName(QString::fromUtf8("actionLoad_Indenter_Config_File")); | 219 _actionLoadIndenterConfigFile->setObjectName(QString::fromUtf8("_actionLoadIndenterConfigFile")); |
185 actionLoad_Indenter_Config_File->setIcon(QIcon(QString::fromUtf8(":/mainWindow/load_indent_cfg.png"))); | 220 _actionLoadIndenterConfigFile->setIcon(QIcon(QString::fromUtf8(":/mainWindow/load_indent_cfg.png"))); |
186 | 221 |
187 actionSave_Indenter_Config_File = new QAction(this); | 222 _actionSaveIndenterConfigFile = new QAction(this); |
188 actionSave_Indenter_Config_File->setObjectName(QString::fromUtf8("actionSave_Indenter_Config_File")); | 223 _actionSaveIndenterConfigFile->setObjectName(QString::fromUtf8("_actionSaveIndenterConfigFile")); |
189 actionSave_Indenter_Config_File->setIcon(QIcon(QString::fromUtf8(":/mainWindow/save_indent_cfg.png"))); | 224 _actionSaveIndenterConfigFile->setIcon(QIcon(QString::fromUtf8(":/mainWindow/save_indent_cfg.png"))); |
190 | 225 |
191 actionCreateShellScript = new QAction(this); | 226 _actionCreateShellScript = new QAction(this); |
192 actionCreateShellScript->setObjectName(QString::fromUtf8("actionCreateShellScript")); | 227 _actionCreateShellScript->setObjectName(QString::fromUtf8("_actionCreateShellScript")); |
193 actionCreateShellScript->setIcon(QIcon(QString::fromUtf8(":/mainWindow/shell.png"))); | 228 _actionCreateShellScript->setIcon(QIcon(QString::fromUtf8(":/mainWindow/shell.png"))); |
194 | 229 |
195 actionResetIndenterParameters = new QAction(this); | 230 _actionResetIndenterParameters = new QAction(this); |
196 actionResetIndenterParameters->setObjectName(QString::fromUtf8("actionResetIndenterParameters")); | 231 _actionResetIndenterParameters->setObjectName(QString::fromUtf8("_actionResetIndenterParameters")); |
197 actionResetIndenterParameters->setIcon(QIcon(QString::fromUtf8(":/mainWindow/view-refresh.png"))); | 232 _actionResetIndenterParameters->setIcon(QIcon(QString::fromUtf8(":/mainWindow/view-refresh.png"))); |
198 | 233 |
199 menuIndenter = new QMenu(this); | 234 _menuIndenter = new QMenu(this); |
200 menuIndenter->setObjectName(QString::fromUtf8("menuIndenter")); | 235 _menuIndenter->setObjectName(QString::fromUtf8("_menuIndenter")); |
201 menuIndenter->addAction(actionLoad_Indenter_Config_File); | 236 _menuIndenter->addAction(_actionLoadIndenterConfigFile); |
202 menuIndenter->addAction(actionSave_Indenter_Config_File); | 237 _menuIndenter->addAction(_actionSaveIndenterConfigFile); |
203 menuIndenter->addAction(actionCreateShellScript); | 238 _menuIndenter->addAction(_actionCreateShellScript); |
204 menuIndenter->addAction(actionResetIndenterParameters); | 239 _menuIndenter->addAction(_actionResetIndenterParameters); |
205 } | 240 } |
206 } | 241 } |
207 | 242 |
208 | 243 |
209 /*! | 244 /*! |
210 \brief Returns the context menu used for some actions like saving the indenter config file. | 245 \brief Returns the context menu used for some actions like saving the indenter config file. |
211 */ | 246 */ |
212 QMenu* IndentHandler::getIndenterMenu() { | 247 QMenu* IndentHandler::getIndenterMenu() { |
213 return menuIndenter; | 248 return _menuIndenter; |
214 } | 249 } |
215 | 250 |
216 | 251 |
217 /*! | 252 /*! |
218 \brief Returns the actions of the context menu used for some actions like saving the indenter config file. | 253 \brief Returns the actions of the context menu used for some actions like saving the indenter config file. |
219 */ | 254 */ |
220 QList<QAction*> IndentHandler::getIndenterMenuActions() { | 255 QList<QAction*> IndentHandler::getIndenterMenuActions() { |
221 QList<QAction*> actionList; | 256 QList<QAction*> actionList; |
222 actionList << actionLoad_Indenter_Config_File << actionSave_Indenter_Config_File << actionCreateShellScript << actionResetIndenterParameters; | 257 actionList << _actionLoadIndenterConfigFile << _actionSaveIndenterConfigFile << _actionCreateShellScript << _actionResetIndenterParameters; |
223 return actionList; | 258 return actionList; |
224 } | 259 } |
225 | 260 |
226 | 261 |
227 /*! | 262 /*! |
248 QString shellParameterPlaceholder = "%1"; | 283 QString shellParameterPlaceholder = "%1"; |
249 #else | 284 #else |
250 QString shellParameterPlaceholder = "$1"; | 285 QString shellParameterPlaceholder = "$1"; |
251 #endif | 286 #endif |
252 | 287 |
253 parameterInputFile = " " + inputFileParameter + "\"" + shellParameterPlaceholder + "\""; | 288 parameterInputFile = " " + _inputFileParameter + "\"" + shellParameterPlaceholder + "\""; |
254 | 289 |
255 if ( outputFileParameter != "none" && outputFileParameter != "stdout" ) { | 290 if ( _outputFileParameter != "none" && _outputFileParameter != "stdout" ) { |
256 if ( outputFileName == inputFileName ) { | 291 if ( _outputFileName == _inputFileName ) { |
257 parameterOuputFile = " " + outputFileParameter + "\"" + shellParameterPlaceholder + "\""; | 292 parameterOuputFile = " " + _outputFileParameter + "\"" + shellParameterPlaceholder + "\""; |
258 } | 293 } |
259 else { | 294 else { |
260 parameterOuputFile = " " + outputFileParameter + outputFileName + ".tmp"; | 295 parameterOuputFile = " " + _outputFileParameter + _outputFileName + ".tmp"; |
261 } | 296 } |
262 } | 297 } |
263 | 298 |
264 // If the config file name is empty it is assumed that all parameters are sent via command line call | 299 // If the config file name is empty it is assumed that all parameters are sent via command line call |
265 if ( globalConfigFilename_.isEmpty() ) { | 300 if ( _globalConfigFilename.isEmpty() ) { |
266 parameterParameterFile = " " + getParameterString(); | 301 parameterParameterFile = " " + getParameterString(); |
267 } | 302 } |
268 // else if needed add the parameter to the indenter call string where the config file can be found. | 303 // else if needed add the parameter to the indenter call string where the config file can be found. |
269 else if (useCfgFileParameter != "none") { | 304 else if (_useCfgFileParameter != "none") { |
270 parameterParameterFile = " " + useCfgFileParameter + "\"./" + configFilename + "\""; | 305 parameterParameterFile = " " + _useCfgFileParameter + "\"./" + configFilename + "\""; |
271 } | 306 } |
272 | 307 |
273 // Assemble indenter call string for parameters according to the set order. | 308 // Assemble indenter call string for parameters according to the set order. |
274 if ( parameterOrder == "ipo" ) { | 309 if ( _parameterOrder == "ipo" ) { |
275 indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile; | 310 indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile; |
276 } | 311 } |
277 else if ( parameterOrder == "pio" ) { | 312 else if ( _parameterOrder == "pio" ) { |
278 indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile; | 313 indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile; |
279 } | 314 } |
280 else if ( parameterOrder == "poi" ) { | 315 else if ( _parameterOrder == "poi" ) { |
281 indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile; | 316 indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile; |
282 } | 317 } |
283 else { | 318 else { |
284 indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile; | 319 indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile; |
285 } | 320 } |
286 | 321 |
287 // Generate the indenter call string either for win32 or other systems. | 322 // Generate the indenter call string either for win32 or other systems. |
288 #if defined(Q_OS_WIN32) | 323 #if defined(Q_OS_WIN32) |
289 indenterCompleteCallString = indenterExecutableCallString + indenterCompleteCallString; | 324 indenterCompleteCallString = _indenterExecutableCallString + indenterCompleteCallString; |
290 #else | 325 #else |
291 indenterCompleteCallString = "#!/bin/bash\n" + indenterExecutableCallString + indenterCompleteCallString; | 326 indenterCompleteCallString = "#!/bin/bash\n" + _indenterExecutableCallString + indenterCompleteCallString; |
292 #endif | 327 #endif |
293 | 328 |
294 // If the indenter writes to stdout pipe the output into a file | 329 // If the indenter writes to stdout pipe the output into a file |
295 if ( outputFileParameter == "stdout" ) { | 330 if ( _outputFileParameter == "stdout" ) { |
296 indenterCompleteCallString = indenterCompleteCallString + " >" + outputFileName + ".tmp"; | 331 indenterCompleteCallString = indenterCompleteCallString + " >" + _outputFileName + ".tmp"; |
297 } | 332 } |
298 | 333 |
299 // If the output filename is not the same as the input filename copy the output over the input. | 334 // If the output filename is not the same as the input filename copy the output over the input. |
300 if ( outputFileName != inputFileName ) { | 335 if ( _outputFileName != _inputFileName ) { |
301 #if defined(Q_OS_WIN32) | 336 #if defined(Q_OS_WIN32) |
302 replaceInputFileCommand = "move /Y " + outputFileName + ".tmp \"" + shellParameterPlaceholder + "\"\n"; | 337 replaceInputFileCommand = "move /Y " + _outputFileName + ".tmp \"" + shellParameterPlaceholder + "\"\n"; |
303 #else | 338 #else |
304 replaceInputFileCommand = "mv " + outputFileName + ".tmp \"" + shellParameterPlaceholder + "\"\n"; | 339 replaceInputFileCommand = "mv " + _outputFileName + ".tmp \"" + shellParameterPlaceholder + "\"\n"; |
305 #endif | 340 #endif |
306 } | 341 } |
307 | 342 |
308 #if defined(Q_OS_WIN32) | 343 #if defined(Q_OS_WIN32) |
309 QString shellScript( TemplateBatchScript::getTemplateBatchScript() ); | 344 QString shellScript( TemplateBatchScript::getTemplateBatchScript() ); |
328 | 363 |
329 The \a inputFileExtension has to be given as parameter so the called indenter | 364 The \a inputFileExtension has to be given as parameter so the called indenter |
330 can identify the programming language if needed. | 365 can identify the programming language if needed. |
331 */ | 366 */ |
332 QString IndentHandler::callIndenter(QString sourceCode, QString inputFileExtension) { | 367 QString IndentHandler::callIndenter(QString sourceCode, QString inputFileExtension) { |
333 if ( indenterExecutableSuffix == ".js" ) { | 368 if ( _indenterExecutableSuffix == ".js" ) { |
334 return callJavaScriptIndenter(sourceCode); | 369 return callJavaScriptIndenter(sourceCode); |
335 } | 370 } |
336 else { | 371 else { |
337 return callExecutableIndenter(sourceCode, inputFileExtension); | 372 return callExecutableIndenter(sourceCode, inputFileExtension); |
338 } | 373 } |
348 QString IndentHandler::callJavaScriptIndenter(QString sourceCode) { | 383 QString IndentHandler::callJavaScriptIndenter(QString sourceCode) { |
349 QScriptEngine engine; | 384 QScriptEngine engine; |
350 | 385 |
351 engine.globalObject().setProperty("unformattedCode", sourceCode); | 386 engine.globalObject().setProperty("unformattedCode", sourceCode); |
352 | 387 |
353 QFile jsDecoderFile( indenterExecutableCallString ); | 388 QFile jsDecoderFile( _indenterExecutableCallString ); |
354 QString jsDecoderCode; | 389 QString jsDecoderCode; |
355 if (jsDecoderFile.open(QFile::ReadOnly)) { | 390 if (jsDecoderFile.open(QFile::ReadOnly)) { |
356 jsDecoderCode = jsDecoderFile.readAll(); | 391 jsDecoderCode = jsDecoderFile.readAll(); |
357 } | 392 } |
358 jsDecoderFile.close(); | 393 jsDecoderFile.close(); |
367 | 402 |
368 The \a inputFileExtension has to be given as parameter so the called indenter | 403 The \a inputFileExtension has to be given as parameter so the called indenter |
369 can identify the programming language if needed. | 404 can identify the programming language if needed. |
370 */ | 405 */ |
371 QString IndentHandler::callExecutableIndenter(QString sourceCode, QString inputFileExtension) { | 406 QString IndentHandler::callExecutableIndenter(QString sourceCode, QString inputFileExtension) { |
372 Q_ASSERT_X( !inputFileName.isEmpty(), "callIndenter", "inputFileName is empty" ); | 407 Q_ASSERT_X( !_inputFileName.isEmpty(), "callIndenter", "_inputFileName is empty" ); |
373 // Q_ASSERT_X( !outputFileName.isEmpty(), "callIndenter", "outputFileName is empty" ); | 408 // Q_ASSERT_X( !_outputFileName.isEmpty(), "callIndenter", "_outputFileName is empty" ); |
374 Q_ASSERT_X( !indenterFileName.isEmpty(), "callIndenter", "indenterFileName is empty" ); | 409 Q_ASSERT_X( !_indenterFileName.isEmpty(), "callIndenter", "_indenterFileName is empty" ); |
375 | 410 |
376 if ( indenterFileName.isEmpty() ) { | 411 if ( _indenterFileName.isEmpty() ) { |
377 return ""; | 412 return ""; |
378 } | 413 } |
379 | 414 |
380 QString formattedSourceCode; | 415 QString formattedSourceCode; |
381 QString indenterCompleteCallString; | 416 QString indenterCompleteCallString; |
386 QString processReturnString; | 421 QString processReturnString; |
387 | 422 |
388 // Generate the parameter string that will be saved to the indenters config file | 423 // Generate the parameter string that will be saved to the indenters config file |
389 QString parameterString = getParameterString(); | 424 QString parameterString = getParameterString(); |
390 | 425 |
391 if ( !globalConfigFilename_.isEmpty() ) { | 426 if ( !_globalConfigFilename.isEmpty() ) { |
392 saveConfigFile( tempDirctoryStr + "/" + globalConfigFilename_, parameterString ); | 427 saveConfigFile( _tempDirctoryStr + "/" + _globalConfigFilename, parameterString ); |
393 } | 428 } |
394 | 429 |
395 // Only add a dot to file extension if the string is not empty | 430 // Only add a dot to file extension if the string is not empty |
396 if ( !inputFileExtension.isEmpty() ) { | 431 if ( !inputFileExtension.isEmpty() ) { |
397 inputFileExtension = "." + inputFileExtension; | 432 inputFileExtension = "." + inputFileExtension; |
398 } | 433 } |
399 | 434 |
400 // Delete any previously used input src file and create a new input src file. | 435 // Delete any previously used input src file and create a new input src file. |
401 QFile::remove(tempDirctoryStr + "/" + inputFileName + inputFileExtension); | 436 QFile::remove(_tempDirctoryStr + "/" + _inputFileName + inputFileExtension); |
402 QFile inputSrcFile(tempDirctoryStr + "/" + inputFileName + inputFileExtension); | 437 QFile inputSrcFile(_tempDirctoryStr + "/" + _inputFileName + inputFileExtension); |
403 // Write the source code to the input file for the indenter | 438 // Write the source code to the input file for the indenter |
404 if ( inputSrcFile.open( QFile::ReadWrite | QFile::Text ) ) { | 439 if ( inputSrcFile.open( QFile::ReadWrite | QFile::Text ) ) { |
405 inputSrcFile.write( sourceCode.toUtf8() ); | 440 inputSrcFile.write( sourceCode.toUtf8() ); |
406 inputSrcFile.close(); | 441 inputSrcFile.close(); |
407 qDebug() << __LINE__ << " " << __FUNCTION__ << ": Wrote to be indented source code to file " << inputSrcFile.fileName(); | 442 qDebug() << __LINE__ << " " << __FUNCTION__ << ": Wrote to be indented source code to file " << inputSrcFile.fileName(); |
409 else { | 444 else { |
410 qCritical() << __LINE__ << " " << __FUNCTION__ << ": Couldn't write to be indented source code to file " << inputSrcFile.fileName(); | 445 qCritical() << __LINE__ << " " << __FUNCTION__ << ": Couldn't write to be indented source code to file " << inputSrcFile.fileName(); |
411 } | 446 } |
412 | 447 |
413 // Set the input file for the to be called indenter. | 448 // Set the input file for the to be called indenter. |
414 if ( inputFileParameter.trimmed() == "<" || inputFileParameter == "stdin" ) { | 449 if ( _inputFileParameter.trimmed() == "<" || _inputFileParameter == "stdin" ) { |
415 parameterInputFile = ""; | 450 parameterInputFile = ""; |
416 indentProcess.setStandardInputFile( inputSrcFile.fileName() ); | 451 indentProcess.setStandardInputFile( inputSrcFile.fileName() ); |
417 } | 452 } |
418 else { | 453 else { |
419 parameterInputFile = " " + inputFileParameter + inputFileName + inputFileExtension; | 454 parameterInputFile = " " + _inputFileParameter + _inputFileName + inputFileExtension; |
420 } | 455 } |
421 | 456 |
422 // Set the output file for the to be called indenter. | 457 // Set the output file for the to be called indenter. |
423 if ( outputFileParameter != "none" && outputFileParameter != "stdout" ) { | 458 if ( _outputFileParameter != "none" && _outputFileParameter != "stdout" ) { |
424 parameterOuputFile = " " + outputFileParameter + outputFileName + inputFileExtension; | 459 parameterOuputFile = " " + _outputFileParameter + _outputFileName + inputFileExtension; |
425 } | 460 } |
426 | 461 |
427 #ifdef Q_OS_WIN32 | 462 #ifdef Q_OS_WIN32 |
428 // Paths may contain Unicode or other foreign characters. Windows commands line tools will | 463 // Paths may contain Unicode or other foreign characters. Windows commands line tools will |
429 // receive als falsely encoded path string by QProcess or they connot correctly handle | 464 // receive als falsely encoded path string by QProcess or they connot correctly handle |
430 // the Unicode path on their own. | 465 // the Unicode path on their own. |
431 // Because of this the path gets converted to Windows short paths using the 8.3 notation. | 466 // Because of this the path gets converted to Windows short paths using the 8.3 notation. |
432 | 467 |
433 qDebug() << __LINE__ << " " << __FUNCTION__ << ": Temp dir before trying to convert it to short Windows path is" << tempDirctoryStr; | 468 qDebug() << __LINE__ << " " << __FUNCTION__ << ": Temp dir before trying to convert it to short Windows path is" << _tempDirctoryStr; |
434 | 469 |
435 // At first convert the temp path to Windows like separators. | 470 // At first convert the temp path to Windows like separators. |
436 QString tempDirctoryStrHelper = QDir::toNativeSeparators(tempDirctoryStr).replace("\\", "\\\\"); | 471 QString tempDirctoryStrHelper = QDir::toNativeSeparators(_tempDirctoryStr).replace("\\", "\\\\"); |
437 // Then convert the QString to a WCHAR array and NULL terminate it. | 472 // Then convert the QString to a WCHAR array and NULL terminate it. |
438 WCHAR *tempDirctoryWindowsStr = new WCHAR[ tempDirctoryStrHelper.length()+1 ]; | 473 WCHAR *tempDirctoryWindowsStr = new WCHAR[ tempDirctoryStrHelper.length()+1 ]; |
439 tempDirctoryStrHelper.toWCharArray( tempDirctoryWindowsStr ); | 474 tempDirctoryStrHelper.toWCharArray( tempDirctoryWindowsStr ); |
440 tempDirctoryWindowsStr[ tempDirctoryStrHelper.length() ] = (WCHAR)NULL; | 475 tempDirctoryWindowsStr[ tempDirctoryStrHelper.length() ] = (WCHAR)NULL; |
441 | 476 |
454 #else | 489 #else |
455 buffer = new TCHAR[length]; | 490 buffer = new TCHAR[length]; |
456 length = GetShortPathName((LPCTSTR)tempDirctoryWindowsStr, buffer, length); | 491 length = GetShortPathName((LPCTSTR)tempDirctoryWindowsStr, buffer, length); |
457 tempDirctoryStrHelper = buffer; | 492 tempDirctoryStrHelper = buffer; |
458 #endif | 493 #endif |
459 tempDirctoryStr = QDir::fromNativeSeparators(tempDirctoryStrHelper).replace("//", "/"); | 494 _tempDirctoryStr = QDir::fromNativeSeparators(tempDirctoryStrHelper).replace("//", "/"); |
460 delete [] buffer; | 495 delete [] buffer; |
461 | 496 |
462 // Check whether the short path still contains some kind of non ascii characters. | 497 // Check whether the short path still contains some kind of non ascii characters. |
463 if ( tempDirctoryStr.length() != tempDirctoryStr.toAscii().length() ) { | 498 if ( _tempDirctoryStr.length() != _tempDirctoryStr.toAscii().length() ) { |
464 qWarning() << __LINE__ << " " << __FUNCTION__ << ": Shortened path still contains non ascii characters. Could cause some indenters not to work properly!"; | 499 qWarning() << __LINE__ << " " << __FUNCTION__ << ": Shortened path still contains non ascii characters. Could cause some indenters not to work properly!"; |
465 } | 500 } |
466 } | 501 } |
467 else { | 502 else { |
468 qWarning() << __LINE__ << " " << __FUNCTION__ << ": Couldn't retrieve a short version of the temporary path!"; | 503 qWarning() << __LINE__ << " " << __FUNCTION__ << ": Couldn't retrieve a short version of the temporary path!"; |
469 } | 504 } |
470 | 505 |
471 qDebug() << __LINE__ << " " << __FUNCTION__ << ": Temp dir after trying to convert it to short Windows path is " << tempDirctoryStr; | 506 qDebug() << __LINE__ << " " << __FUNCTION__ << ": Temp dir after trying to convert it to short Windows path is " << _tempDirctoryStr; |
472 | 507 |
473 delete [] tempDirctoryWindowsStr; | 508 delete [] tempDirctoryWindowsStr; |
474 #endif | 509 #endif |
475 | 510 |
476 // If the config file name is empty it is assumed that all parameters are sent via command line call | 511 // If the config file name is empty it is assumed that all parameters are sent via command line call |
477 if ( globalConfigFilename_.isEmpty() ) { | 512 if ( _globalConfigFilename.isEmpty() ) { |
478 parameterParameterFile = " " + parameterString; | 513 parameterParameterFile = " " + parameterString; |
479 } | 514 } |
480 // if needed add the parameter to the indenter call string where the config file can be found | 515 // if needed add the parameter to the indenter call string where the config file can be found |
481 else if (useCfgFileParameter != "none") { | 516 else if (_useCfgFileParameter != "none") { |
482 parameterParameterFile = " " + useCfgFileParameter + "\"" + tempDirctoryStr + "/" + globalConfigFilename_ + "\""; | 517 parameterParameterFile = " " + _useCfgFileParameter + "\"" + _tempDirctoryStr + "/" + _globalConfigFilename + "\""; |
483 } | 518 } |
484 | 519 |
485 // Assemble indenter call string for parameters according to the set order. | 520 // Assemble indenter call string for parameters according to the set order. |
486 if ( parameterOrder == "ipo" ) { | 521 if ( _parameterOrder == "ipo" ) { |
487 indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile; | 522 indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile; |
488 } | 523 } |
489 else if ( parameterOrder == "pio" ) { | 524 else if ( _parameterOrder == "pio" ) { |
490 indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile; | 525 indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile; |
491 } | 526 } |
492 else if ( parameterOrder == "poi" ) { | 527 else if ( _parameterOrder == "poi" ) { |
493 indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile; | 528 indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile; |
494 } | 529 } |
495 else { | 530 else { |
496 indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile; | 531 indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile; |
497 } | 532 } |
498 | 533 |
499 // If no indenter executable call string could be created before, show an error message. | 534 // If no indenter executable call string could be created before, show an error message. |
500 if ( indenterExecutableCallString.isEmpty() ) { | 535 if ( _indenterExecutableCallString.isEmpty() ) { |
501 errorMessageDialog->showMessage(tr("No indenter executable"), | 536 _errorMessageDialog->showMessage(tr("No indenter executable"), |
502 tr("There exists no indenter executable with the name \"%1\" in the directory \"%2\" nor in the global environment.").arg(indenterFileName).arg(indenterDirctoryStr) ); | 537 tr("There exists no indenter executable with the name \"%1\" in the directory \"%2\" nor in the global environment.").arg(_indenterFileName).arg(_indenterDirctoryStr) ); |
503 return sourceCode; | 538 return sourceCode; |
504 } | 539 } |
505 | 540 |
506 // Generate the indenter call string either for win32 or other systems. | 541 // Generate the indenter call string either for win32 or other systems. |
507 indenterCompleteCallString = indenterExecutableCallString + indenterCompleteCallString; | 542 indenterCompleteCallString = _indenterExecutableCallString + indenterCompleteCallString; |
508 | 543 |
509 // errors and standard outputs from the process call are merged together | 544 // errors and standard outputs from the process call are merged together |
510 //indentProcess.setReadChannelMode(QProcess::MergedChannels); | 545 //indentProcess.setReadChannelMode(QProcess::MergedChannels); |
511 | 546 |
512 // Set the directory where the indenter will be executed for the process' environment as PWD. | 547 // Set the directory where the indenter will be executed for the process' environment as PWD. |
513 QStringList env = indentProcess.environment(); | 548 QStringList env = indentProcess.environment(); |
514 env << "PWD=" + QFileInfo(tempDirctoryStr).absoluteFilePath(); | 549 env << "PWD=" + QFileInfo(_tempDirctoryStr).absoluteFilePath(); |
515 indentProcess.setEnvironment( env ); | 550 indentProcess.setEnvironment( env ); |
516 | 551 |
517 // Set the directory for the indenter execution | 552 // Set the directory for the indenter execution |
518 indentProcess.setWorkingDirectory( QFileInfo(tempDirctoryStr).absoluteFilePath() ); | 553 indentProcess.setWorkingDirectory( QFileInfo(_tempDirctoryStr).absoluteFilePath() ); |
519 | 554 |
520 qDebug() << __LINE__ << " " << __FUNCTION__ << ": Will call the indenter in the directory " << indentProcess.workingDirectory() << " using this commandline call: " << indenterCompleteCallString; | 555 qDebug() << __LINE__ << " " << __FUNCTION__ << ": Will call the indenter in the directory " << indentProcess.workingDirectory() << " using this commandline call: " << indenterCompleteCallString; |
521 | 556 |
522 indentProcess.start(indenterCompleteCallString); | 557 indentProcess.start(indenterCompleteCallString); |
523 | 558 |
555 "(STDOUT):" + encodeToHTML( indentProcess.readAllStandardOutput() ) + "<br>" + | 590 "(STDOUT):" + encodeToHTML( indentProcess.readAllStandardOutput() ) + "<br>" + |
556 "(STDERR):" + encodeToHTML( indentProcess.readAllStandardError() ) + "<br>" + | 591 "(STDERR):" + encodeToHTML( indentProcess.readAllStandardError() ) + "<br>" + |
557 "</pre></html></body>"; | 592 "</pre></html></body>"; |
558 qWarning() << __LINE__ << " " << __FUNCTION__ << processReturnString; | 593 qWarning() << __LINE__ << " " << __FUNCTION__ << processReturnString; |
559 QApplication::restoreOverrideCursor(); | 594 QApplication::restoreOverrideCursor(); |
560 errorMessageDialog->showMessage(tr("Error calling Indenter"), processReturnString); | 595 _errorMessageDialog->showMessage(tr("Error calling Indenter"), processReturnString); |
561 } | 596 } |
562 | 597 |
563 | 598 |
564 // If the indenter returned an error code != 0 show its output. | 599 // If the indenter returned an error code != 0 show its output. |
565 if ( indentProcess.exitCode() != 0 ) { | 600 if ( indentProcess.exitCode() != 0 ) { |
571 "(STDERR):" + encodeToHTML( indentProcess.readAllStandardError() ) + "<br>" + | 606 "(STDERR):" + encodeToHTML( indentProcess.readAllStandardError() ) + "<br>" + |
572 tr("<br><b>Callstring was:</b> ") + encodeToHTML(indenterCompleteCallString) + | 607 tr("<br><b>Callstring was:</b> ") + encodeToHTML(indenterCompleteCallString) + |
573 "</html></body>"; | 608 "</html></body>"; |
574 qWarning() << __LINE__ << " " << __FUNCTION__ << processReturnString; | 609 qWarning() << __LINE__ << " " << __FUNCTION__ << processReturnString; |
575 QApplication::restoreOverrideCursor(); | 610 QApplication::restoreOverrideCursor(); |
576 errorMessageDialog->showMessage( tr("Indenter returned error"), processReturnString ); | 611 _errorMessageDialog->showMessage( tr("Indenter returned error"), processReturnString ); |
577 } | 612 } |
578 | 613 |
579 // Only get the formatted source code, if calling the indenter did succeed. | 614 // Only get the formatted source code, if calling the indenter did succeed. |
580 if ( calledProcessSuccessfully ) { | 615 if ( calledProcessSuccessfully ) { |
581 // If the indenter results are written to stdout, read them from there... | 616 // If the indenter results are written to stdout, read them from there... |
582 if ( indentProcess.exitCode() == 0 && outputFileParameter == "stdout" ) { | 617 if ( indentProcess.exitCode() == 0 && _outputFileParameter == "stdout" ) { |
583 formattedSourceCode = indentProcess.readAllStandardOutput(); | 618 formattedSourceCode = indentProcess.readAllStandardOutput(); |
584 qDebug() << __LINE__ << " " << __FUNCTION__ << ": Read indenter output from StdOut."; | 619 qDebug() << __LINE__ << " " << __FUNCTION__ << ": Read indenter output from StdOut."; |
585 } | 620 } |
586 // ... else read the output file generated by the indenter call. | 621 // ... else read the output file generated by the indenter call. |
587 else { | 622 else { |
588 QFile outSrcFile(tempDirctoryStr + "/" + outputFileName + inputFileExtension); | 623 QFile outSrcFile(_tempDirctoryStr + "/" + _outputFileName + inputFileExtension); |
589 if ( outSrcFile.open(QFile::ReadOnly | QFile::Text) ) { | 624 if ( outSrcFile.open(QFile::ReadOnly | QFile::Text) ) { |
590 QTextStream outSrcStrm(&outSrcFile); | 625 QTextStream outSrcStrm(&outSrcFile); |
591 outSrcStrm.setCodec( QTextCodec::codecForName("UTF-8") ); | 626 outSrcStrm.setCodec( QTextCodec::codecForName("UTF-8") ); |
592 formattedSourceCode = outSrcStrm.readAll(); | 627 formattedSourceCode = outSrcStrm.readAll(); |
593 outSrcFile.close(); | 628 outSrcFile.close(); |
601 else { | 636 else { |
602 return sourceCode; | 637 return sourceCode; |
603 } | 638 } |
604 | 639 |
605 // Delete the temporary input and output files. | 640 // Delete the temporary input and output files. |
606 QFile::remove(tempDirctoryStr + "/" + outputFileName + inputFileExtension); | 641 QFile::remove(_tempDirctoryStr + "/" + _outputFileName + inputFileExtension); |
607 QFile::remove(tempDirctoryStr + "/" + inputFileName + inputFileExtension); | 642 QFile::remove(_tempDirctoryStr + "/" + _inputFileName + inputFileExtension); |
608 | 643 |
609 return formattedSourceCode; | 644 return formattedSourceCode; |
610 } | 645 } |
611 | 646 |
612 | 647 |
615 */ | 650 */ |
616 QString IndentHandler::getParameterString() { | 651 QString IndentHandler::getParameterString() { |
617 QString parameterString = ""; | 652 QString parameterString = ""; |
618 | 653 |
619 // generate parameter string for all boolean values | 654 // generate parameter string for all boolean values |
620 foreach (ParamBoolean pBoolean, paramBooleans) { | 655 foreach (ParamBoolean pBoolean, _paramBooleans) { |
621 if ( pBoolean.checkBox->isChecked() ) { | 656 if ( pBoolean.checkBox->isChecked() ) { |
622 if ( !pBoolean.trueString.isEmpty() ) { | 657 if ( !pBoolean.trueString.isEmpty() ) { |
623 parameterString += pBoolean.trueString + cfgFileParameterEnding; | 658 parameterString += pBoolean.trueString + _cfgFileParameterEnding; |
624 } | 659 } |
625 } | 660 } |
626 else { | 661 else { |
627 if ( !pBoolean.falseString.isEmpty() ) { | 662 if ( !pBoolean.falseString.isEmpty() ) { |
628 parameterString += pBoolean.falseString + cfgFileParameterEnding; | 663 parameterString += pBoolean.falseString + _cfgFileParameterEnding; |
629 } | 664 } |
630 } | 665 } |
631 } | 666 } |
632 | 667 |
633 // generate parameter string for all numeric values | 668 // generate parameter string for all numeric values |
634 foreach (ParamNumeric pNumeric, paramNumerics) { | 669 foreach (ParamNumeric pNumeric, _paramNumerics) { |
635 if ( pNumeric.valueEnabledChkBox->isChecked() ) { | 670 if ( pNumeric.valueEnabledChkBox->isChecked() ) { |
636 parameterString += pNumeric.paramCallName + QString::number( pNumeric.spinBox->value() ) + cfgFileParameterEnding; | 671 parameterString += pNumeric.paramCallName + QString::number( pNumeric.spinBox->value() ) + _cfgFileParameterEnding; |
637 } | 672 } |
638 } | 673 } |
639 | 674 |
640 // generate parameter string for all string values | 675 // generate parameter string for all string values |
641 foreach (ParamString pString, paramStrings) { | 676 foreach (ParamString pString, _paramStrings) { |
642 if ( !pString.lineEdit->text().isEmpty() && pString.valueEnabledChkBox->isChecked() ) { | 677 if ( !pString.lineEdit->text().isEmpty() && pString.valueEnabledChkBox->isChecked() ) { |
643 // Create parameter definition for each value devided by a | sign. | 678 // Create parameter definition for each value devided by a | sign. |
644 foreach (QString paramValue, pString.lineEdit->text().split("|")) { | 679 foreach (QString paramValue, pString.lineEdit->text().split("|")) { |
645 parameterString += pString.paramCallName + paramValue + cfgFileParameterEnding; | 680 parameterString += pString.paramCallName + paramValue + _cfgFileParameterEnding; |
646 } | 681 } |
647 } | 682 } |
648 } | 683 } |
649 | 684 |
650 // generate parameter string for all multiple choice values | 685 // generate parameter string for all multiple choice values |
651 foreach (ParamMultiple pMultiple, paramMultiples) { | 686 foreach (ParamMultiple pMultiple, _paramMultiples) { |
652 if ( pMultiple.valueEnabledChkBox->isChecked() ) { | 687 if ( pMultiple.valueEnabledChkBox->isChecked() ) { |
653 parameterString += pMultiple.choicesStrings.at( pMultiple.comboBox->currentIndex () ) + cfgFileParameterEnding; | 688 parameterString += pMultiple.choicesStrings.at( pMultiple.comboBox->currentIndex () ) + _cfgFileParameterEnding; |
654 } | 689 } |
655 } | 690 } |
656 | 691 |
657 return parameterString; | 692 return parameterString; |
658 } | 693 } |
693 cfgFileData = cfgFile.readAll(); | 728 cfgFileData = cfgFile.readAll(); |
694 cfgFile.close(); | 729 cfgFile.close(); |
695 } | 730 } |
696 | 731 |
697 // Search for name of each boolean parameter and set its value if found. | 732 // Search for name of each boolean parameter and set its value if found. |
698 foreach (ParamBoolean pBoolean, paramBooleans) { | 733 foreach (ParamBoolean pBoolean, _paramBooleans) { |
699 // boolean value that will be assigned to the checkbox | 734 // boolean value that will be assigned to the checkbox |
700 bool paramValue = false; | 735 bool paramValue = false; |
701 | 736 |
702 // first search for the longer parameter string | 737 // first search for the longer parameter string |
703 // the true parameter string is longer than the false string | 738 // the true parameter string is longer than the false string |
715 if ( index != -1 ) { | 750 if ( index != -1 ) { |
716 paramValue = false; | 751 paramValue = false; |
717 } | 752 } |
718 // neither true nor false parameter found so use default value | 753 // neither true nor false parameter found so use default value |
719 else { | 754 else { |
720 paramValue = indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); | 755 paramValue = _indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); |
721 } | 756 } |
722 } | 757 } |
723 } | 758 } |
724 // the false parameter string is longer than the true string | 759 // the false parameter string is longer than the true string |
725 else { | 760 else { |
736 if ( index != -1 ) { | 771 if ( index != -1 ) { |
737 paramValue = true; | 772 paramValue = true; |
738 } | 773 } |
739 // neither true nor false parameter found so use default value | 774 // neither true nor false parameter found so use default value |
740 else { | 775 else { |
741 paramValue = indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); | 776 paramValue = _indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); |
742 } | 777 } |
743 } | 778 } |
744 } | 779 } |
745 pBoolean.checkBox->setChecked(paramValue); | 780 pBoolean.checkBox->setChecked(paramValue); |
746 } | 781 } |
747 | 782 |
748 // Search for name of each numeric parameter and set the value found behind it. | 783 // Search for name of each numeric parameter and set the value found behind it. |
749 foreach (ParamNumeric pNumeric, paramNumerics) { | 784 foreach (ParamNumeric pNumeric, _paramNumerics) { |
750 index = cfgFileData.indexOf( pNumeric.paramCallName, 0, Qt::CaseInsensitive ); | 785 index = cfgFileData.indexOf( pNumeric.paramCallName, 0, Qt::CaseInsensitive ); |
751 // parameter was found in config file | 786 // parameter was found in config file |
752 if ( index != -1 ) { | 787 if ( index != -1 ) { |
753 // set index after the parameter name, so in front of the number | 788 // set index after the parameter name, so in front of the number |
754 index += pNumeric.paramCallName.length(); | 789 index += pNumeric.paramCallName.length(); |
755 | 790 |
756 // Find the end of the parameter by searching for set config file parameter ending. Most of time this is a carriage return. | 791 // Find the end of the parameter by searching for set config file parameter ending. Most of time this is a carriage return. |
757 crPos = cfgFileData.indexOf( cfgFileParameterEnding, index+1 ); | 792 crPos = cfgFileData.indexOf( _cfgFileParameterEnding, index+1 ); |
758 | 793 |
759 // get the number and convert it to int | 794 // get the number and convert it to int |
760 QString test = cfgFileData.mid( index, crPos - index ); | 795 QString test = cfgFileData.mid( index, crPos - index ); |
761 paramValue = cfgFileData.mid( index, crPos - index ).toInt(NULL); | 796 paramValue = cfgFileData.mid( index, crPos - index ).toInt(NULL); |
762 | 797 |
766 pNumeric.valueEnabledChkBox->setChecked( true ); | 801 pNumeric.valueEnabledChkBox->setChecked( true ); |
767 QObject::connect(pNumeric.spinBox, SIGNAL(valueChanged(int)), this, SLOT(handleChangedIndenterSettings())); | 802 QObject::connect(pNumeric.spinBox, SIGNAL(valueChanged(int)), this, SLOT(handleChangedIndenterSettings())); |
768 } | 803 } |
769 // parameter was not found in config file | 804 // parameter was not found in config file |
770 else { | 805 else { |
771 int defaultValue = indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt(); | 806 int defaultValue = _indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt(); |
772 pNumeric.spinBox->setValue( defaultValue ); | 807 pNumeric.spinBox->setValue( defaultValue ); |
773 pNumeric.valueEnabledChkBox->setChecked( false ); | 808 pNumeric.valueEnabledChkBox->setChecked( false ); |
774 } | 809 } |
775 } | 810 } |
776 | 811 |
777 // Search for name of each string parameter and set it. | 812 // Search for name of each string parameter and set it. |
778 foreach (ParamString pString, paramStrings) { | 813 foreach (ParamString pString, _paramStrings) { |
779 paramValueStr = ""; | 814 paramValueStr = ""; |
780 // The number of the found values for this parameter name. | 815 // The number of the found values for this parameter name. |
781 int numberOfValues = 0; | 816 int numberOfValues = 0; |
782 index = cfgFileData.indexOf( pString.paramCallName, 0, Qt::CaseInsensitive ); | 817 index = cfgFileData.indexOf( pString.paramCallName, 0, Qt::CaseInsensitive ); |
783 // If parameter was found in config file | 818 // If parameter was found in config file |
787 | 822 |
788 // Set index after the parameter name, so it points to the front of the string value. | 823 // Set index after the parameter name, so it points to the front of the string value. |
789 index += pString.paramCallName.length(); | 824 index += pString.paramCallName.length(); |
790 | 825 |
791 // Find the end of the parameter by searching for set config file parameter ending. Most of time this is a carriage return. | 826 // Find the end of the parameter by searching for set config file parameter ending. Most of time this is a carriage return. |
792 crPos = cfgFileData.indexOf( cfgFileParameterEnding, index+1 ); | 827 crPos = cfgFileData.indexOf( _cfgFileParameterEnding, index+1 ); |
793 | 828 |
794 // Get the string and remember it. | 829 // Get the string and remember it. |
795 if ( numberOfValues < 2 ) { | 830 if ( numberOfValues < 2 ) { |
796 paramValueStr = QString( cfgFileData.mid( index, crPos - index ) ); | 831 paramValueStr = QString( cfgFileData.mid( index, crPos - index ) ); |
797 } | 832 } |
807 pString.lineEdit->setText( paramValueStr ); | 842 pString.lineEdit->setText( paramValueStr ); |
808 pString.valueEnabledChkBox->setChecked( true ); | 843 pString.valueEnabledChkBox->setChecked( true ); |
809 } | 844 } |
810 // Parameter was not found in config file | 845 // Parameter was not found in config file |
811 else { | 846 else { |
812 paramValueStr = indenterSettings->value(pString.paramName + "/ValueDefault").toString(); | 847 paramValueStr = _indenterSettings->value(pString.paramName + "/ValueDefault").toString(); |
813 pString.lineEdit->setText( paramValueStr ); | 848 pString.lineEdit->setText( paramValueStr ); |
814 pString.valueEnabledChkBox->setChecked( false ); | 849 pString.valueEnabledChkBox->setChecked( false ); |
815 } | 850 } |
816 } | 851 } |
817 | 852 |
818 // search for name of each multiple choice parameter and set it | 853 // search for name of each multiple choice parameter and set it |
819 foreach (ParamMultiple pMultiple, paramMultiples) { | 854 foreach (ParamMultiple pMultiple, _paramMultiples) { |
820 int i = 0; | 855 int i = 0; |
821 index = -1; | 856 index = -1; |
822 | 857 |
823 // search for all parameter names of the multiple choice list | 858 // search for all parameter names of the multiple choice list |
824 // if one is found, set it and leave the while loop | 859 // if one is found, set it and leave the while loop |
831 i++; | 866 i++; |
832 } | 867 } |
833 | 868 |
834 // parameter was not set in config file, so use default value | 869 // parameter was not set in config file, so use default value |
835 if ( index == -1 ) { | 870 if ( index == -1 ) { |
836 int defaultValue = indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt(); | 871 int defaultValue = _indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt(); |
837 pMultiple.comboBox->setCurrentIndex( defaultValue ); | 872 pMultiple.comboBox->setCurrentIndex( defaultValue ); |
838 pMultiple.valueEnabledChkBox->setChecked( false ); | 873 pMultiple.valueEnabledChkBox->setChecked( false ); |
839 } | 874 } |
840 } | 875 } |
841 | 876 |
846 /*! | 881 /*! |
847 \brief Sets all indenter parameters to their default values defined in the ini file. | 882 \brief Sets all indenter parameters to their default values defined in the ini file. |
848 */ | 883 */ |
849 void IndentHandler::resetToDefaultValues() { | 884 void IndentHandler::resetToDefaultValues() { |
850 // Search for name of each boolean parameter and set its value if found. | 885 // Search for name of each boolean parameter and set its value if found. |
851 foreach (ParamBoolean pBoolean, paramBooleans) { | 886 foreach (ParamBoolean pBoolean, _paramBooleans) { |
852 // Boolean value that will be assigned to the checkbox. | 887 // Boolean value that will be assigned to the checkbox. |
853 bool defaultValue = indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); | 888 bool defaultValue = _indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); |
854 pBoolean.checkBox->setChecked( defaultValue ); | 889 pBoolean.checkBox->setChecked( defaultValue ); |
855 } | 890 } |
856 | 891 |
857 // Search for name of each numeric parameter and set the value found behind it. | 892 // Search for name of each numeric parameter and set the value found behind it. |
858 foreach (ParamNumeric pNumeric, paramNumerics) { | 893 foreach (ParamNumeric pNumeric, _paramNumerics) { |
859 int defaultValue = indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt(); | 894 int defaultValue = _indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt(); |
860 pNumeric.spinBox->setValue( defaultValue ); | 895 pNumeric.spinBox->setValue( defaultValue ); |
861 pNumeric.valueEnabledChkBox->setChecked( indenterSettings->value(pNumeric.paramName + "/Enabled").toBool() ); | 896 pNumeric.valueEnabledChkBox->setChecked( _indenterSettings->value(pNumeric.paramName + "/Enabled").toBool() ); |
862 } | 897 } |
863 | 898 |
864 // Search for name of each string parameter and set it. | 899 // Search for name of each string parameter and set it. |
865 foreach (ParamString pString, paramStrings) { | 900 foreach (ParamString pString, _paramStrings) { |
866 QString defaultValue = indenterSettings->value(pString.paramName + "/ValueDefault").toString(); | 901 QString defaultValue = _indenterSettings->value(pString.paramName + "/ValueDefault").toString(); |
867 pString.lineEdit->setText( defaultValue ); | 902 pString.lineEdit->setText( defaultValue ); |
868 pString.valueEnabledChkBox->setChecked( indenterSettings->value(pString.paramName + "/Enabled").toBool() ); | 903 pString.valueEnabledChkBox->setChecked( _indenterSettings->value(pString.paramName + "/Enabled").toBool() ); |
869 } | 904 } |
870 | 905 |
871 // Search for name of each multiple choice parameter and set it. | 906 // Search for name of each multiple choice parameter and set it. |
872 foreach (ParamMultiple pMultiple, paramMultiples) { | 907 foreach (ParamMultiple pMultiple, _paramMultiples) { |
873 int defaultValue = indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt(); | 908 int defaultValue = _indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt(); |
874 pMultiple.comboBox->setCurrentIndex( defaultValue ); | 909 pMultiple.comboBox->setCurrentIndex( defaultValue ); |
875 pMultiple.valueEnabledChkBox->setChecked( indenterSettings->value(pMultiple.paramName + "/Enabled").toBool() ); | 910 pMultiple.valueEnabledChkBox->setChecked( _indenterSettings->value(pMultiple.paramName + "/Enabled").toBool() ); |
876 } | 911 } |
877 } | 912 } |
878 | 913 |
879 | 914 |
880 /*! | 915 /*! |
882 */ | 917 */ |
883 void IndentHandler::readIndentIniFile(QString iniFilePath) { | 918 void IndentHandler::readIndentIniFile(QString iniFilePath) { |
884 Q_ASSERT_X( !iniFilePath.isEmpty(), "readIndentIniFile", "iniFilePath is empty" ); | 919 Q_ASSERT_X( !iniFilePath.isEmpty(), "readIndentIniFile", "iniFilePath is empty" ); |
885 | 920 |
886 // open the ini-file that contains all available indenter settings with their additional infos | 921 // open the ini-file that contains all available indenter settings with their additional infos |
887 indenterSettings = new UiGuiIniFileParser(iniFilePath); | 922 _indenterSettings = new UiGuiIniFileParser(iniFilePath); |
888 | 923 |
889 QStringList categories; | 924 QStringList categories; |
890 //QString indenterGroupString = ""; | 925 //QString indenterGroupString = ""; |
891 QString paramToolTip = ""; | 926 QString paramToolTip = ""; |
892 | 927 |
893 | 928 |
894 // | 929 // |
895 // parse ini file indenter header | 930 // parse ini file indenter header |
896 // | 931 // |
897 | 932 |
898 indenterName = indenterSettings->value("header/indenterName").toString(); | 933 _indenterName = _indenterSettings->value("header/indenterName").toString(); |
899 indenterFileName = indenterSettings->value("header/indenterFileName").toString(); | 934 _indenterFileName = _indenterSettings->value("header/indenterFileName").toString(); |
900 globalConfigFilename_ = indenterSettings->value("header/configFilename").toString(); | 935 _globalConfigFilename = _indenterSettings->value("header/configFilename").toString(); |
901 useCfgFileParameter = indenterSettings->value("header/useCfgFileParameter").toString(); | 936 _useCfgFileParameter = _indenterSettings->value("header/useCfgFileParameter").toString(); |
902 cfgFileParameterEnding = indenterSettings->value("header/cfgFileParameterEnding").toString(); | 937 _cfgFileParameterEnding = _indenterSettings->value("header/cfgFileParameterEnding").toString(); |
903 if ( cfgFileParameterEnding == "cr" ) { | 938 if ( _cfgFileParameterEnding == "cr" ) { |
904 cfgFileParameterEnding = "\n"; | 939 _cfgFileParameterEnding = "\n"; |
905 } | 940 } |
906 indenterShowHelpParameter = indenterSettings->value("header/showHelpParameter").toString(); | 941 _indenterShowHelpParameter = _indenterSettings->value("header/showHelpParameter").toString(); |
907 | 942 |
908 if ( indenterFileName.isEmpty() ) { | 943 if ( _indenterFileName.isEmpty() ) { |
909 errorMessageDialog->showMessage( tr("Indenter ini file header error"), | 944 _errorMessageDialog->showMessage( tr("Indenter ini file header error"), |
910 tr("The loaded indenter ini file \"%1\"has a faulty header. At least the indenters file name is not set.").arg(iniFilePath) ); | 945 tr("The loaded indenter ini file \"%1\"has a faulty header. At least the indenters file name is not set.").arg(iniFilePath) ); |
911 } | 946 } |
912 | 947 |
913 // Read the parameter order. Possible values are (p=parameter[file] i=inputfile o=outputfile) | 948 // Read the parameter order. Possible values are (p=parameter[file] i=inputfile o=outputfile) |
914 // pio, ipo, iop | 949 // pio, ipo, iop |
915 parameterOrder = indenterSettings->value("header/parameterOrder", "pio").toString(); | 950 _parameterOrder = _indenterSettings->value("header/parameterOrder", "pio").toString(); |
916 inputFileParameter = indenterSettings->value("header/inputFileParameter").toString(); | 951 _inputFileParameter = _indenterSettings->value("header/inputFileParameter").toString(); |
917 inputFileName = indenterSettings->value("header/inputFileName").toString(); | 952 _inputFileName = _indenterSettings->value("header/inputFileName").toString(); |
918 outputFileParameter = indenterSettings->value("header/outputFileParameter").toString(); | 953 _outputFileParameter = _indenterSettings->value("header/outputFileParameter").toString(); |
919 outputFileName = indenterSettings->value("header/outputFileName").toString(); | 954 _outputFileName = _indenterSettings->value("header/outputFileName").toString(); |
920 fileTypes = indenterSettings->value("header/fileTypes").toString(); | 955 _fileTypes = _indenterSettings->value("header/fileTypes").toString(); |
921 fileTypes.replace('|', " "); | 956 _fileTypes.replace('|', " "); |
922 | 957 |
923 // read the categories names which are separated by "|" | 958 // read the categories names which are separated by "|" |
924 QString categoriesStr = indenterSettings->value("header/categories").toString(); | 959 QString categoriesStr = _indenterSettings->value("header/categories").toString(); |
925 categories = categoriesStr.split("|"); | 960 categories = categoriesStr.split("|"); |
926 // Assure that the category list is never empty. At least contain a "general" section. | 961 // Assure that the category list is never empty. At least contain a "general" section. |
927 if ( categories.isEmpty() ) { | 962 if ( categories.isEmpty() ) { |
928 categories.append("General"); | 963 categories.append("General"); |
929 } | 964 } |
930 | 965 |
931 ToolBoxPage toolBoxPage; | 966 IndenterParameterCategoryPage categoryPage; |
932 | 967 |
933 // create a page for each category and store its references in a toolboxpage-array | 968 // create a page for each category and store its references in a toolboxpage-array |
934 foreach (QString category, categories) { | 969 foreach (QString category, categories) { |
935 toolBoxPage.page = new QWidget(); | 970 categoryPage.widget = new QWidget(); |
936 toolBoxPage.page->setObjectName(category); | 971 categoryPage.widget->setObjectName(category); |
937 toolBoxPage.page->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); | 972 categoryPage.widget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
938 toolBoxPage.vboxLayout = new QVBoxLayout(toolBoxPage.page); | 973 categoryPage.vboxLayout = new QVBoxLayout(categoryPage.widget); |
939 toolBoxPage.vboxLayout->setSpacing(6); | 974 categoryPage.vboxLayout->setSpacing(6); |
940 toolBoxPage.vboxLayout->setMargin(9); | 975 categoryPage.vboxLayout->setMargin(9); |
941 toolBoxPage.vboxLayout->setObjectName(category); | 976 categoryPage.vboxLayout->setObjectName(category); |
942 toolBoxPages.append(toolBoxPage); | 977 _indenterParameterCategoryPages.append(categoryPage); |
943 toolBox->addItem(toolBoxPage.page, category); | 978 _indenterParameterCategoriesToolBox->addItem(categoryPage.widget, category); |
944 } | 979 } |
945 | 980 |
946 | 981 |
947 // | 982 // |
948 // parse ini file indenter parameters | 983 // parse ini file indenter parameters |
949 // | 984 // |
950 | 985 |
951 // read all possible parameters written in brackets [] | 986 // read all possible parameters written in brackets [] |
952 indenterParameters = indenterSettings->childGroups(); | 987 _indenterParameters = _indenterSettings->childGroups(); |
953 | 988 |
954 // read each parameter to create the corresponding input field | 989 // read each parameter to create the corresponding input field |
955 foreach (QString indenterParameter, indenterParameters) { | 990 foreach (QString indenterParameter, _indenterParameters) { |
956 // if it is not the indent header definition read the parameter and add it to | 991 // if it is not the indent header definition read the parameter and add it to |
957 // the corresponding category toolbox page | 992 // the corresponding category toolbox page |
958 if ( indenterParameter != "header") { | 993 if ( indenterParameter != "header") { |
959 // read to which category the parameter belongs | 994 // read to which category the parameter belongs |
960 int category = indenterSettings->value(indenterParameter + "/Category").toInt(); | 995 int category = _indenterSettings->value(indenterParameter + "/Category").toInt(); |
961 // Assure that the category number is never greater than the available categories. | 996 // Assure that the category number is never greater than the available categories. |
962 if ( category > toolBoxPages.size()-1 ) { | 997 if ( category > _indenterParameterCategoryPages.size()-1 ) { |
963 category = toolBoxPages.size()-1; | 998 category = _indenterParameterCategoryPages.size()-1; |
964 } | 999 } |
965 // read which type of input field the parameter needs | 1000 // read which type of input field the parameter needs |
966 QString editType = indenterSettings->value(indenterParameter + "/EditorType").toString(); | 1001 QString editType = _indenterSettings->value(indenterParameter + "/EditorType").toString(); |
967 | 1002 |
968 // edit type is numeric so create a spinbox with label | 1003 // edit type is numeric so create a spinbox with label |
969 if ( editType == "numeric" ) { | 1004 if ( editType == "numeric" ) { |
970 // read the parameter name as it is used at the command line or in its config file | 1005 // read the parameter name as it is used at the command line or in its config file |
971 QString parameterCallName = indenterSettings->value(indenterParameter + "/CallName").toString(); | 1006 QString parameterCallName = _indenterSettings->value(indenterParameter + "/CallName").toString(); |
972 | 1007 |
973 // create checkbox which enables or disables the parameter | 1008 // create checkbox which enables or disables the parameter |
974 QCheckBox *chkBox = new QCheckBox( toolBoxPages.at(category).page ); | 1009 QCheckBox *chkBox = new QCheckBox( _indenterParameterCategoryPages.at(category).widget ); |
975 chkBox->setChecked( indenterSettings->value(indenterParameter + "/Enabled").toBool() ); | 1010 chkBox->setChecked( _indenterSettings->value(indenterParameter + "/Enabled").toBool() ); |
976 chkBox->setToolTip( "Enables/disables the parameter. If disabled the indenters default value will be used." ); | 1011 chkBox->setToolTip( "Enables/disables the parameter. If disabled the indenters default value will be used." ); |
977 chkBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); | 1012 chkBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); |
978 int left, top, right, bottom; | 1013 int left, top, right, bottom; |
979 chkBox->getContentsMargins( &left, &top, &right, &bottom ); | 1014 chkBox->getContentsMargins( &left, &top, &right, &bottom ); |
980 chkBox->setContentsMargins( left, top, 0, bottom ); | 1015 chkBox->setContentsMargins( left, top, 0, bottom ); |
981 | 1016 |
982 // create the spinbox | 1017 // create the spinbox |
983 QSpinBox *spinBox = new QSpinBox( toolBoxPages.at(category).page ); | 1018 QSpinBox *spinBox = new QSpinBox( _indenterParameterCategoryPages.at(category).widget ); |
984 paramToolTip = indenterSettings->value(indenterParameter + "/Description").toString(); | 1019 paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); |
985 spinBox->setToolTip( paramToolTip ); | 1020 spinBox->setToolTip( paramToolTip ); |
986 spinBox->setMaximumWidth(50); | 1021 spinBox->setMaximumWidth(50); |
987 spinBox->setMinimumWidth(50); | 1022 spinBox->setMinimumWidth(50); |
988 if ( mainWindow != NULL ) { | 1023 if ( _mainWindow != NULL ) { |
989 spinBox->installEventFilter( mainWindow ); | 1024 spinBox->installEventFilter( _mainWindow ); |
990 } | 1025 } |
991 if ( indenterSettings->value(indenterParameter + "/MinVal").toString() != "" ) { | 1026 if ( _indenterSettings->value(indenterParameter + "/MinVal").toString() != "" ) { |
992 spinBox->setMinimum( indenterSettings->value(indenterParameter + "/MinVal").toInt() ); | 1027 spinBox->setMinimum( _indenterSettings->value(indenterParameter + "/MinVal").toInt() ); |
993 } | 1028 } |
994 else { | 1029 else { |
995 spinBox->setMinimum( 0 ); | 1030 spinBox->setMinimum( 0 ); |
996 } | 1031 } |
997 if ( indenterSettings->value(indenterParameter + "/MaxVal").toString() != "" ) { | 1032 if ( _indenterSettings->value(indenterParameter + "/MaxVal").toString() != "" ) { |
998 spinBox->setMaximum( indenterSettings->value(indenterParameter + "/MaxVal").toInt() ); | 1033 spinBox->setMaximum( _indenterSettings->value(indenterParameter + "/MaxVal").toInt() ); |
999 } | 1034 } |
1000 else { | 1035 else { |
1001 spinBox->setMaximum( 2000 ); | 1036 spinBox->setMaximum( 2000 ); |
1002 } | 1037 } |
1003 | 1038 |
1004 // create the label | 1039 // create the label |
1005 QLabel *label = new QLabel( toolBoxPages.at(category).page ); | 1040 QLabel *label = new QLabel( _indenterParameterCategoryPages.at(category).widget ); |
1006 label->setText(indenterParameter); | 1041 label->setText(indenterParameter); |
1007 label->setBuddy(spinBox); | 1042 label->setBuddy(spinBox); |
1008 label->setToolTip( paramToolTip ); | 1043 label->setToolTip( paramToolTip ); |
1009 if ( mainWindow != NULL ) { | 1044 if ( _mainWindow != NULL ) { |
1010 label->installEventFilter( mainWindow ); | 1045 label->installEventFilter( _mainWindow ); |
1011 } | 1046 } |
1012 | 1047 |
1013 // put all into a layout and add it to the toolbox page | 1048 // put all into a layout and add it to the toolbox page |
1014 QHBoxLayout *hboxLayout = new QHBoxLayout(); | 1049 QHBoxLayout *hboxLayout = new QHBoxLayout(); |
1015 hboxLayout->addWidget(chkBox); | 1050 hboxLayout->addWidget(chkBox); |
1016 hboxLayout->addWidget(spinBox); | 1051 hboxLayout->addWidget(spinBox); |
1017 hboxLayout->addWidget(label); | 1052 hboxLayout->addWidget(label); |
1018 toolBoxPages.at(category).vboxLayout->addLayout(hboxLayout); | 1053 _indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout); |
1019 | 1054 |
1020 // remember parameter name and reference to its spinbox | 1055 // remember parameter name and reference to its spinbox |
1021 ParamNumeric paramNumeric; | 1056 ParamNumeric paramNumeric; |
1022 paramNumeric.paramName = indenterParameter; | 1057 paramNumeric.paramName = indenterParameter; |
1023 paramNumeric.paramCallName = parameterCallName; | 1058 paramNumeric.paramCallName = parameterCallName; |
1024 paramNumeric.spinBox = spinBox; | 1059 paramNumeric.spinBox = spinBox; |
1025 paramNumeric.label = label; | 1060 paramNumeric.label = label; |
1026 paramNumeric.valueEnabledChkBox = chkBox; | 1061 paramNumeric.valueEnabledChkBox = chkBox; |
1027 paramNumeric.spinBox->setValue( indenterSettings->value(paramNumeric.paramName + "/ValueDefault").toInt() ); | 1062 paramNumeric.spinBox->setValue( _indenterSettings->value(paramNumeric.paramName + "/ValueDefault").toInt() ); |
1028 paramNumerics.append(paramNumeric); | 1063 _paramNumerics.append(paramNumeric); |
1029 | 1064 |
1030 QObject::connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(handleChangedIndenterSettings())); | 1065 QObject::connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(handleChangedIndenterSettings())); |
1031 QObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); | 1066 QObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); |
1032 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS | 1067 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS |
1033 connect( spinBox, SIGNAL(valueChanged(int)), this, SLOT(updateDrawing()) ); | 1068 connect( spinBox, SIGNAL(valueChanged(int)), this, SLOT(updateDrawing()) ); |
1034 #endif // UNIVERSALINDENTGUI_NPP_EXPORTS | 1069 #endif // UNIVERSALINDENTGUI_NPP_EXPORTS |
1035 } | 1070 } |
1036 // edit type is boolean so create a checkbox | 1071 // edit type is boolean so create a checkbox |
1037 else if ( editType == "boolean" ) { | 1072 else if ( editType == "boolean" ) { |
1038 // create the checkbox, make its settings and add it to the toolbox page | 1073 // create the checkbox, make its settings and add it to the toolbox page |
1039 QCheckBox *chkBox = new QCheckBox( toolBoxPages.at(category).page ); | 1074 QCheckBox *chkBox = new QCheckBox( _indenterParameterCategoryPages.at(category).widget ); |
1040 chkBox->setText(indenterParameter); | 1075 chkBox->setText(indenterParameter); |
1041 paramToolTip = indenterSettings->value(indenterParameter + "/Description").toString(); | 1076 paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); |
1042 chkBox->setToolTip( paramToolTip ); | 1077 chkBox->setToolTip( paramToolTip ); |
1043 if ( mainWindow != NULL ) { | 1078 if ( _mainWindow != NULL ) { |
1044 chkBox->installEventFilter( mainWindow ); | 1079 chkBox->installEventFilter( _mainWindow ); |
1045 } | 1080 } |
1046 toolBoxPages.at(category).vboxLayout->addWidget(chkBox); | 1081 _indenterParameterCategoryPages.at(category).vboxLayout->addWidget(chkBox); |
1047 | 1082 |
1048 // remember parameter name and reference to its checkbox | 1083 // remember parameter name and reference to its checkbox |
1049 ParamBoolean paramBoolean; | 1084 ParamBoolean paramBoolean; |
1050 paramBoolean.paramName = indenterParameter; | 1085 paramBoolean.paramName = indenterParameter; |
1051 paramBoolean.checkBox = chkBox; | 1086 paramBoolean.checkBox = chkBox; |
1052 QStringList trueFalseStrings = indenterSettings->value(indenterParameter + "/TrueFalse").toString().split("|"); | 1087 QStringList trueFalseStrings = _indenterSettings->value(indenterParameter + "/TrueFalse").toString().split("|"); |
1053 paramBoolean.trueString = trueFalseStrings.at(0); | 1088 paramBoolean.trueString = trueFalseStrings.at(0); |
1054 paramBoolean.falseString = trueFalseStrings.at(1); | 1089 paramBoolean.falseString = trueFalseStrings.at(1); |
1055 paramBoolean.checkBox->setChecked( indenterSettings->value(paramBoolean.paramName + "/ValueDefault").toBool() ); | 1090 paramBoolean.checkBox->setChecked( _indenterSettings->value(paramBoolean.paramName + "/ValueDefault").toBool() ); |
1056 paramBooleans.append(paramBoolean); | 1091 _paramBooleans.append(paramBoolean); |
1057 | 1092 |
1058 QObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); | 1093 QObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); |
1059 } | 1094 } |
1060 // edit type is numeric so create a line edit with label | 1095 // edit type is numeric so create a line edit with label |
1061 else if ( editType == "string" ) { | 1096 else if ( editType == "string" ) { |
1062 // read the parameter name as it is used at the command line or in its config file | 1097 // read the parameter name as it is used at the command line or in its config file |
1063 QString parameterCallName = indenterSettings->value(indenterParameter + "/CallName").toString(); | 1098 QString parameterCallName = _indenterSettings->value(indenterParameter + "/CallName").toString(); |
1064 | 1099 |
1065 // create check box which enables or disables the parameter | 1100 // create check box which enables or disables the parameter |
1066 QCheckBox *chkBox = new QCheckBox( toolBoxPages.at(category).page ); | 1101 QCheckBox *chkBox = new QCheckBox( _indenterParameterCategoryPages.at(category).widget ); |
1067 chkBox->setChecked( indenterSettings->value(indenterParameter + "/Enabled").toBool() ); | 1102 chkBox->setChecked( _indenterSettings->value(indenterParameter + "/Enabled").toBool() ); |
1068 chkBox->setToolTip( "Enables/disables the parameter. If disabled the indenters default value will be used." ); | 1103 chkBox->setToolTip( "Enables/disables the parameter. If disabled the indenters default value will be used." ); |
1069 chkBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); | 1104 chkBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); |
1070 int left, top, right, bottom; | 1105 int left, top, right, bottom; |
1071 chkBox->getContentsMargins( &left, &top, &right, &bottom ); | 1106 chkBox->getContentsMargins( &left, &top, &right, &bottom ); |
1072 chkBox->setContentsMargins( left, top, 0, bottom ); | 1107 chkBox->setContentsMargins( left, top, 0, bottom ); |
1073 | 1108 |
1074 // create the line edit | 1109 // create the line edit |
1075 QLineEdit *lineEdit = new QLineEdit( toolBoxPages.at(category).page ); | 1110 QLineEdit *lineEdit = new QLineEdit( _indenterParameterCategoryPages.at(category).widget ); |
1076 paramToolTip = indenterSettings->value(indenterParameter + "/Description").toString(); | 1111 paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); |
1077 lineEdit->setToolTip( paramToolTip ); | 1112 lineEdit->setToolTip( paramToolTip ); |
1078 lineEdit->setMaximumWidth(50); | 1113 lineEdit->setMaximumWidth(50); |
1079 lineEdit->setMinimumWidth(50); | 1114 lineEdit->setMinimumWidth(50); |
1080 if ( mainWindow != NULL ) { | 1115 if ( _mainWindow != NULL ) { |
1081 lineEdit->installEventFilter( mainWindow ); | 1116 lineEdit->installEventFilter( _mainWindow ); |
1082 } | 1117 } |
1083 | 1118 |
1084 // create the label | 1119 // create the label |
1085 QLabel *label = new QLabel( toolBoxPages.at(category).page ); | 1120 QLabel *label = new QLabel( _indenterParameterCategoryPages.at(category).widget ); |
1086 label->setText(indenterParameter); | 1121 label->setText(indenterParameter); |
1087 label->setBuddy(lineEdit); | 1122 label->setBuddy(lineEdit); |
1088 label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); | 1123 label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); |
1089 label->setToolTip( paramToolTip ); | 1124 label->setToolTip( paramToolTip ); |
1090 if ( mainWindow != NULL ) { | 1125 if ( _mainWindow != NULL ) { |
1091 label->installEventFilter( mainWindow ); | 1126 label->installEventFilter( _mainWindow ); |
1092 } | 1127 } |
1093 | 1128 |
1094 // put all into a layout and add it to the toolbox page | 1129 // put all into a layout and add it to the toolbox page |
1095 QHBoxLayout *hboxLayout = new QHBoxLayout(); | 1130 QHBoxLayout *hboxLayout = new QHBoxLayout(); |
1096 hboxLayout->addWidget(chkBox); | 1131 hboxLayout->addWidget(chkBox); |
1097 hboxLayout->addWidget(lineEdit); | 1132 hboxLayout->addWidget(lineEdit); |
1098 hboxLayout->addWidget(label); | 1133 hboxLayout->addWidget(label); |
1099 toolBoxPages.at(category).vboxLayout->addLayout(hboxLayout); | 1134 _indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout); |
1100 | 1135 |
1101 // remember parameter name and reference to its line edit | 1136 // remember parameter name and reference to its line edit |
1102 ParamString paramString; | 1137 ParamString paramString; |
1103 paramString.paramName = indenterParameter; | 1138 paramString.paramName = indenterParameter; |
1104 paramString.paramCallName = parameterCallName; | 1139 paramString.paramCallName = parameterCallName; |
1105 paramString.lineEdit = lineEdit; | 1140 paramString.lineEdit = lineEdit; |
1106 paramString.label = label; | 1141 paramString.label = label; |
1107 paramString.valueEnabledChkBox = chkBox; | 1142 paramString.valueEnabledChkBox = chkBox; |
1108 paramString.lineEdit->setText( indenterSettings->value(paramString.paramName + "/ValueDefault").toString() ); | 1143 paramString.lineEdit->setText( _indenterSettings->value(paramString.paramName + "/ValueDefault").toString() ); |
1109 paramStrings.append(paramString); | 1144 _paramStrings.append(paramString); |
1110 | 1145 |
1111 QObject::connect(lineEdit, SIGNAL(editingFinished()), this, SLOT(handleChangedIndenterSettings())); | 1146 QObject::connect(lineEdit, SIGNAL(editingFinished()), this, SLOT(handleChangedIndenterSettings())); |
1112 QObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); | 1147 QObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); |
1113 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS | 1148 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS |
1114 connect( lineEdit, SIGNAL(textChanged(const QString)), this, SLOT(updateDrawing()) ); | 1149 connect( lineEdit, SIGNAL(textChanged(const QString)), this, SLOT(updateDrawing()) ); |
1115 #endif // UNIVERSALINDENTGUI_NPP_EXPORTS | 1150 #endif // UNIVERSALINDENTGUI_NPP_EXPORTS |
1116 } | 1151 } |
1117 // edit type is multiple so create a combobox with label | 1152 // edit type is multiple so create a combobox with label |
1118 else if ( editType == "multiple" ) { | 1153 else if ( editType == "multiple" ) { |
1119 // read the parameter name as it is used at the command line or in its config file | 1154 // read the parameter name as it is used at the command line or in its config file |
1120 QString parameterCallName = indenterSettings->value(indenterParameter + "/CallName").toString(); | 1155 QString parameterCallName = _indenterSettings->value(indenterParameter + "/CallName").toString(); |
1121 | 1156 |
1122 // create checkbox which enables or disables the parameter | 1157 // create checkbox which enables or disables the parameter |
1123 QCheckBox *chkBox = new QCheckBox( toolBoxPages.at(category).page ); | 1158 QCheckBox *chkBox = new QCheckBox( _indenterParameterCategoryPages.at(category).widget ); |
1124 chkBox->setChecked( indenterSettings->value(indenterParameter + "/Enabled").toBool() ); | 1159 chkBox->setChecked( _indenterSettings->value(indenterParameter + "/Enabled").toBool() ); |
1125 chkBox->setToolTip( "Enables/disables the parameter. If disabled the indenters default value will be used." ); | 1160 chkBox->setToolTip( "Enables/disables the parameter. If disabled the indenters default value will be used." ); |
1126 chkBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); | 1161 chkBox->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); |
1127 int left, top, right, bottom; | 1162 int left, top, right, bottom; |
1128 chkBox->getContentsMargins( &left, &top, &right, &bottom ); | 1163 chkBox->getContentsMargins( &left, &top, &right, &bottom ); |
1129 chkBox->setContentsMargins( left, top, 0, bottom ); | 1164 chkBox->setContentsMargins( left, top, 0, bottom ); |
1130 | 1165 |
1131 // create the combo box | 1166 // create the combo box |
1132 QComboBox *comboBox = new QComboBox( toolBoxPages.at(category).page ); | 1167 QComboBox *comboBox = new QComboBox( _indenterParameterCategoryPages.at(category).widget ); |
1133 QStringList choicesStrings = indenterSettings->value(indenterParameter + "/Choices").toString().split("|"); | 1168 QStringList choicesStrings = _indenterSettings->value(indenterParameter + "/Choices").toString().split("|"); |
1134 QStringList choicesStringsReadable = indenterSettings->value(indenterParameter + "/ChoicesReadable").toString().split("|", QString::SkipEmptyParts); | 1169 QStringList choicesStringsReadable = _indenterSettings->value(indenterParameter + "/ChoicesReadable").toString().split("|", QString::SkipEmptyParts); |
1135 if ( choicesStringsReadable.isEmpty() ) { | 1170 if ( choicesStringsReadable.isEmpty() ) { |
1136 comboBox->addItems( choicesStrings ); | 1171 comboBox->addItems( choicesStrings ); |
1137 } | 1172 } |
1138 else { | 1173 else { |
1139 comboBox->addItems( choicesStringsReadable ); | 1174 comboBox->addItems( choicesStringsReadable ); |
1140 } | 1175 } |
1141 paramToolTip = indenterSettings->value(indenterParameter + "/Description").toString(); | 1176 paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); |
1142 comboBox->setToolTip( paramToolTip ); | 1177 comboBox->setToolTip( paramToolTip ); |
1143 if ( mainWindow != NULL ) { | 1178 if ( _mainWindow != NULL ) { |
1144 comboBox->installEventFilter( mainWindow ); | 1179 comboBox->installEventFilter( _mainWindow ); |
1145 } | 1180 } |
1146 | 1181 |
1147 // put all into a layout and add it to the toolbox page | 1182 // put all into a layout and add it to the toolbox page |
1148 QHBoxLayout *hboxLayout = new QHBoxLayout(); | 1183 QHBoxLayout *hboxLayout = new QHBoxLayout(); |
1149 hboxLayout->addWidget(chkBox); | 1184 hboxLayout->addWidget(chkBox); |
1150 hboxLayout->addWidget(comboBox); | 1185 hboxLayout->addWidget(comboBox); |
1151 toolBoxPages.at(category).vboxLayout->addLayout(hboxLayout); | 1186 _indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout); |
1152 | 1187 |
1153 // remember parameter name and reference to its lineedit | 1188 // remember parameter name and reference to its lineedit |
1154 ParamMultiple paramMultiple; | 1189 ParamMultiple paramMultiple; |
1155 paramMultiple.paramName = indenterParameter; | 1190 paramMultiple.paramName = indenterParameter; |
1156 paramMultiple.paramCallName = parameterCallName; | 1191 paramMultiple.paramCallName = parameterCallName; |
1157 paramMultiple.comboBox = comboBox; | 1192 paramMultiple.comboBox = comboBox; |
1158 paramMultiple.choicesStrings = choicesStrings; | 1193 paramMultiple.choicesStrings = choicesStrings; |
1159 paramMultiple.choicesStringsReadable = choicesStringsReadable; | 1194 paramMultiple.choicesStringsReadable = choicesStringsReadable; |
1160 paramMultiple.valueEnabledChkBox = chkBox; | 1195 paramMultiple.valueEnabledChkBox = chkBox; |
1161 paramMultiple.comboBox->setCurrentIndex( indenterSettings->value(paramMultiple.paramName + "/ValueDefault").toInt() ); | 1196 paramMultiple.comboBox->setCurrentIndex( _indenterSettings->value(paramMultiple.paramName + "/ValueDefault").toInt() ); |
1162 paramMultiples.append(paramMultiple); | 1197 _paramMultiples.append(paramMultiple); |
1163 | 1198 |
1164 QObject::connect(comboBox, SIGNAL(activated(int)), this, SLOT(handleChangedIndenterSettings())); | 1199 QObject::connect(comboBox, SIGNAL(activated(int)), this, SLOT(handleChangedIndenterSettings())); |
1165 QObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); | 1200 QObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); |
1166 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS | 1201 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS |
1167 connect( comboBox, SIGNAL(activated(int)), this, SLOT(updateDrawing()) ); | 1202 connect( comboBox, SIGNAL(activated(int)), this, SLOT(updateDrawing()) ); |
1169 } | 1204 } |
1170 } | 1205 } |
1171 } | 1206 } |
1172 | 1207 |
1173 // put a spacer at each page end | 1208 // put a spacer at each page end |
1174 foreach (ToolBoxPage tbp, toolBoxPages) { | 1209 foreach (IndenterParameterCategoryPage categoryPage, _indenterParameterCategoryPages) { |
1175 tbp.vboxLayout->addStretch(); | 1210 categoryPage.vboxLayout->addStretch(); |
1176 } | 1211 } |
1177 } | 1212 } |
1178 | 1213 |
1179 | 1214 |
1180 /*! | 1215 /*! |
1181 \brief Searches and returns all indenters a configuration file is found for. | 1216 \brief Searches and returns all indenters a configuration file is found for. |
1182 | 1217 |
1183 Opens all uigui ini files found in the list \a indenterIniFileList, opens each ini file | 1218 Opens all uigui ini files found in the list \a _indenterIniFileList, opens each ini file |
1184 and reads the there defined real name of the indenter. These names are being returned as QStringList. | 1219 and reads the there defined real name of the indenter. These names are being returned as QStringList. |
1185 */ | 1220 */ |
1186 QStringList IndentHandler::getAvailableIndenters() { | 1221 QStringList IndentHandler::getAvailableIndenters() { |
1187 QStringList indenterNamesList; | 1222 QStringList indenterNamesList; |
1188 | 1223 |
1189 // Loop for every existing uigui ini file | 1224 // Loop for every existing uigui ini file |
1190 foreach (QString indenterIniFile, indenterIniFileList) { | 1225 foreach (QString indenterIniFile, _indenterIniFileList) { |
1191 // Open the ini file and search for the indenter name | 1226 // Open the ini file and search for the indenter name |
1192 QFile file(indenterDirctoryStr + "/" + indenterIniFile); | 1227 QFile file(_indenterDirctoryStr + "/" + indenterIniFile); |
1193 if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) { | 1228 if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) { |
1194 int index = -1; | 1229 int index = -1; |
1195 QByteArray line; | 1230 QByteArray line; |
1196 // Search for the string "indenterName=" and get the following string until line end. | 1231 // Search for the string "indenterName=" and get the following string until line end. |
1197 while ( index == -1 && !file.atEnd() ) { | 1232 while ( index == -1 && !file.atEnd() ) { |
1214 */ | 1249 */ |
1215 void IndentHandler::setIndenter(int indenterID) { | 1250 void IndentHandler::setIndenter(int indenterID) { |
1216 QApplication::setOverrideCursor(Qt::WaitCursor); | 1251 QApplication::setOverrideCursor(Qt::WaitCursor); |
1217 | 1252 |
1218 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS | 1253 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS |
1219 disconnect( toolBox, SIGNAL(currentChanged(int)), this, SLOT(updateDrawing()) ); | 1254 disconnect( _indenterParameterCategoriesToolBox, SIGNAL(currentChanged(int)), this, SLOT(updateDrawing()) ); |
1220 #endif // UNIVERSALINDENTGUI_NPP_EXPORTS | 1255 #endif // UNIVERSALINDENTGUI_NPP_EXPORTS |
1221 | 1256 |
1222 // Generate the parameter string that will be saved to the indenters config file. | 1257 // Generate the parameter string that will be saved to the indenters config file. |
1223 QString parameterString = getParameterString(); | 1258 QString parameterString = getParameterString(); |
1224 if ( !indenterFileName.isEmpty() ) { | 1259 if ( !_indenterFileName.isEmpty() ) { |
1225 saveConfigFile( settingsDirctoryStr + "/" + indenterFileName + ".cfg", parameterString ); | 1260 saveConfigFile( _settingsDirctoryStr + "/" + _indenterFileName + ".cfg", parameterString ); |
1226 } | 1261 } |
1227 | 1262 |
1228 // Take care if the selected indenterID is smaller or greater than the number of existing indenters | 1263 // Take care if the selected indenterID is smaller or greater than the number of existing indenters |
1229 if ( indenterID < 0 ) { | 1264 if ( indenterID < 0 ) { |
1230 indenterID = 0; | 1265 indenterID = 0; |
1231 } | 1266 } |
1232 if ( indenterID >= indenterIniFileList.count() ) { | 1267 if ( indenterID >= _indenterIniFileList.count() ) { |
1233 indenterID = indenterIniFileList.count() - 1; | 1268 indenterID = _indenterIniFileList.count() - 1; |
1234 } | 1269 } |
1235 | 1270 |
1236 // remove all pages from the toolbox | 1271 // remove all pages from the toolbox |
1237 for (int i = 0; i < toolBox->count(); i++) { | 1272 for (int i = 0; i < _indenterParameterCategoriesToolBox->count(); i++) { |
1238 toolBox->removeItem(i); | 1273 _indenterParameterCategoriesToolBox->removeItem(i); |
1239 } | 1274 } |
1240 | 1275 |
1241 // delete all toolbox pages and by this its children | 1276 // delete all toolbox pages and by this its children |
1242 foreach (ToolBoxPage toolBoxPage, toolBoxPages) { | 1277 foreach (IndenterParameterCategoryPage categoryPage, _indenterParameterCategoryPages) { |
1243 delete toolBoxPage.page; | 1278 delete categoryPage.widget; |
1244 } | 1279 } |
1245 | 1280 |
1246 // empty all lists, which stored infos for the toolbox pages and its widgets | 1281 // empty all lists, which stored infos for the toolbox pages and its widgets |
1247 toolBoxPages.clear(); | 1282 _indenterParameterCategoryPages.clear(); |
1248 paramStrings.clear(); | 1283 _paramStrings.clear(); |
1249 paramNumerics.clear(); | 1284 _paramNumerics.clear(); |
1250 paramBooleans.clear(); | 1285 _paramBooleans.clear(); |
1251 paramMultiples.clear(); | 1286 _paramMultiples.clear(); |
1252 delete indenterSettings; | 1287 delete _indenterSettings; |
1253 | 1288 |
1254 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS | 1289 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS |
1255 QWidget dummyWidget; | 1290 QWidget dummyWidget; |
1256 toolBox->addItem(&dummyWidget, "dummyText"); | 1291 _indenterParameterCategoriesToolBox->addItem(&dummyWidget, "dummyText"); |
1257 #endif | 1292 #endif |
1258 | 1293 |
1259 readIndentIniFile( indenterDirctoryStr + "/" + indenterIniFileList.at(indenterID) ); | 1294 readIndentIniFile( _indenterDirctoryStr + "/" + _indenterIniFileList.at(indenterID) ); |
1260 | 1295 |
1261 // Find out how the indenter can be executed. | 1296 // Find out how the indenter can be executed. |
1262 createIndenterCallString(); | 1297 createIndenterCallString(); |
1263 | 1298 |
1264 // Load the users last settings made for this indenter. | 1299 // Load the users last settings made for this indenter. |
1265 loadConfigFile( settingsDirctoryStr + "/" + indenterFileName + ".cfg" ); | 1300 loadConfigFile( _settingsDirctoryStr + "/" + _indenterFileName + ".cfg" ); |
1266 | 1301 |
1267 handleChangedIndenterSettings(); | 1302 handleChangedIndenterSettings(); |
1268 | 1303 |
1269 QApplication::restoreOverrideCursor(); | 1304 QApplication::restoreOverrideCursor(); |
1270 | 1305 |
1271 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS | 1306 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS |
1272 connect( toolBox, SIGNAL(currentChanged(int)), this, SLOT(updateDrawing()) ); | 1307 connect( _indenterParameterCategoriesToolBox, SIGNAL(currentChanged(int)), this, SLOT(updateDrawing()) ); |
1273 toolBox->removeItem( toolBox->indexOf(&dummyWidget) ); | 1308 _indenterParameterCategoriesToolBox->removeItem( _indenterParameterCategoriesToolBox->indexOf(&dummyWidget) ); |
1274 #endif // UNIVERSALINDENTGUI_NPP_EXPORTS | 1309 #endif // UNIVERSALINDENTGUI_NPP_EXPORTS |
1275 } | 1310 } |
1276 | 1311 |
1277 | 1312 |
1278 /*! | 1313 /*! |
1279 \brief Returns a string containing by the indenter supported file types/extensions divided by a space. | 1314 \brief Returns a string containing by the indenter supported file types/extensions divided by a space. |
1280 */ | 1315 */ |
1281 QString IndentHandler::getPossibleIndenterFileExtensions() { | 1316 QString IndentHandler::getPossibleIndenterFileExtensions() { |
1282 return fileTypes; | 1317 return _fileTypes; |
1283 } | 1318 } |
1284 | 1319 |
1285 | 1320 |
1286 /*! | 1321 /*! |
1287 \brief Returns the path and filename of the current indenter config file. | 1322 \brief Returns the path and filename of the current indenter config file. |
1288 */ | 1323 */ |
1289 QString IndentHandler::getIndenterCfgFile() { | 1324 QString IndentHandler::getIndenterCfgFile() { |
1290 QFileInfo fileInfo( indenterDirctoryStr + "/" + globalConfigFilename_ ); | 1325 QFileInfo fileInfo( _indenterDirctoryStr + "/" + _globalConfigFilename ); |
1291 return fileInfo.absoluteFilePath(); | 1326 return fileInfo.absoluteFilePath(); |
1292 } | 1327 } |
1293 | 1328 |
1294 | 1329 |
1295 /*! | 1330 /*! |
1296 \brief Tries to create a call path string for the indenter executable. If successful returns true. | 1331 \brief Tries to create a call path string for the indenter executable. If successful returns true. |
1297 */ | 1332 */ |
1298 bool IndentHandler::createIndenterCallString() { | 1333 bool IndentHandler::createIndenterCallString() { |
1299 QProcess indentProcess; | 1334 QProcess indentProcess; |
1300 | 1335 |
1301 if ( indenterFileName.isEmpty() ) { | 1336 if ( _indenterFileName.isEmpty() ) { |
1302 return false; | 1337 return false; |
1303 } | 1338 } |
1304 | 1339 |
1305 // First try to call the indenter inside of the data dir, using some suffix | 1340 // First try to call the indenter inside of the data dir, using some suffix |
1306 // ------------------------------------------------------------------------ | 1341 // ------------------------------------------------------------------------ |
1307 | 1342 |
1308 // Set the directory for the indenter execution | 1343 // Set the directory for the indenter execution |
1309 indentProcess.setWorkingDirectory( QFileInfo(indenterDirctoryStr).absoluteFilePath() ); | 1344 indentProcess.setWorkingDirectory( QFileInfo(_indenterDirctoryStr).absoluteFilePath() ); |
1310 | 1345 |
1311 foreach ( QString suffix, QStringList() << "" << ".exe" << ".bat" << ".com" << ".sh" ) { | 1346 foreach ( QString suffix, QStringList() << "" << ".exe" << ".bat" << ".com" << ".sh" ) { |
1312 indenterExecutableSuffix = suffix; | 1347 _indenterExecutableSuffix = suffix; |
1313 indenterExecutableCallString = QFileInfo(indenterDirctoryStr).absoluteFilePath() + "/" + indenterFileName; | 1348 _indenterExecutableCallString = QFileInfo(_indenterDirctoryStr).absoluteFilePath() + "/" + _indenterFileName; |
1314 indenterExecutableCallString += suffix; | 1349 _indenterExecutableCallString += suffix; |
1315 | 1350 |
1316 // Only try to call the indenter, if the file exists. | 1351 // Only try to call the indenter, if the file exists. |
1317 if ( QFile::exists(indenterExecutableCallString) ) { | 1352 if ( QFile::exists(_indenterExecutableCallString) ) { |
1318 // Only try to call the indenter directly if it is no php file | 1353 // Only try to call the indenter directly if it is no php file |
1319 if ( QFileInfo(indenterExecutableCallString).suffix().toLower() != "php" ) { | 1354 if ( QFileInfo(_indenterExecutableCallString).suffix().toLower() != "php" ) { |
1320 indentProcess.start( "\"" + indenterExecutableCallString + + "\" " + indenterShowHelpParameter ); | 1355 indentProcess.start( "\"" + _indenterExecutableCallString + + "\" " + _indenterShowHelpParameter ); |
1321 if ( indentProcess.waitForFinished(2000) ) { | 1356 if ( indentProcess.waitForFinished(2000) ) { |
1322 indenterExecutableCallString = "\"" + indenterExecutableCallString + "\""; | 1357 _indenterExecutableCallString = "\"" + _indenterExecutableCallString + "\""; |
1323 return true; | 1358 return true; |
1324 } | 1359 } |
1325 else if ( indentProcess.error() == QProcess::Timedout ) { | 1360 else if ( indentProcess.error() == QProcess::Timedout ) { |
1326 indenterExecutableCallString = "\"" + indenterExecutableCallString + "\""; | 1361 _indenterExecutableCallString = "\"" + _indenterExecutableCallString + "\""; |
1327 return true; | 1362 return true; |
1328 } | 1363 } |
1329 } | 1364 } |
1330 | 1365 |
1331 // Test for needed interpreters | 1366 // Test for needed interpreters |
1332 // ---------------------------- | 1367 // ---------------------------- |
1333 // If the file could not be executed, try to find a shebang at its start or test if its a php file. | 1368 // If the file could not be executed, try to find a shebang at its start or test if its a php file. |
1334 QString interpreterName = ""; | 1369 QString interpreterName = ""; |
1335 QFile indenterExecutable( indenterExecutableCallString ); | 1370 QFile indenterExecutable( _indenterExecutableCallString ); |
1336 | 1371 |
1337 // If indenter executable file has .php as suffix, use php as default interpreter | 1372 // If indenter executable file has .php as suffix, use php as default interpreter |
1338 if ( QFileInfo(indenterExecutableCallString).suffix().toLower() == "php" ) { | 1373 if ( QFileInfo(_indenterExecutableCallString).suffix().toLower() == "php" ) { |
1339 interpreterName = "php -f"; | 1374 interpreterName = "php -f"; |
1340 } | 1375 } |
1341 // Else try to open the file and read the shebang. | 1376 // Else try to open the file and read the shebang. |
1342 else if ( indenterExecutable.open(QFile::ReadOnly) ) { | 1377 else if ( indenterExecutable.open(QFile::ReadOnly) ) { |
1343 // Read the first line of the file. | 1378 // Read the first line of the file. |
1352 } | 1387 } |
1353 } | 1388 } |
1354 | 1389 |
1355 // Try to call the interpreter, if it exists. | 1390 // Try to call the interpreter, if it exists. |
1356 if ( !interpreterName.isEmpty() ) { | 1391 if ( !interpreterName.isEmpty() ) { |
1357 indenterExecutableCallString = interpreterName + " \"" + indenterExecutableCallString + "\""; | 1392 _indenterExecutableCallString = interpreterName + " \"" + _indenterExecutableCallString + "\""; |
1358 indentProcess.start( interpreterName + " -h"); | 1393 indentProcess.start( interpreterName + " -h"); |
1359 if ( indentProcess.waitForFinished(2000) ) { | 1394 if ( indentProcess.waitForFinished(2000) ) { |
1360 return true; | 1395 return true; |
1361 } | 1396 } |
1362 else if ( indentProcess.error() == QProcess::Timedout ) { | 1397 else if ( indentProcess.error() == QProcess::Timedout ) { |
1363 return true; | 1398 return true; |
1364 } | 1399 } |
1365 // now we know an interpreter is needed but it could not be called, so inform the user. | 1400 // now we know an interpreter is needed but it could not be called, so inform the user. |
1366 else { | 1401 else { |
1367 errorMessageDialog->showMessage( tr("Interpreter needed"), | 1402 _errorMessageDialog->showMessage( tr("Interpreter needed"), |
1368 tr("To use the selected indenter the program \"%1\" needs to be available in the global environment. You should add an entry to your path settings.").arg(interpreterName) ); | 1403 tr("To use the selected indenter the program \"%1\" needs to be available in the global environment. You should add an entry to your path settings.").arg(interpreterName) ); |
1369 return true; | 1404 return true; |
1370 } | 1405 } |
1371 } | 1406 } |
1372 } | 1407 } |
1373 } | 1408 } |
1374 | 1409 |
1375 | 1410 |
1376 // If unsuccessful try if the indenter executable is a JavaScript file | 1411 // If unsuccessful try if the indenter executable is a JavaScript file |
1377 // ------------------------------------------------------------------- | 1412 // ------------------------------------------------------------------- |
1378 indenterExecutableSuffix = ".js"; | 1413 _indenterExecutableSuffix = ".js"; |
1379 indenterExecutableCallString = QFileInfo(indenterDirctoryStr).absoluteFilePath() + "/" + indenterFileName; | 1414 _indenterExecutableCallString = QFileInfo(_indenterDirctoryStr).absoluteFilePath() + "/" + _indenterFileName; |
1380 indenterExecutableCallString += indenterExecutableSuffix; | 1415 _indenterExecutableCallString += _indenterExecutableSuffix; |
1381 if ( QFile::exists(indenterExecutableCallString) ) { | 1416 if ( QFile::exists(_indenterExecutableCallString) ) { |
1382 return true; | 1417 return true; |
1383 } | 1418 } |
1384 | 1419 |
1385 | 1420 |
1386 // If unsuccessful try to call the indenter global, using some suffix | 1421 // If unsuccessful try to call the indenter global, using some suffix |
1387 // ------------------------------------------------------------------ | 1422 // ------------------------------------------------------------------ |
1388 foreach ( QString suffix, QStringList() << "" << ".exe" << ".bat" << ".com" << ".sh" ) { | 1423 foreach ( QString suffix, QStringList() << "" << ".exe" << ".bat" << ".com" << ".sh" ) { |
1389 indenterExecutableSuffix = suffix; | 1424 _indenterExecutableSuffix = suffix; |
1390 indenterExecutableCallString = indenterFileName + suffix; | 1425 _indenterExecutableCallString = _indenterFileName + suffix; |
1391 indentProcess.start( indenterExecutableCallString + " " + indenterShowHelpParameter ); | 1426 indentProcess.start( _indenterExecutableCallString + " " + _indenterShowHelpParameter ); |
1392 if ( indentProcess.waitForFinished(2000) ) { | 1427 if ( indentProcess.waitForFinished(2000) ) { |
1393 return true; | 1428 return true; |
1394 } | 1429 } |
1395 else if ( indentProcess.error() == QProcess::Timedout ) { | 1430 else if ( indentProcess.error() == QProcess::Timedout ) { |
1396 return true; | 1431 return true; |
1398 } | 1433 } |
1399 | 1434 |
1400 | 1435 |
1401 // If even globally calling the indenter fails, try calling .com and .exe via wine | 1436 // If even globally calling the indenter fails, try calling .com and .exe via wine |
1402 // ------------------------------------------------------------------------------- | 1437 // ------------------------------------------------------------------------------- |
1403 indenterExecutableCallString = "\"" + QFileInfo(indenterDirctoryStr).absoluteFilePath() + "/" + indenterFileName; | 1438 _indenterExecutableCallString = "\"" + QFileInfo(_indenterDirctoryStr).absoluteFilePath() + "/" + _indenterFileName; |
1404 | 1439 |
1405 foreach ( QString suffix, QStringList() << ".exe" << ".com" ) { | 1440 foreach ( QString suffix, QStringList() << ".exe" << ".com" ) { |
1406 indenterExecutableSuffix = suffix; | 1441 _indenterExecutableSuffix = suffix; |
1407 if ( QFile::exists(indenterDirctoryStr + "/" + indenterFileName + suffix) ) { | 1442 if ( QFile::exists(_indenterDirctoryStr + "/" + _indenterFileName + suffix) ) { |
1408 QProcess wineTestProcess; | 1443 QProcess wineTestProcess; |
1409 wineTestProcess.start("wine --version"); | 1444 wineTestProcess.start("wine --version"); |
1410 // if the process of wine was not callable assume that wine is not installed | 1445 // if the process of wine was not callable assume that wine is not installed |
1411 if ( !wineTestProcess.waitForFinished(2000) ) { | 1446 if ( !wineTestProcess.waitForFinished(2000) ) { |
1412 errorMessageDialog->showMessage(tr("wine not installed"), tr("There exists only a win32 executable of the indenter and wine does not seem to be installed. Please install wine to be able to run the indenter.") ); | 1447 _errorMessageDialog->showMessage(tr("wine not installed"), tr("There exists only a win32 executable of the indenter and wine does not seem to be installed. Please install wine to be able to run the indenter.") ); |
1413 indenterExecutableCallString = ""; | 1448 _indenterExecutableCallString = ""; |
1414 return false; | 1449 return false; |
1415 } | 1450 } |
1416 else { | 1451 else { |
1417 indenterExecutableCallString = "\"" + QFileInfo(indenterDirctoryStr).absoluteFilePath() + "/"; | 1452 _indenterExecutableCallString = "\"" + QFileInfo(_indenterDirctoryStr).absoluteFilePath() + "/"; |
1418 indenterExecutableCallString += indenterFileName + suffix + "\""; | 1453 _indenterExecutableCallString += _indenterFileName + suffix + "\""; |
1419 indenterExecutableCallString = "wine " + indenterExecutableCallString; | 1454 _indenterExecutableCallString = "wine " + _indenterExecutableCallString; |
1420 | 1455 |
1421 return true; | 1456 return true; |
1422 } | 1457 } |
1423 } | 1458 } |
1424 } | 1459 } |
1425 | 1460 |
1426 indenterExecutableCallString = ""; | 1461 _indenterExecutableCallString = ""; |
1427 indenterExecutableSuffix = ""; | 1462 _indenterExecutableSuffix = ""; |
1428 return false; | 1463 return false; |
1429 } | 1464 } |
1430 | 1465 |
1431 | 1466 |
1432 /*! | 1467 /*! |
1433 \brief Returns a string that points to where the indenters manual can be found. | 1468 \brief Returns a string that points to where the indenters manual can be found. |
1434 */ | 1469 */ |
1435 QString IndentHandler::getManual() { | 1470 QString IndentHandler::getManual() { |
1436 if ( indenterSettings != NULL ) { | 1471 if ( _indenterSettings != NULL ) { |
1437 return indenterSettings->value("header/manual").toString(); | 1472 return _indenterSettings->value("header/manual").toString(); |
1438 } | 1473 } |
1439 else { | 1474 else { |
1440 return ""; | 1475 return ""; |
1441 } | 1476 } |
1442 } | 1477 } |
1453 | 1488 |
1454 /*! | 1489 /*! |
1455 \brief Can be called to update all widgets text to the currently selected language. | 1490 \brief Can be called to update all widgets text to the currently selected language. |
1456 */ | 1491 */ |
1457 void IndentHandler::retranslateUi() { | 1492 void IndentHandler::retranslateUi() { |
1458 indenterSelectionCombobox->setToolTip( tr("<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Shows the currently chosen indenters name and lets you choose other available indenters</p></body></html>") ); | 1493 _indenterSelectionCombobox->setToolTip( tr("<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Shows the currently chosen indenters name and lets you choose other available indenters</p></body></html>") ); |
1459 indenterParameterHelpButton->setToolTip( tr("Brings you to the online manual of the currently selected indenter, where you can get further help on the possible parameters.") ); | 1494 _indenterParameterHelpButton->setToolTip( tr("Brings you to the online manual of the currently selected indenter, where you can get further help on the possible parameters.") ); |
1460 | 1495 |
1461 actionLoad_Indenter_Config_File->setText(QApplication::translate("IndentHandler", "Load Indenter Config File", 0, QApplication::UnicodeUTF8)); | 1496 _actionLoadIndenterConfigFile->setText(QApplication::translate("IndentHandler", "Load Indenter Config File", 0, QApplication::UnicodeUTF8)); |
1462 actionLoad_Indenter_Config_File->setStatusTip(QApplication::translate("IndentHandler", "Opens a file dialog to load the original config file of the indenter.", 0, QApplication::UnicodeUTF8)); | 1497 _actionLoadIndenterConfigFile->setStatusTip(QApplication::translate("IndentHandler", "Opens a file dialog to load the original config file of the indenter.", 0, QApplication::UnicodeUTF8)); |
1463 actionLoad_Indenter_Config_File->setShortcut(QApplication::translate("IndentHandler", "Alt+O", 0, QApplication::UnicodeUTF8)); | 1498 _actionLoadIndenterConfigFile->setShortcut(QApplication::translate("IndentHandler", "Alt+O", 0, QApplication::UnicodeUTF8)); |
1464 | 1499 |
1465 actionSave_Indenter_Config_File->setText(QApplication::translate("IndentHandler", "Save Indenter Config File", 0, QApplication::UnicodeUTF8)); | 1500 _actionSaveIndenterConfigFile->setText(QApplication::translate("IndentHandler", "Save Indenter Config File", 0, QApplication::UnicodeUTF8)); |
1466 actionSave_Indenter_Config_File->setStatusTip(QApplication::translate("IndentHandler", "Opens a dialog to save the current indenter configuration to a file.", 0, QApplication::UnicodeUTF8)); | 1501 _actionSaveIndenterConfigFile->setStatusTip(QApplication::translate("IndentHandler", "Opens a dialog to save the current indenter configuration to a file.", 0, QApplication::UnicodeUTF8)); |
1467 actionSave_Indenter_Config_File->setShortcut(QApplication::translate("IndentHandler", "Alt+S", 0, QApplication::UnicodeUTF8)); | 1502 _actionSaveIndenterConfigFile->setShortcut(QApplication::translate("IndentHandler", "Alt+S", 0, QApplication::UnicodeUTF8)); |
1468 | 1503 |
1469 actionCreateShellScript->setText(QApplication::translate("IndentHandler", "Create Indenter Call Shell Script", 0, QApplication::UnicodeUTF8)); | 1504 _actionCreateShellScript->setText(QApplication::translate("IndentHandler", "Create Indenter Call Shell Script", 0, QApplication::UnicodeUTF8)); |
1470 actionCreateShellScript->setToolTip(QApplication::translate("IndentHandler", "Create a shell script that calls the current selected indenter for formatting an as parameter given file with the current indent settings.", 0, QApplication::UnicodeUTF8)); | 1505 _actionCreateShellScript->setToolTip(QApplication::translate("IndentHandler", "Create a shell script that calls the current selected indenter for formatting an as parameter given file with the current indent settings.", 0, QApplication::UnicodeUTF8)); |
1471 actionCreateShellScript->setStatusTip(QApplication::translate("IndentHandler", "Create a shell script that calls the current selected indenter for formatting an as parameter given file with the current indent settings.", 0, QApplication::UnicodeUTF8)); | 1506 _actionCreateShellScript->setStatusTip(QApplication::translate("IndentHandler", "Create a shell script that calls the current selected indenter for formatting an as parameter given file with the current indent settings.", 0, QApplication::UnicodeUTF8)); |
1472 | 1507 |
1473 actionResetIndenterParameters->setText(QApplication::translate("IndentHandler", "Reset indenter parameters", 0, QApplication::UnicodeUTF8)); | 1508 _actionResetIndenterParameters->setText(QApplication::translate("IndentHandler", "Reset indenter parameters", 0, QApplication::UnicodeUTF8)); |
1474 actionResetIndenterParameters->setToolTip(QApplication::translate("IndentHandler", "Resets all indenter parameters to the default values.", 0, QApplication::UnicodeUTF8)); | 1509 _actionResetIndenterParameters->setToolTip(QApplication::translate("IndentHandler", "Resets all indenter parameters to the default values.", 0, QApplication::UnicodeUTF8)); |
1475 actionResetIndenterParameters->setStatusTip(QApplication::translate("IndentHandler", "Resets all indenter parameters to the default values.", 0, QApplication::UnicodeUTF8)); | 1510 _actionResetIndenterParameters->setStatusTip(QApplication::translate("IndentHandler", "Resets all indenter parameters to the default values.", 0, QApplication::UnicodeUTF8)); |
1476 } | 1511 } |
1477 | 1512 |
1478 | 1513 |
1479 /*! | 1514 /*! |
1480 \brief Returns the name of the currently selected indenter. | 1515 \brief Returns the name of the currently selected indenter. |
1481 */ | 1516 */ |
1482 QString IndentHandler::getCurrentIndenterName() { | 1517 QString IndentHandler::getCurrentIndenterName() { |
1483 QString currentIndenterName = indenterSelectionCombobox->currentText(); | 1518 QString currentIndenterName = _indenterSelectionCombobox->currentText(); |
1484 | 1519 |
1485 // Remove the supported programming languages from indenters name, which are set in braces. | 1520 // Remove the supported programming languages from indenters name, which are set in braces. |
1486 if ( currentIndenterName.indexOf("(") > 0 ) { | 1521 if ( currentIndenterName.indexOf("(") > 0 ) { |
1487 // Using index-1 to also leave out the blank before the brace. | 1522 // Using index-1 to also leave out the blank before the brace. |
1488 currentIndenterName = currentIndenterName.left( currentIndenterName.indexOf("(")-1 ); | 1523 currentIndenterName = currentIndenterName.left( currentIndenterName.indexOf("(")-1 ); |
1559 | 1594 |
1560 // Delete any old file, write the new contents and set executable permissions. | 1595 // Delete any old file, write the new contents and set executable permissions. |
1561 QFile::remove(shellScriptFileName); | 1596 QFile::remove(shellScriptFileName); |
1562 QFile outSrcFile(shellScriptFileName); | 1597 QFile outSrcFile(shellScriptFileName); |
1563 if ( outSrcFile.open( QFile::ReadWrite | QFile::Text ) ) { | 1598 if ( outSrcFile.open( QFile::ReadWrite | QFile::Text ) ) { |
1564 QString shellScriptConfigFilename = QFileInfo(shellScriptFileName).baseName() + "." + QFileInfo(globalConfigFilename_).suffix(); | 1599 QString shellScriptConfigFilename = QFileInfo(shellScriptFileName).baseName() + "." + QFileInfo(_globalConfigFilename).suffix(); |
1565 | 1600 |
1566 // Get the content of the shell/batch script. | 1601 // Get the content of the shell/batch script. |
1567 QString indenterCallShellScript = generateShellScript(shellScriptConfigFilename); | 1602 QString indenterCallShellScript = generateShellScript(shellScriptConfigFilename); |
1568 | 1603 |
1569 // Replace placeholder for script name in script template. | 1604 // Replace placeholder for script name in script template. |
1576 #endif | 1611 #endif |
1577 outSrcFile.close(); | 1612 outSrcFile.close(); |
1578 | 1613 |
1579 // Save the indenter config file to the same directory, where the shell srcipt was saved to, | 1614 // Save the indenter config file to the same directory, where the shell srcipt was saved to, |
1580 // because the script will reference it there via "./". | 1615 // because the script will reference it there via "./". |
1581 if ( !globalConfigFilename_.isEmpty() ) { | 1616 if ( !_globalConfigFilename.isEmpty() ) { |
1582 saveConfigFile( QFileInfo(shellScriptFileName).path() + "/" + shellScriptConfigFilename, getParameterString() ); | 1617 saveConfigFile( QFileInfo(shellScriptFileName).path() + "/" + shellScriptConfigFilename, getParameterString() ); |
1583 } | 1618 } |
1584 } | 1619 } |
1585 } | 1620 } |
1586 | 1621 |
1617 } | 1652 } |
1618 } | 1653 } |
1619 | 1654 |
1620 | 1655 |
1621 /*! | 1656 /*! |
1622 \brief Sets the function pointer \a parameterChangedCallback to the given callback | 1657 \brief Sets the function pointer \a _parameterChangedCallback to the given callback |
1623 function \a paramChangedCallback. | 1658 function \a paramChangedCallback. |
1624 | 1659 |
1625 Is needed for use as Notepad++ plugin. | 1660 Is needed for use as Notepad++ plugin. |
1626 */ | 1661 */ |
1627 void IndentHandler::setParameterChangedCallback( void(*paramChangedCallback)(void) ) { | 1662 void IndentHandler::setParameterChangedCallback( void(*paramChangedCallback)(void) ) { |
1628 parameterChangedCallback = paramChangedCallback; | 1663 _parameterChangedCallback = paramChangedCallback; |
1629 } | 1664 } |
1630 | 1665 |
1631 | 1666 |
1632 /*! | 1667 /*! |
1633 \brief Emits the \a indenterSettingsChanged signal and if set executes the \a parameterChangedCallback function. | 1668 \brief Emits the \a indenterSettingsChanged signal and if set executes the \a _parameterChangedCallback function. |
1634 | 1669 |
1635 Is needed for use as Notepad++ plugin. | 1670 Is needed for use as Notepad++ plugin. |
1636 */ | 1671 */ |
1637 void IndentHandler::handleChangedIndenterSettings() { | 1672 void IndentHandler::handleChangedIndenterSettings() { |
1638 emit( indenterSettingsChanged() ); | 1673 emit( indenterSettingsChanged() ); |
1639 | 1674 |
1640 if ( parameterChangedCallback != NULL ) { | 1675 if ( _parameterChangedCallback != NULL ) { |
1641 parameterChangedCallback(); | 1676 _parameterChangedCallback(); |
1642 } | 1677 } |
1643 } | 1678 } |
1644 | 1679 |
1645 | 1680 |
1646 /*! | 1681 /*! |
1647 \brief Sets a callback function that shall be called, when the this indenter parameter window gets closed. | 1682 \brief Sets a callback function that shall be called, when the this indenter parameter window gets closed. |
1648 | 1683 |
1649 Is needed for use as Notepad++ plugin. | 1684 Is needed for use as Notepad++ plugin. |
1650 */ | 1685 */ |
1651 void IndentHandler::setWindowClosedCallback( void(*winClosedCallback)(void) ) { | 1686 void IndentHandler::setWindowClosedCallback( void(*winClosedCallback)(void) ) { |
1652 windowClosedCallback = winClosedCallback; | 1687 _windowClosedCallback = winClosedCallback; |
1653 } | 1688 } |
1654 | 1689 |
1655 | 1690 |
1656 /*! | 1691 /*! |
1657 \brief Is called on this indenter parameter window close and if set calls the function \a windowClosedCallback. | 1692 \brief Is called on this indenter parameter window close and if set calls the function \a _windowClosedCallback. |
1658 | 1693 |
1659 Is needed for use as Notepad++ plugin. | 1694 Is needed for use as Notepad++ plugin. |
1660 */ | 1695 */ |
1661 void IndentHandler::closeEvent(QCloseEvent *event) { | 1696 void IndentHandler::closeEvent(QCloseEvent *event) { |
1662 if ( windowClosedCallback != NULL ) { | 1697 if ( _windowClosedCallback != NULL ) { |
1663 windowClosedCallback(); | 1698 _windowClosedCallback(); |
1664 } | 1699 } |
1665 event->accept(); | 1700 event->accept(); |
1666 } | 1701 } |
1667 | 1702 |
1668 | 1703 |
1669 /*! | 1704 /*! |
1670 \brief Returns the id (list index) of the currently selected indenter. | 1705 \brief Returns the id (list index) of the currently selected indenter. |
1671 */ | 1706 */ |
1672 int IndentHandler::getIndenterId() { | 1707 int IndentHandler::getIndenterId() { |
1673 return indenterSelectionCombobox->currentIndex(); | 1708 return _indenterSelectionCombobox->currentIndex(); |
1674 } | 1709 } |
1675 | 1710 |
1676 | 1711 |
1677 void IndentHandler::updateDrawing() { | 1712 void IndentHandler::updateDrawing() { |
1678 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS | 1713 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS |
1694 | 1729 |
1695 | 1730 |
1696 /*! | 1731 /*! |
1697 \brief Converts characters < > and & in the \a text to HTML codes < > and &. | 1732 \brief Converts characters < > and & in the \a text to HTML codes < > and &. |
1698 */ | 1733 */ |
1734 //TODO: This function should go into a string helper/tool class/file. | |
1699 QString IndentHandler::encodeToHTML(const QString &text) { | 1735 QString IndentHandler::encodeToHTML(const QString &text) { |
1700 QString htmlText = text; | 1736 QString htmlText = text; |
1701 htmlText.replace("&", "&"); | 1737 htmlText.replace("&", "&"); |
1702 htmlText.replace("<", "<"); | 1738 htmlText.replace("<", "<"); |
1703 htmlText.replace(">", ">"); | 1739 htmlText.replace(">", ">"); |