diff --git a/ground/gcs/src/libs/utils/stringutils.cpp b/ground/gcs/src/libs/utils/stringutils.cpp new file mode 100644 index 000000000..6e2dfbf17 --- /dev/null +++ b/ground/gcs/src/libs/utils/stringutils.cpp @@ -0,0 +1,49 @@ +/** + ****************************************************************************** + * + * @file pathutils.cpp + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015. + * @brief String utilities + * + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "stringutils.h" + +namespace Utils { +QString toLowerCamelCase(const QString & name) +{ + QString str = name; + + for (int i = 0; i < str.length(); ++i) { + if (str[i].isLower() || !str[i].isLetter()) { + break; + } + if (i > 0 && i < str.length() - 1) { + // after first, look ahead one + if (str[i + 1].isLower()) { + break; + } + } + str[i] = str[i].toLower(); + } + + return str; +} +} diff --git a/ground/gcs/src/libs/utils/stringutils.h b/ground/gcs/src/libs/utils/stringutils.h new file mode 100644 index 000000000..ad633dc40 --- /dev/null +++ b/ground/gcs/src/libs/utils/stringutils.h @@ -0,0 +1,49 @@ +/** + ****************************************************************************** + * + * @file stringutils.h + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015. + * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. + * @brief + * @see The GNU Public License (GPL) Version 3 + * @defgroup + * @{ + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef STRINGUTILS_H +#define STRINGUTILS_H + +#include "utils_global.h" + +#include + +namespace Utils { +/** + * Convert a string to lower camel case. + * Handles following cases : + * - Property -> property + * - MyProperty -> myProperty + * - MYProperty -> myProperty + * - MY_Property -> my_Property + * - MY -> my + */ +QTCREATOR_UTILS_EXPORT QString toLowerCamelCase(const QString &); +} + +#endif /* STRINGUTILS_H */ diff --git a/ground/gcs/src/libs/utils/utils.pro b/ground/gcs/src/libs/utils/utils.pro index 1e178077d..1cd671d33 100644 --- a/ground/gcs/src/libs/utils/utils.pro +++ b/ground/gcs/src/libs/utils/utils.pro @@ -14,6 +14,7 @@ DEFINES += PLUGIN_REL_PATH=$$shell_quote(\"$$relative_path($$GCS_PLUGIN_PATH, $$ SOURCES += \ reloadpromptutils.cpp \ settingsutils.cpp \ + stringutils.cpp \ filesearch.cpp \ pathchooser.cpp \ pathlisteditor.cpp \ @@ -59,6 +60,7 @@ SOURCES += \ mustache.cpp \ textbubbleslider.cpp + SOURCES += xmlconfig.cpp win32 { @@ -74,6 +76,7 @@ HEADERS += \ utils_global.h \ reloadpromptutils.h \ settingsutils.h \ + stringutils.h \ filesearch.h \ listutils.h \ pathchooser.h \ diff --git a/ground/gcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp b/ground/gcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp index 93072fcc0..1539e9848 100644 --- a/ground/gcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp +++ b/ground/gcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp @@ -20,11 +20,11 @@ #include "uavobject.h" #include "flightbatterysettings.h" #include "utils/svgimageprovider.h" +#include "utils/stringutils.h" #ifdef USE_OSG #include "osgearth.h" #endif #include -#include #include #include #include @@ -33,36 +33,6 @@ #include #include -/* - * Convert a string to lower camel case. - * Handles following cases : - * - Property -> property - * - MyProperty -> myProperty - * - MYProperty -> myProperty - * - MY_Property -> my_Property - * - MY -> my - */ -// TODO move to some utility class -QString toLowerCamelCase(const QString & name) -{ - QString str = name; - - for (int i = 0; i < str.length(); ++i) { - if (str[i].isLower() || !str[i].isLetter()) { - break; - } - if (i > 0 && i < str.length() - 1) { - // after first, look ahead one - if (str[i + 1].isLower()) { - break; - } - } - str[i] = str[i].toLower(); - } - - return str; -} - PfdQmlGadgetWidget::PfdQmlGadgetWidget(QWindow *parent) : QQuickView(parent), m_openGLEnabled(false), @@ -121,7 +91,7 @@ PfdQmlGadgetWidget::PfdQmlGadgetWidget(QWindow *parent) : if (object) { // expose object with lower camel case name - engine()->rootContext()->setContextProperty(toLowerCamelCase(objectName), object); + engine()->rootContext()->setContextProperty(Utils::toLowerCamelCase(objectName), object); } else { qWarning() << "Failed to load object" << objectName; }