Many improvements

PermGen can be tweaked from the settings menu
Groups are saved on change/exit
Install target is no longer completely broken
All the deplibs are now static
Added notes dialog
Fixed ini file format support (can save strings with newlines, tabs. UTF-8 is explicitly used!)
Rename button now uses line breaks so it doesn't grow ever wider (Added a custom tool button subclass)
There is now a CAT button. Meow.
This commit is contained in:
Petr Mrázek
2013-08-25 22:48:41 +02:00
parent d884f849d6
commit f0990fae4b
26 changed files with 512 additions and 96 deletions

View File

@ -46,6 +46,6 @@ include_directories(${LIBSETTINGS_INCLUDE_DIR})
add_definitions(-DLIBSETTINGS_LIBRARY)
add_library(libSettings SHARED ${LIBSETTINGS_SOURCES} ${LIBSETTINGS_HEADERS} ${LIBSETTINGS_HEADERS_PRIVATE})
add_library(libSettings STATIC ${LIBSETTINGS_SOURCES} ${LIBSETTINGS_HEADERS} ${LIBSETTINGS_HEADERS_PRIVATE})
qt5_use_modules(libSettings Core)
target_link_libraries(libSettings)

View File

@ -13,13 +13,11 @@
* limitations under the License.
*/
#ifndef INIFILE_H
#define INIFILE_H
#include <QMap>
#pragma once
#include <QString>
#include <QVariant>
#include "libsettings_config.h"
// Sectionless INI parser (for instance config files)
@ -33,6 +31,6 @@ public:
QVariant get(QString key, QVariant def) const;
void set(QString key, QVariant val);
QString unescape(QString orig);
QString escape(QString orig);
};
#endif // INIFILE_H

View File

@ -19,21 +19,40 @@
#include <QTextStream>
#include <QStringList>
INIFile::INIFile()
{
}
QString INIFile::unescape(QString orig)
{
orig.replace("\\n", "\n");
orig.replace("\\t", "\t");
orig.replace("\\\\", "\\");
return orig;
}
QString INIFile::escape(QString orig)
{
orig.replace("\\", "\\\\");
orig.replace("\n", "\\n");
orig.replace("\t", "\\t");
return orig;
}
bool INIFile::saveFile(QString fileName)
{
// TODO Handle errors.
QFile file(fileName);
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
out.setCodec("UTF-8");
for (Iterator iter = begin(); iter != end(); iter++)
{
out << iter.key() << "=" << iter.value().toString() << "\n";
QString value = iter.value().toString();
value = escape(value);
out << iter.key() << "=" << value << "\n";
}
return true;
@ -45,6 +64,7 @@ bool INIFile::loadFile(QString fileName)
QFile file(fileName);
file.open(QIODevice::ReadOnly);
QTextStream in(&file);
in.setCodec("UTF-8");
QStringList lines = in.readAll().split('\n');
for (int i = 0; i < lines.count(); i++)
@ -59,13 +79,9 @@ bool INIFile::loadFile(QString fileName)
QString key = line.left(eqPos).trimmed();
QString valueStr = line.right(line.length() - eqPos - 1).trimmed();
valueStr = unescape(valueStr);
QVariant value(valueStr);
/*
QString dbg = key;
dbg += " = ";
dbg += valueStr;
qDebug(dbg.toLocal8Bit());
*/
this->operator [](key) = value;
}