From: Michal MalĂ˝ Date: Fri, 17 Apr 2015 17:17:55 +0000 (+0200) Subject: - Make DataWriterBackend::filename non-pure virtual and move the X-Git-Tag: 0.5c~9 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=78d973be0a3d52d4cb1b225ac840f6a31743d240;p=anyanka.git - Make DataWriterBackend::filename non-pure virtual and move the implementation currently used in CSVDataWriterBackend to base DataWriterBackend - Fix a bug where the last character in file name is cut if the file name contains a valid suffix for the currently selected output format --- diff --git a/csvdatawriterbackend.cpp b/csvdatawriterbackend.cpp index 1372426..1a8901d 100644 --- a/csvdatawriterbackend.cpp +++ b/csvdatawriterbackend.cpp @@ -39,28 +39,6 @@ QString CSVDataWriterBackend::header(const QVariantList& data) const return line + "\n"; } -QString CSVDataWriterBackend::filename(const QString& name, const QString& extra) const -{ - - QString newname; - int dotIdx; - - dotIdx = name.lastIndexOf('.'); - if (dotIdx > 0) { - QString suffix = name.mid(dotIdx+1).toLower(); - if (suffix.compare(FILE_EXTENSION) == 0) - newname = name.mid(0, dotIdx-1); /* Cut the suffix */ - else - newname = name; - } else - newname = name; - - if (extra.compare("") != 0) - return newname + "_" + extra + "." + FILE_EXTENSION; - else - return newname + "." + FILE_EXTENSION; -} - QString CSVDataWriterBackend::line(const QVariantList& data) const { QString line; diff --git a/csvdatawriterbackend.h b/csvdatawriterbackend.h index 9864b07..1fa4ebb 100644 --- a/csvdatawriterbackend.h +++ b/csvdatawriterbackend.h @@ -32,7 +32,6 @@ class CSVDataWriterBackend : public DataWriterBackend public: CSVDataWriterBackend(QObject* parent = nullptr); QString header(const QVariantList& data) const; - QString filename(const QString& name, const QString& extra) const; QString line(const QVariantList& data) const; private: diff --git a/datawriterbackend.cpp b/datawriterbackend.cpp index 072fce9..800386e 100644 --- a/datawriterbackend.cpp +++ b/datawriterbackend.cpp @@ -28,3 +28,24 @@ DataWriterBackend::DataWriterBackend(const QString& extension, QObject* parent) FILE_EXTENSION(extension) { } + +QString DataWriterBackend::filename(const QString& name, const QString& extra) const +{ + QString newname; + int dotIdx; + + dotIdx = name.lastIndexOf('.'); + if (dotIdx > 0) { + QString suffix = name.mid(dotIdx+1).toLower(); + if (suffix.compare(FILE_EXTENSION) == 0) + newname = name.mid(0, dotIdx); /* Cut the suffix */ + else + newname = name; + } else + newname = name; + + if (extra.compare("") != 0) + return newname + "_" + extra + "." + FILE_EXTENSION; + else + return newname + "." + FILE_EXTENSION; +} diff --git a/datawriterbackend.h b/datawriterbackend.h index 852e327..a4fc070 100644 --- a/datawriterbackend.h +++ b/datawriterbackend.h @@ -32,7 +32,7 @@ class DataWriterBackend : public QObject public: explicit DataWriterBackend(const QString& extension, QObject* parent = nullptr); virtual QString header(const QVariantList& data) const = 0; - virtual QString filename(const QString& name, const QString& extra = QString()) const = 0; + virtual QString filename(const QString& name, const QString& extra = QString()) const; virtual QString line(const QVariantList& data) const = 0; const QString FILE_EXTENSION;