mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-16 08:29:15 +01:00
LP-183 move toLowerCamelCase method to new string utility
This commit is contained in:
parent
57f0320605
commit
9c4c906765
49
ground/gcs/src/libs/utils/stringutils.cpp
Normal file
49
ground/gcs/src/libs/utils/stringutils.cpp
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
49
ground/gcs/src/libs/utils/stringutils.h
Normal file
49
ground/gcs/src/libs/utils/stringutils.h
Normal file
@ -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 <QString>
|
||||||
|
|
||||||
|
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 */
|
@ -14,6 +14,7 @@ DEFINES += PLUGIN_REL_PATH=$$shell_quote(\"$$relative_path($$GCS_PLUGIN_PATH, $$
|
|||||||
SOURCES += \
|
SOURCES += \
|
||||||
reloadpromptutils.cpp \
|
reloadpromptutils.cpp \
|
||||||
settingsutils.cpp \
|
settingsutils.cpp \
|
||||||
|
stringutils.cpp \
|
||||||
filesearch.cpp \
|
filesearch.cpp \
|
||||||
pathchooser.cpp \
|
pathchooser.cpp \
|
||||||
pathlisteditor.cpp \
|
pathlisteditor.cpp \
|
||||||
@ -59,6 +60,7 @@ SOURCES += \
|
|||||||
mustache.cpp \
|
mustache.cpp \
|
||||||
textbubbleslider.cpp
|
textbubbleslider.cpp
|
||||||
|
|
||||||
|
|
||||||
SOURCES += xmlconfig.cpp
|
SOURCES += xmlconfig.cpp
|
||||||
|
|
||||||
win32 {
|
win32 {
|
||||||
@ -74,6 +76,7 @@ HEADERS += \
|
|||||||
utils_global.h \
|
utils_global.h \
|
||||||
reloadpromptutils.h \
|
reloadpromptutils.h \
|
||||||
settingsutils.h \
|
settingsutils.h \
|
||||||
|
stringutils.h \
|
||||||
filesearch.h \
|
filesearch.h \
|
||||||
listutils.h \
|
listutils.h \
|
||||||
pathchooser.h \
|
pathchooser.h \
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
#include "uavobject.h"
|
#include "uavobject.h"
|
||||||
#include "flightbatterysettings.h"
|
#include "flightbatterysettings.h"
|
||||||
#include "utils/svgimageprovider.h"
|
#include "utils/svgimageprovider.h"
|
||||||
|
#include "utils/stringutils.h"
|
||||||
#ifdef USE_OSG
|
#ifdef USE_OSG
|
||||||
#include "osgearth.h"
|
#include "osgearth.h"
|
||||||
#endif
|
#endif
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSvgRenderer>
|
|
||||||
#include <QtOpenGL/QGLWidget>
|
#include <QtOpenGL/QGLWidget>
|
||||||
#include <QtCore/qfileinfo.h>
|
#include <QtCore/qfileinfo.h>
|
||||||
#include <QtCore/qdir.h>
|
#include <QtCore/qdir.h>
|
||||||
@ -33,36 +33,6 @@
|
|||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
|
|
||||||
/*
|
|
||||||
* 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) :
|
PfdQmlGadgetWidget::PfdQmlGadgetWidget(QWindow *parent) :
|
||||||
QQuickView(parent),
|
QQuickView(parent),
|
||||||
m_openGLEnabled(false),
|
m_openGLEnabled(false),
|
||||||
@ -121,7 +91,7 @@ PfdQmlGadgetWidget::PfdQmlGadgetWidget(QWindow *parent) :
|
|||||||
|
|
||||||
if (object) {
|
if (object) {
|
||||||
// expose object with lower camel case name
|
// expose object with lower camel case name
|
||||||
engine()->rootContext()->setContextProperty(toLowerCamelCase(objectName), object);
|
engine()->rootContext()->setContextProperty(Utils::toLowerCamelCase(objectName), object);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Failed to load object" << objectName;
|
qWarning() << "Failed to load object" << objectName;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user