summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2023-06-28 17:02:19 +0900
committerMichele Calgaro <[email protected]>2023-06-28 17:02:19 +0900
commit97a6a7874e936017a833c68701b3adf7f709e675 (patch)
treee68430f37198ac8cf3f035a61b794008bcb7a929
parentfebcebba0742e2c2029259a8cca2076ce792a428 (diff)
downloaduniversal-indent-gui-tqt-97a6a7874e936017a833c68701b3adf7f709e675.tar.gz
universal-indent-gui-tqt-97a6a7874e936017a833c68701b3adf7f709e675.zip
Added logic to load/save indenter config file
Signed-off-by: Michele Calgaro <[email protected]>
-rw-r--r--src/IndentHandler.cpp485
1 files changed, 241 insertions, 244 deletions
diff --git a/src/IndentHandler.cpp b/src/IndentHandler.cpp
index f3eec88..62745e2 100644
--- a/src/IndentHandler.cpp
+++ b/src/IndentHandler.cpp
@@ -608,57 +608,58 @@ TQString IndentHandler::getParameterString()
{
TQString parameterString = "";
-//--- // generate parameter string for all boolean values
-//--- foreach(ParamBoolean pBoolean, m_paramBooleans)
-//--- {
-//--- if (pBoolean.checkBox->isChecked())
-//--- {
-//--- if (!pBoolean.trueString.isEmpty())
-//--- {
-//--- parameterString += pBoolean.trueString + m_cfgFileParameterEnding;
-//--- }
-//--- }
-//--- else
-//--- {
-//--- if (!pBoolean.falseString.isEmpty())
-//--- {
-//--- parameterString += pBoolean.falseString + m_cfgFileParameterEnding;
-//--- }
-//--- }
-//--- }
-//---
-//--- // generate parameter string for all numeric values
-//--- foreach(ParamNumeric pNumeric, m_paramNumerics)
-//--- {
-//--- if (pNumeric.valueEnabledChkBox->isChecked())
-//--- {
-//--- parameterString += pNumeric.paramCallName + TQString::number(pNumeric.spinBox->value()) +
-//--- m_cfgFileParameterEnding;
-//--- }
-//--- }
-//---
-//--- // generate parameter string for all string values
-//--- foreach(ParamString pString, m_paramStrings)
-//--- {
-//--- if (!pString.lineEdit->text().isEmpty() && pString.valueEnabledChkBox->isChecked())
-//--- {
-//--- // Create parameter definition for each value devided by a | sign.
-//--- foreach(TQString paramValue, pString.lineEdit->text().split("|"))
-//--- {
-//--- parameterString += pString.paramCallName + paramValue + m_cfgFileParameterEnding;
-//--- }
-//--- }
-//--- }
-//---
-//--- // generate parameter string for all multiple choice values
-//--- foreach(ParamMultiple pMultiple, m_paramMultiples)
-//--- {
-//--- if (pMultiple.valueEnabledChkBox->isChecked())
-//--- {
-//--- parameterString += pMultiple.choicesStrings.at(pMultiple.comboBox->currentIndex()) +
-//--- m_cfgFileParameterEnding;
-//--- }
-//--- }
+ // generate parameter string for all boolean values
+ for (const ParamBoolean &pBoolean : m_paramBooleans)
+ {
+ if (pBoolean.checkBox->isChecked())
+ {
+ if (!pBoolean.trueString.isEmpty())
+ {
+ parameterString += pBoolean.trueString + m_cfgFileParameterEnding;
+ }
+ }
+ else
+ {
+ if (!pBoolean.falseString.isEmpty())
+ {
+ parameterString += pBoolean.falseString + m_cfgFileParameterEnding;
+ }
+ }
+ }
+
+ // generate parameter string for all numeric values
+ for (const ParamNumeric &pNumeric : m_paramNumerics)
+ {
+ if (pNumeric.valueEnabledChkBox->isChecked())
+ {
+ parameterString += pNumeric.paramCallName + TQString::number(pNumeric.spinBox->value()) +
+ m_cfgFileParameterEnding;
+ }
+ }
+
+ // generate parameter string for all string values
+ for (const ParamString &pString : m_paramStrings)
+ {
+ if (!pString.lineEdit->text().isEmpty() && pString.valueEnabledChkBox->isChecked())
+ {
+ // Create parameter definition for each value devided by a | sign.
+ TQStringList pStringList = TQStringList::split("|", pString.lineEdit->text());
+ for (const TQString &paramValue : pStringList)
+ {
+ parameterString += pString.paramCallName + paramValue + m_cfgFileParameterEnding;
+ }
+ }
+ }
+
+ // generate parameter string for all multiple choice values
+ for (const ParamMultiple &pMultiple : m_paramMultiples)
+ {
+ if (pMultiple.valueEnabledChkBox->isChecked())
+ {
+ parameterString += pMultiple.choicesStrings[pMultiple.comboBox->currentItem()] +
+ m_cfgFileParameterEnding;
+ }
+ }
return parameterString;
}
@@ -697,180 +698,180 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName)
cfgFile.close();
}
-//--- // 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 paramValue = false;
-//---
-//--- // first search for the longer parameter string
-//--- // the true parameter string is longer than the false string
-//--- if (pBoolean.trueString.length() > pBoolean.falseString.length())
-//--- {
-//--- // search for the true string
-//--- index = cfgFileData.indexOf(pBoolean.trueString, 0, TQt::CaseInsensitive);
-//--- // 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
-//--- {
-//--- index = cfgFileData.indexOf(pBoolean.falseString, 0, TQt::CaseInsensitive);
-//--- // if false string found set the parameter value to false
-//--- if (index != -1)
-//--- {
-//--- paramValue = false;
-//--- }
-//--- // neither true nor false parameter found so use default value
-//--- else
-//--- {
-//--- paramValue = m_indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool();
-//--- }
-//--- }
-//--- }
-//--- // the false parameter string is longer than the true string
-//--- else
-//--- {
-//--- // search for the false string
-//--- index = cfgFileData.indexOf(pBoolean.falseString, 0, TQt::CaseInsensitive);
-//--- // if false string found set the parameter value to false
-//--- if (index != -1)
-//--- {
-//--- paramValue = false;
-//--- }
-//--- // if false string not found, search for true string
-//--- else
-//--- {
-//--- index = cfgFileData.indexOf(pBoolean.trueString, 0, TQt::CaseInsensitive);
-//--- // if true string found set the parameter value to true
-//--- if (index != -1)
-//--- {
-//--- paramValue = true;
-//--- }
-//--- // neither true nor false parameter found so use default value
-//--- else
-//--- {
-//--- paramValue = m_indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool();
-//--- }
-//--- }
-//--- }
-//--- pBoolean.checkBox->setChecked(paramValue);
-//--- }
-//---
-//--- // Search for name of each numeric parameter and set the value found behind it.
-//--- foreach(ParamNumeric pNumeric, m_paramNumerics)
-//--- {
-//--- index = cfgFileData.indexOf(pNumeric.paramCallName, 0, TQt::CaseInsensitive);
-//--- // parameter was found in config file
-//--- if (index != -1)
-//--- {
-//--- // set index after the parameter name, so in front of the number
-//--- 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 = cfgFileData.indexOf(m_cfgFileParameterEnding, index + 1);
-//---
-//--- // get the number and convert it to int
-//--- TQString test = cfgFileData.mid(index, crPos - index);
-//--- 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);
-//--- }
-//--- }
-//---
-//--- // Search for name of each string parameter and set it.
-//--- foreach(ParamString pString, m_paramStrings)
-//--- {
-//--- paramValueStr = "";
-//--- // The number of the found values for this parameter name.
-//--- int numberOfValues = 0;
-//--- index = cfgFileData.indexOf(pString.paramCallName, 0, TQt::CaseInsensitive);
-//--- // If parameter was found in config file
-//--- if (index != -1)
-//--- {
-//--- while (index != -1)
-//--- {
-//--- numberOfValues++;
-//---
-//--- // Set index after the parameter name, so it points to the front of the string value.
-//--- index += pString.paramCallName.length();
-//---
-//--- // Find the end of the parameter by searching for set config file parameter ending. Most of
-//--- // time this is a carriage return.
-//--- crPos = cfgFileData.indexOf(m_cfgFileParameterEnding, index + 1);
-//---
-//--- // Get the string and remember it.
-//--- if (numberOfValues < 2)
-//--- {
-//--- paramValueStr = TQString(cfgFileData.mid(index, crPos - index));
-//--- }
-//--- // If the same parameter has been set multiple times, concatenate the strings dvivided by a
-//--- // |.
-//--- else
-//--- {
-//--- paramValueStr = paramValueStr + "|" + TQString(cfgFileData.mid(index, crPos - index));
-//--- }
-//---
-//--- // Get next value for this setting, if one exists.
-//--- index = cfgFileData.indexOf(pString.paramCallName, crPos + 1, TQt::CaseInsensitive);
-//--- }
-//--- // Set the text for the line edit.
-//--- pString.lineEdit->setText(paramValueStr);
-//--- pString.valueEnabledChkBox->setChecked(true);
-//--- }
-//--- // Parameter was not found in config file
-//--- else
-//--- {
-//--- paramValueStr = m_indenterSettings->value(pString.paramName + "/ValueDefault").toString();
-//--- pString.lineEdit->setText(paramValueStr);
-//--- pString.valueEnabledChkBox->setChecked(false);
-//--- }
-//--- }
-//---
-//--- // search for name of each multiple choice parameter and set it
-//--- foreach(ParamMultiple pMultiple, m_paramMultiples)
-//--- {
-//--- int i = 0;
-//--- index = -1;
-//---
-//--- // 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)
-//--- {
-//--- index = cfgFileData.indexOf(pMultiple.choicesStrings.at(i), 0, TQt::CaseInsensitive);
-//--- if (index != -1)
-//--- {
-//--- pMultiple.comboBox->setCurrentIndex(i);
-//--- pMultiple.valueEnabledChkBox->setChecked(true);
-//--- }
-//--- i++;
-//--- }
-//---
-//--- // parameter was not set in config file, so use default value
-//--- if (index == -1)
-//--- {
-//--- int defaultValue = m_indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt();
-//--- pMultiple.comboBox->setCurrentIndex(defaultValue);
-//--- pMultiple.valueEnabledChkBox->setChecked(false);
-//--- }
-//--- }
+ // 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 paramValue = false;
+
+ // first search for the longer parameter string
+ // the true parameter string is longer than the false string
+ if (pBoolean.trueString.length() > pBoolean.falseString.length())
+ {
+ // search for the true string
+ int 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
+ {
+ index = cfgFileData.find(pBoolean.falseString, 0, false);
+ // if false string found set the parameter value to false
+ if (index != -1)
+ {
+ paramValue = false;
+ }
+ // neither true nor false parameter found so use default value
+ else
+ {
+ paramValue = m_indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool();
+ }
+ }
+ }
+ // the false parameter string is longer than the true string
+ else
+ {
+ // search for the false string
+ int index = cfgFileData.find(pBoolean.falseString, 0, false);
+ // if false string found set the parameter value to false
+ if (index != -1)
+ {
+ paramValue = false;
+ }
+ // if false string not found, search for true string
+ else
+ {
+ index = cfgFileData.find(pBoolean.trueString, 0, false);
+ // if true string found set the parameter value to true
+ if (index != -1)
+ {
+ paramValue = true;
+ }
+ // neither true nor false parameter found so use default value
+ else
+ {
+ paramValue = m_indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool();
+ }
+ }
+ }
+ pBoolean.checkBox->setChecked(paramValue);
+ }
+
+ // Search for name of each numeric parameter and set the value found behind it.
+ for(const ParamNumeric &pNumeric : m_paramNumerics)
+ {
+ int index = cfgFileData.find(pNumeric.paramCallName, 0, false);
+ // parameter was found in config file
+ if (index != -1)
+ {
+ // set index after the parameter name, so in front of the number
+ 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 = cfgFileData.find(m_cfgFileParameterEnding, index + 1);
+
+ // get the number and convert it to int
+ TQString test = cfgFileData.mid(index, crPos - index);
+ 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);
+ }
+ }
+
+ // 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;
+ int index = cfgFileData.find(pString.paramCallName, 0, false);
+ // If parameter was found in config file
+ if (index != -1)
+ {
+ TQString paramValueStr = TQString::null;
+ while (index != -1)
+ {
+ numberOfValues++;
+
+ // Set index after the parameter name, so it points to the front of the string value.
+ index += pString.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 = cfgFileData.find(m_cfgFileParameterEnding, index + 1);
+
+ // Get the string and remember it.
+ if (numberOfValues < 2)
+ {
+ paramValueStr = TQString(cfgFileData.mid(index, crPos - index));
+ }
+ // If the same parameter has been set multiple times, concatenate the strings dvivided by a
+ // |.
+ else
+ {
+ paramValueStr = paramValueStr + "|" + TQString(cfgFileData.mid(index, crPos - index));
+ }
+
+ // Get next value for this setting, if one exists.
+ index = cfgFileData.find(pString.paramCallName, crPos + 1, false);
+ }
+ // Set the text for the line edit.
+ pString.lineEdit->setText(paramValueStr);
+ pString.valueEnabledChkBox->setChecked(true);
+ }
+ // Parameter was not found in config file
+ else
+ {
+ pString.lineEdit->setText(m_indenterSettings->value(pString.paramName +
+ "/ValueDefault").toString());
+ pString.valueEnabledChkBox->setChecked(false);
+ }
+ }
+
+ // search for name of each multiple choice parameter and set it
+ for (const ParamMultiple &pMultiple : m_paramMultiples)
+ {
+ int i = 0;
+ int index = -1;
+
+ // 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)
+ {
+ index = cfgFileData.find(pMultiple.choicesStrings[i], 0, false);
+ if (index != -1)
+ {
+ pMultiple.comboBox->setCurrentItem(i);
+ pMultiple.valueEnabledChkBox->setChecked(true);
+ }
+ i++;
+ }
+
+ // parameter was not set in config file, so use default value
+ if (index == -1)
+ {
+ int defaultValue = m_indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt();
+ pMultiple.comboBox->setCurrentItem(defaultValue);
+ pMultiple.valueEnabledChkBox->setChecked(false);
+ }
+ }
return true;
}
@@ -984,7 +985,6 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath)
// create a page for each category and store its references in a toolboxpage-array
for (const TQString &category : categories)
{
- tqWarning("Creating category "+category);
categoryPage.widget = new TQWidget();
categoryPage.widget->setName(category.local8Bit());
categoryPage.widget->setSizePolicy(TQSizePolicy::MinimumExpanding,
@@ -1556,10 +1556,10 @@ void IndentHandler::showIndenterManual() const
//--- TQString currentIndenterName = m_indenterSelectionCombobox->currentText();
//---
//--- // Remove the supported programming languages from indenters name, which are set in braces.
-//--- if (currentIndenterName.indexOf("(") > 0)
+//--- if (currentIndenterName.find("(") > 0)
//--- {
//--- // Using index-1 to also leave out the blank before the brace.
-//--- currentIndenterName = currentIndenterName.left(currentIndenterName.indexOf("(") - 1);
+//--- currentIndenterName = currentIndenterName.left(currentIndenterName.find("(") - 1);
//--- }
//---
//--- return currentIndenterName;
@@ -1572,7 +1572,7 @@ void IndentHandler::showIndenterManual() const
*/
void IndentHandler::openConfigFileDialog()
{
- TQString configFilePath = TQFileDialog::getOpenFileName(getIndenterCfgFile(), "All files (*.*)",
+ TQString configFilePath = TQFileDialog::getOpenFileName(getIndenterCfgFile(), tr("All files (*.*)"),
nullptr, nullptr, tr("Choose indenter config file"));
if (!configFilePath.isEmpty())
@@ -1591,21 +1591,18 @@ void IndentHandler::openConfigFileDialog()
*/
void IndentHandler::saveasIndentCfgFileDialog()
{
-//--- TQString fileExtensions = tr("All files") + " (*.*)";
-//---
-//--- //TQString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./",
-//--- // fileExtensions );
-//--- TQString fileName = TQFileDialog::getSaveFileName(this, tr(
-//--- "Save indent config file"), getIndenterCfgFile(), fileExtensions);
-//---
-//--- if (fileName != "")
-//--- {
-//--- TQFile::remove(fileName);
-//--- TQFile outCfgFile(fileName);
-//--- outCfgFile.open(TQFile::ReadWrite | TQFile::Text);
-//--- outCfgFile.write(getParameterString().toAscii());
-//--- outCfgFile.close();
-//--- }
+ TQString fileName = TQFileDialog::getSaveFileName(getIndenterCfgFile(), tr("All files (*.*)"),
+ nullptr, nullptr, tr("Save indent config file"));
+
+ if (!fileName.isEmpty())
+ {
+ TQFile::remove(fileName);
+ TQFile outCfgFile(fileName);
+ outCfgFile.open(IO_ReadWrite | IO_Translate);
+ TQCString paramCString = getParameterString().local8Bit();
+ outCfgFile.writeBlock(paramCString.data(), paramCString.length());
+ outCfgFile.close();
+ }
}
/*