return false;
};
- if (filename.contains(".xml"))
+ if (filename.endsWith(".xml",Qt::CaseInsensitive))
{
XMLParameterWriter writer(tree_widget); // create a xml writer
if (!writer.write_xml_file(&file)) // and write the xml file
return false;
}
- else if (filename.contains(".prm"))
+ else if (filename.endsWith(".prm",Qt::CaseInsensitive))
{
- PRMParameterWriter writer(tree_widget); // create a prm writer
+ PRMParameterWriter writer(tree_widget); // create a prm writer
if (!writer.write_prm_file(&file)) // and write the prm file
return false;
}
// loop over the elements
for (int i = 0; i < tree_widget->topLevelItemCount(); ++i)
{
- const QString item_string = write_item(tree_widget->topLevelItem(i),0);
+ const QString item_string = item_to_string(tree_widget->topLevelItem(i),0);
device->write(item_string.toAscii());
}
- QString PRMParameterWriter::write_item(const QTreeWidgetItem *item,
- const unsigned int indentation_level)
+ QString PRMParameterWriter::item_to_string(const QTreeWidgetItem *item,
+ const unsigned int indentation_level)
{
QString item_string;
{ // we have a parameter
bool non_default_value;
- if (item->text(5).contains("Double"))
+ if (item->text(5).startsWith("[Double"))
non_default_value = item->data(1,Qt::DisplayRole).toReal() != item->data(2,Qt::DisplayRole).toReal();
else
non_default_value = item->data(1,Qt::DisplayRole).toString() != item->data(2,Qt::DisplayRole).toString();
else
{
for (int i = 0; i < item->childCount(); ++i)
- item_string.push_back(write_item(item->child(i),indentation_level+1));
+ item_string.push_back(item_to_string(item->child(i),indentation_level+1));
if (!item_string.isEmpty())
{
private:
/**
- * This function writes a given @p item of <tt>tree_widget</tt>
- * to a file in prm format.
- * If the @p item is a parameter it is written if its value differs
+ * This function creates a string that corresponds to the data written
+ * to a prm file for a given @p item of <tt>tree_widget</tt>.
+ * If the @p item is a parameter it is only written if its value differs
* from its default value. If the @p item is a subsection, a start element
* <code>subsection</code> is written and <tt>write_item</tt> is called
* recursively to write the next <tt>item</tt>.
- * If not items in this subsection differ from their default value then
+ * If no items in this subsection differ from their default values then
* the subsection is not written.
* @p indentation_level describes the level the current item belongs to.
* 0 describes a top level item and each subsection increases the level
* by one.
*
*/
- QString write_item (const QTreeWidgetItem *item,
- const unsigned int indentation_level);
+ QString item_to_string (const QTreeWidgetItem *item,
+ const unsigned int indentation_level);
/**
* A pointer to the QTreeWidget structure