From 782e2cc2a279f87e6e949190d00e8a91b94518a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Sat, 15 Mar 2014 19:11:36 +0100 Subject: [PATCH] Make "Helpers" a full class --- datafileexporter.cpp | 2 +- gui/graphview.h | 1 - gui/signalview.cpp | 1 - helpers.h | 42 +++++++++++++++++++++++------------------- imagedrawer.cpp | 2 +- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/datafileexporter.cpp b/datafileexporter.cpp index 536152f..823b4b6 100644 --- a/datafileexporter.cpp +++ b/datafileexporter.cpp @@ -163,7 +163,7 @@ DataFileExporter::ReturnCode DataFileExporter::writeToFile(QFile& file, const Da void DataFileExporter::guessFormatFromSuffix(const QString& name) { - QString suffix = getFileNameSuffix(name); + QString suffix = Helpers::getFileNameSuffix(name); if (suffix.length() == 0) return; diff --git a/gui/graphview.h b/gui/graphview.h index 9e44c0e..2718ef7 100644 --- a/gui/graphview.h +++ b/gui/graphview.h @@ -26,7 +26,6 @@ #include "gui/graphviewcontextmenu.h" #include "signaldrawer.h" -#include "helpers.h" #include "metatypes.h" #include #include diff --git a/gui/signalview.cpp b/gui/signalview.cpp index 2b8d620..6edaeab 100644 --- a/gui/signalview.cpp +++ b/gui/signalview.cpp @@ -23,7 +23,6 @@ #include "gui/signalview.h" #include "ui_signalview.h" -#include "helpers.h" #include #include #include diff --git a/helpers.h b/helpers.h index c3b889a..f492ed2 100644 --- a/helpers.h +++ b/helpers.h @@ -26,29 +26,33 @@ #include -template static T average(T* vals, size_t len) { - T sum = 0; - for (size_t i = 0; i < len; i++) - sum += vals[i]; - return sum / len; -} -template static T clamp(T in, T min, T max) { - if (in < min) - return min; - if (in > max) - return max; -} +class Helpers { -static QString getFileNameSuffix(const QString& name) -{ - int dotIdx = name.lastIndexOf('.'); +public: + template static T average(T* vals, size_t len) { + T sum = 0; + for (size_t i = 0; i < len; i++) + sum += vals[i]; + return sum / len; + } - if (dotIdx < 0) - return ""; + template static T clamp(T in, T min, T max) { + if (in < min) + return min; + if (in > max) + return max; + } - return name.mid(dotIdx+1).toLower(); -} + static QString getFileNameSuffix(const QString& name) + { + int dotIdx = name.lastIndexOf('.'); + if (dotIdx < 0) + return ""; + return name.mid(dotIdx+1).toLower(); + } + +}; #endif // MATHHELPERS_H diff --git a/imagedrawer.cpp b/imagedrawer.cpp index af82ad6..e751a5f 100644 --- a/imagedrawer.cpp +++ b/imagedrawer.cpp @@ -94,7 +94,7 @@ QList ImageDrawer::supportedImageFormats() int ImageDrawer::guessFormatFromSuffix(const QString& name) { QList formats = ImageDrawer::supportedImageFormats(); - QString suffix = getFileNameSuffix(name); + QString suffix = Helpers::getFileNameSuffix(name); if (suffix.length() == 0) return -1; -- 2.43.5