diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/IndentHandler.cpp | 387 | ||||
-rw-r--r-- | src/IndentHandler.h | 9 |
2 files changed, 179 insertions, 217 deletions
diff --git a/src/IndentHandler.cpp b/src/IndentHandler.cpp index 142cb39..f80b7c6 100644 --- a/src/IndentHandler.cpp +++ b/src/IndentHandler.cpp @@ -597,89 +597,65 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName) // Search for name of each boolean parameter and set its value if found. for (const ParamBoolean &pBoolean : m_paramBooleans) { - // boolean value that will be assigned to the checkbox + bool found = false; bool paramValue = false; + paramValue = m_indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); - // first search for the longer parameter string - // the true parameter string is longer than the false string - if (pBoolean.trueString.length() > pBoolean.falseString.length()) + // try regex matching first + if (!pBoolean.trueRegexString.isEmpty() && !pBoolean.falseRegexString.isEmpty()) { - int index = -1; - // search for the true string - if (m_useRegex) - { - index = cfgFileData.find(TQRegExp(pBoolean.trueString), 0); - } - else - { - index = cfgFileData.find(pBoolean.trueString, 0, false); - } - // if true string found set the parameter value to true - if (index != -1) - { - paramValue = true; - } - // if true string not found, search for false string - else + // search for the longer parameter string first + if (pBoolean.trueRegexString.length() > pBoolean.falseRegexString.length()) { - if (m_useRegex) + if (cfgFileData.find(TQRegExp(pBoolean.trueRegexString), 0) != -1) { - index = cfgFileData.find(TQRegExp(pBoolean.falseString), 0); + paramValue = true; + found = true; } - else + else if (cfgFileData.find(TQRegExp(pBoolean.falseRegexString), 0) != -1) { - index = cfgFileData.find(pBoolean.falseString, 0, false); + paramValue = false; + found = true; } - // if false string found set the parameter value to false - if (index != -1) + } + else + { + if (cfgFileData.find(TQRegExp(pBoolean.falseRegexString), 0) != -1) { paramValue = false; + found = true; } - // neither true nor false parameter found so use default value - else + else if (cfgFileData.find(TQRegExp(pBoolean.trueRegexString), 0) != -1) { - paramValue = m_indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); + paramValue = true; + found = true; } } } - // the false parameter string is longer than the true string - else + // try standard search if regex search failed + if (!found) { - // search for the false string - int index = -1; - if (m_useRegex) - { - index = cfgFileData.find(TQRegExp(pBoolean.falseString), 0); - } - else - { - index = cfgFileData.find(pBoolean.falseString, 0, false); - } - // if false string found set the parameter value to false - if (index != -1) + // search for the longer parameter string first + if (pBoolean.trueString.length() > pBoolean.falseString.length()) { - paramValue = false; - } - // if false string not found, search for true string - else - { - if (m_useRegex) + if (cfgFileData.find(pBoolean.trueString, 0, false) != -1) { - index = cfgFileData.find(TQRegExp(pBoolean.trueString), 0); + paramValue = true; } - else + else if (cfgFileData.find(pBoolean.falseString, 0, false) != -1) { - index = cfgFileData.find(pBoolean.trueString, 0, false); + paramValue = false; } - // if true string found set the parameter value to true - if (index != -1) + } + else + { + if (cfgFileData.find(pBoolean.falseString, 0, false) != -1) { - paramValue = true; + paramValue = false; } - // neither true nor false parameter found so use default value - else + else if (cfgFileData.find(pBoolean.trueString, 0, false) != -1) { - paramValue = m_indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); + paramValue = true; } } } @@ -689,108 +665,108 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName) // Search for name of each numeric parameter and set the value found behind it. for(const ParamNumeric &pNumeric : m_paramNumerics) { - TQRegExp pRegEx(pNumeric.paramCallName); - int index = -1; - if (m_useRegex) - { - index = pRegEx.search(cfgFileData); - } - else - { - index = cfgFileData.find(pNumeric.paramCallName, 0); - } - // parameter was found in config file - if (index != -1) + int paramValue = m_indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt(); + bool found = false; + // try regex matching first + if (!pNumeric.paramCallNameRegex.isEmpty()) { - // set index after the parameter name, so in front of the number - if (m_useRegex) + TQRegExp pRegEx(pNumeric.paramCallNameRegex); + int index = pRegEx.search(cfgFileData); + if (index != -1) { index += pRegEx.matchedLength(); + int crPos = endParamRegex.search(cfgFileData, index + 1); + if (crPos != -1) + { + found = true; + paramValue = cfgFileData.mid(index, crPos - index).toInt(); + } } - else - { - index += pNumeric.paramCallName.length(); - } + } - // Find the end of the parameter by searching for set config file parameter ending. Most of - // time this is a carriage return. - int crPos = index + 1; - if (m_useRegex) - { - crPos = endParamRegex.search(cfgFileData, index + 1); - } - else + // try standard search if regex search failed + if (!found) + { + int index = cfgFileData.find(pNumeric.paramCallName, 0); + if (index != -1) { - crPos = cfgFileData.find(m_cfgFileParameterEnding, index + 1); + index += pNumeric.paramCallName.length(); + int crPos = cfgFileData.find(m_cfgFileParameterEnding, index + 1); + if (crPos != -1) + { + found = true; + paramValue = cfgFileData.mid(index, crPos - index).toInt(); + } } - - // get the number and convert it to int - int paramValue = cfgFileData.mid(index, crPos - index).toInt(nullptr); - - // disable the signal-slot connection. Otherwise signal is emmitted each time when value is - // set - TQObject::disconnect(pNumeric.spinBox, SIGNAL(valueChanged(int)), this, - SLOT(handleChangedIndenterSettings())); - pNumeric.spinBox->setValue(paramValue); - pNumeric.valueEnabledChkBox->setChecked(true); - TQObject::connect(pNumeric.spinBox, SIGNAL(valueChanged(int)), this, - SLOT(handleChangedIndenterSettings())); - } - // parameter was not found in config file - else - { - int defaultValue = m_indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt(); - pNumeric.spinBox->setValue(defaultValue); - pNumeric.valueEnabledChkBox->setChecked(false); } + + // Disconnect and reconnect the signal, otherwise it is emitted each time the value is set + disconnect(pNumeric.spinBox, SIGNAL(valueChanged(int)), + this, SLOT(handleChangedIndenterSettings())); + pNumeric.spinBox->setValue(paramValue); + pNumeric.valueEnabledChkBox->setChecked(found); + connect(pNumeric.spinBox, SIGNAL(valueChanged(int)), + this, SLOT(handleChangedIndenterSettings())); } // Search for name of each string parameter and set it. for (const ParamString &pString : m_paramStrings) { - // The number of the found values for this parameter name. - int numberOfValues = 0; - - TQRegExp pRegEx(pString.paramCallName); - int index = -1; - if (m_useRegex) + TQString paramValueStr = TQString::null; + int numberOfValues = 0; // The number of the found values for this parameter name. + // try regex matching first + if (!pString.paramCallNameRegex.isEmpty()) { - index = pRegEx.search(cfgFileData); - } - else - { - index = cfgFileData.find(pString.paramCallName, 0, false); - } - // If parameter was found in config file - if (index != -1) - { - TQString paramValueStr = TQString::null; - while (index != -1) + TQRegExp pRegEx(pString.paramCallNameRegex); + int index = pRegEx.search(cfgFileData); + if (index != -1) { - numberOfValues++; - - // Set index after the parameter name, so it points to the front of the string value. - if (m_useRegex) + while (index != -1) { + numberOfValues++; + index += pRegEx.matchedLength(); - } - else - { - index += pString.paramCallName.length(); - } + int crPos = stringRegex.search(cfgFileData, index); + crPos += stringRegex.matchedLength(); - // Find the end of the parameter by searching for set config file parameter ending. Most of - // time this is a carriage return. - int crPos = index; - if (m_useRegex) - { - crPos = stringRegex.search(cfgFileData, index); + // Get the string and remember it. + TQString paramStrVal = TQString::null; + if ((crPos - index) >= 2) + { + // Remove leading and trailing quotes + paramStrVal = TQString(cfgFileData.mid(index + 1, crPos - index - 2)); + } + if (numberOfValues < 2) + { + paramValueStr = paramStrVal; + } + else + { + // If the same parameter is set multiple times, concatenate the strings dvivided by a |. + paramValueStr = paramValueStr + "|" + paramStrVal; + } + + // Ignore till end of line because there could a comment + // after the string itself in the configuration file + crPos = endParamRegex.search(cfgFileData, crPos); crPos += stringRegex.matchedLength(); + + // Get next value for this setting, if one exists. + index = pRegEx.search(cfgFileData, crPos); } - else - { - crPos = cfgFileData.find(m_cfgFileParameterEnding, index); - } + } + } + + // try standard search if regex search failed + if (numberOfValues == 0) + { + int index = cfgFileData.find(pString.paramCallName, 0, false); + while (index != -1) + { + numberOfValues++; + + index += pString.paramCallName.length(); + int crPos = cfgFileData.find(m_cfgFileParameterEnding, index); // Get the string and remember it. TQString paramStrVal = TQString::null; @@ -803,78 +779,65 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName) { paramValueStr = paramStrVal; } - // If the same parameter has been set multiple times, concatenate the strings dvivided by a - // |. else { + // If the same parameter is set multiple times, concatenate the strings dvivided by a |. paramValueStr = paramValueStr + "|" + paramStrVal; } - // Ignore till end of line if regex are used (this because there could a comment - // after the string itself in the configuration file - if (m_useRegex) - { - crPos = endParamRegex.search(cfgFileData, crPos); - crPos += stringRegex.matchedLength(); - } - // Get next value for this setting, if one exists. - if (m_useRegex) - { - index = pRegEx.search(cfgFileData, crPos); - } - else - { - index = cfgFileData.find(pString.paramCallName, crPos, false); - } + index = cfgFileData.find(pString.paramCallName, crPos, false); } - // Set the text for the line edit. - pString.lineEdit->setText(paramValueStr); - pString.valueEnabledChkBox->setChecked(true); } - // Parameter was not found in config file - else + + // Set the text for the line edit. + if (numberOfValues == 0) { - pString.lineEdit->setText(m_indenterSettings->value(pString.paramName + - "/ValueDefault").toString()); - pString.valueEnabledChkBox->setChecked(false); + paramValueStr = m_indenterSettings->value(pString.paramName + "/ValueDefault").toString(); } + pString.lineEdit->setText(paramValueStr); + pString.valueEnabledChkBox->setChecked(numberOfValues != 0); } // search for name of each multiple choice parameter and set it for (const ParamMultiple &pMultiple : m_paramMultiples) { - int i = 0; - int index = -1; + bool found = false; - // search for all parameter names of the multiple choice list - // if one is found, set it and leave the while loop - while (i < pMultiple.choicesStrings.count() && index == -1) + // try regex matching first + for (int i = 0; i < pMultiple.choicesRegexStrings.count(); ++i) { - index = cfgFileData.find(pMultiple.choicesStrings[i], 0, false); - if (m_useRegex) - { - index = cfgFileData.find(TQRegExp(pMultiple.choicesStrings[i]), 0); - } - else - { - index = cfgFileData.find(pMultiple.choicesStrings[i], 0, false); - } + int index = cfgFileData.find(TQRegExp(pMultiple.choicesRegexStrings[i]), 0); if (index != -1) { pMultiple.comboBox->setCurrentItem(i); - pMultiple.valueEnabledChkBox->setChecked(true); + found = true; + break; + } + } + + // try standard search + if (!found) + { + for (int i = 0; i < pMultiple.choicesStrings.count(); ++i) + { + int index = cfgFileData.find(pMultiple.choicesStrings[i], 0, false); + if (index != -1) + { + pMultiple.comboBox->setCurrentItem(i); + found = true; + break; + } } - i++; } // parameter was not set in config file, so use default value - if (index == -1) + if (!found) { int defaultValue = m_indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt(); pMultiple.comboBox->setCurrentItem(defaultValue); - pMultiple.valueEnabledChkBox->setChecked(false); } + pMultiple.valueEnabledChkBox->setChecked(found); } return true; @@ -976,14 +939,6 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath) m_outputFileName = m_indenterSettings->value("header/outputFileName").toString(); m_fileTypes = m_indenterSettings->value("header/fileTypes").toString(); m_fileTypes.replace('|', " "); - if (m_indenterSettings->value("header/useRegex").toString() == "true") - { - m_useRegex = true; - } - else - { - m_useRegex = false; - } // read the categories names which are separated by "|" TQString categoriesStr = m_indenterSettings->value("header/categories").toString(); @@ -1044,10 +999,6 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath) // edit type is numeric so create a spinbox with label if (editType == "numeric") { - // read the parameter name as it is used at the command line or in its config file - TQString parameterCallName = - m_indenterSettings->value(indenterParameter + "/CallName").toString(); - // create checkbox which enables or disables the parameter TQCheckBox *chkBox = new TQCheckBox(m_indenterParameterCategoryPages.at(category).widget); chkBox->setChecked(m_indenterSettings->value(indenterParameter + "/Enabled").toBool()); @@ -1102,7 +1053,10 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath) // remember parameter name and reference to its spinbox ParamNumeric paramNumeric; paramNumeric.paramName = indenterParameter; - paramNumeric.paramCallName = parameterCallName; + paramNumeric.paramCallName = m_indenterSettings->value(indenterParameter + + "/CallName").toString(); + paramNumeric.paramCallNameRegex = m_indenterSettings->value(indenterParameter + + "/CallNameRegex").toString(); paramNumeric.spinBox = spinBox; paramNumeric.label = label; paramNumeric.valueEnabledChkBox = chkBox; @@ -1136,6 +1090,10 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath) m_indenterSettings->value(indenterParameter + "/TrueFalse").toString()); paramBoolean.trueString = trueFalseStrings[0]; paramBoolean.falseString = trueFalseStrings[1]; + TQStringList trueFalseRegexStrings = TQStringList::split("|", + m_indenterSettings->value(indenterParameter + "/TrueFalseRegex").toString()); + paramBoolean.trueRegexString = trueFalseRegexStrings[0]; + paramBoolean.falseRegexString = trueFalseRegexStrings[1]; paramBoolean.checkBox->setChecked(m_indenterSettings->value(paramBoolean.paramName + "/ValueDefault").toBool()); m_paramBooleans.append(paramBoolean); @@ -1145,10 +1103,6 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath) // edit type is numeric so create a line edit with label else if (editType == "string") { - // read the parameter name as it is used at the command line or in its config file - TQString parameterCallName = - m_indenterSettings->value(indenterParameter + "/CallName").toString(); - // create check box which enables or disables the parameter TQCheckBox *chkBox = new TQCheckBox(m_indenterParameterCategoryPages.at(category).widget); chkBox->setChecked(m_indenterSettings->value(indenterParameter + "/Enabled").toBool()); @@ -1188,7 +1142,10 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath) // remember parameter name and reference to its line edit ParamString paramString; paramString.paramName = indenterParameter; - paramString.paramCallName = parameterCallName; + paramString.paramCallName = m_indenterSettings->value(indenterParameter + + "/CallName").toString(); + paramString.paramCallNameRegex = m_indenterSettings->value(indenterParameter + + "/CallNameRegex").toString(); paramString.lineEdit = lineEdit; paramString.label = label; paramString.valueEnabledChkBox = chkBox; @@ -1203,10 +1160,6 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath) // edit type is multiple so create a combobox with label else if (editType == "multiple") { - // read the parameter name as it is used at the command line or in its config file - TQString parameterCallName = - m_indenterSettings->value(indenterParameter + "/CallName").toString(); - // create checkbox which enables or disables the parameter TQCheckBox *chkBox = new TQCheckBox(m_indenterParameterCategoryPages.at(category).widget); chkBox->setChecked(m_indenterSettings->value(indenterParameter + "/Enabled").toBool()); @@ -1218,15 +1171,21 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath) TQComboBox *comboBox = new TQComboBox(m_indenterParameterCategoryPages.at(category).widget); TQStringList choicesStrings = TQStringList::split("|", m_indenterSettings->value(indenterParameter + "/Choices").toString()); - TQStringList choicesStringsReadable = TQStringList::split("|", + TQStringList choicesRegexStrings = TQStringList::split("|", + m_indenterSettings->value(indenterParameter + "/ChoicesRegex").toString()); + TQStringList choicesReadableStrings = TQStringList::split("|", m_indenterSettings->value(indenterParameter + "/ChoicesReadable").toString(), true); - if (choicesStringsReadable.isEmpty()) + if (!choicesReadableStrings.isEmpty()) { - comboBox->insertStringList(choicesStrings); + comboBox->insertStringList(choicesReadableStrings); + } + else if (!choicesRegexStrings.isEmpty()) + { + comboBox->insertStringList(choicesRegexStrings); } else { - comboBox->insertStringList(choicesStringsReadable); + comboBox->insertStringList(choicesStrings); } TQString paramToolTip = m_indenterSettings->value(indenterParameter + "/Description").toString(); TQToolTip::add(comboBox, paramToolTip); @@ -1244,11 +1203,11 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath) // remember parameter name and reference to its lineedit ParamMultiple paramMultiple; paramMultiple.paramName = indenterParameter; - paramMultiple.paramCallName = parameterCallName; paramMultiple.comboBox = comboBox; paramMultiple.choicesStrings = choicesStrings; - paramMultiple.choicesStringsReadable = choicesStringsReadable; - paramMultiple.valueEnabledChkBox = chkBox; + paramMultiple.choicesRegexStrings = choicesRegexStrings; + paramMultiple.choicesReadableStrings = choicesReadableStrings; + paramMultiple.valueEnabledChkBox = chkBox; paramMultiple.comboBox->setCurrentItem(m_indenterSettings->value(paramMultiple.paramName + "/ValueDefault").toInt()); m_paramMultiples.append(paramMultiple); diff --git a/src/IndentHandler.h b/src/IndentHandler.h index 5d77214..dfeb41e 100644 --- a/src/IndentHandler.h +++ b/src/IndentHandler.h @@ -90,7 +90,9 @@ class IndentHandler : public TQWidget { TQString paramName; TQString trueString; + TQString trueRegexString; TQString falseString; + TQString falseRegexString; TQCheckBox *checkBox; }; TQValueVector<ParamBoolean> m_paramBooleans; @@ -100,6 +102,7 @@ class IndentHandler : public TQWidget { TQString paramName; TQString paramCallName; + TQString paramCallNameRegex; TQCheckBox *valueEnabledChkBox; TQLineEdit *lineEdit; TQLabel *label; @@ -111,6 +114,7 @@ class IndentHandler : public TQWidget { TQString paramName; TQString paramCallName; + TQString paramCallNameRegex; TQCheckBox *valueEnabledChkBox; TQSpinBox *spinBox; TQLabel *label; @@ -121,11 +125,11 @@ class IndentHandler : public TQWidget struct ParamMultiple { TQString paramName; - TQString paramCallName; TQCheckBox *valueEnabledChkBox; TQComboBox *comboBox; TQStringList choicesStrings; - TQStringList choicesStringsReadable; + TQStringList choicesRegexStrings; + TQStringList choicesReadableStrings; }; TQValueVector<ParamMultiple> m_paramMultiples; @@ -162,7 +166,6 @@ class IndentHandler : public TQWidget TQString m_indenterExecutableCallString; TQString m_indenterExecutableSuffix; bool m_indenterProcessFinished; - bool m_useRegex; //TODO: This function should go into a string helper/tool class/file. TQString encodeToHTML(const TQString &text); |