2014-08-27 12:42:54 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vstringproperty.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 27 8, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2014-08-27 14:39:54 +02:00
|
|
|
** All rights reserved. This program and the accompanying materials
|
|
|
|
** are made available under the terms of the GNU Lesser General Public License
|
|
|
|
** (LGPL) version 2.1 which accompanies this distribution, and is available at
|
|
|
|
** http://www.gnu.org/licenses/lgpl-2.1.html
|
2014-08-27 12:42:54 +02:00
|
|
|
**
|
2014-08-27 14:39:54 +02:00
|
|
|
** This library is distributed in the hope that it will be useful,
|
2014-08-27 12:42:54 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2014-08-27 14:39:54 +02:00
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
** Lesser General Public License for more details.
|
2014-08-27 12:42:54 +02:00
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vstringproperty.h"
|
|
|
|
|
2016-08-23 20:24:14 +02:00
|
|
|
#include <QKeyEvent>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QLatin1String>
|
2014-08-27 12:42:54 +02:00
|
|
|
#include <QLineEdit>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QLocale>
|
2014-08-27 12:42:54 +02:00
|
|
|
#include <QSizePolicy>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QWidget>
|
2014-08-27 12:42:54 +02:00
|
|
|
|
2014-09-14 11:16:59 +02:00
|
|
|
#include "../vproperty_p.h"
|
2014-08-27 12:42:54 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
class QAbstractItemDelegate;
|
|
|
|
class QStyleOptionViewItem;
|
|
|
|
|
2014-08-27 12:42:54 +02:00
|
|
|
using namespace VPE;
|
|
|
|
|
|
|
|
|
|
|
|
VPE::VStringProperty::VStringProperty(const QString &name, const QMap<QString, QVariant> &settings)
|
2016-08-23 20:24:14 +02:00
|
|
|
: VProperty(name, QVariant::String), readOnly(false), typeForParent(0), clearButton(false), m_osSeparator(false)
|
2014-08-27 12:42:54 +02:00
|
|
|
{
|
|
|
|
VProperty::setSettings(settings);
|
2014-10-24 16:27:41 +02:00
|
|
|
d_ptr->VariantValue.setValue(QString());
|
2014-08-27 12:42:54 +02:00
|
|
|
d_ptr->VariantValue.convert(QVariant::String);
|
|
|
|
}
|
|
|
|
|
|
|
|
VPE::VStringProperty::VStringProperty(const QString &name)
|
2016-08-23 20:24:14 +02:00
|
|
|
: VProperty(name), readOnly(false), typeForParent(0), clearButton(false), m_osSeparator(false)
|
2014-08-27 12:42:54 +02:00
|
|
|
{
|
2014-10-24 16:27:41 +02:00
|
|
|
d_ptr->VariantValue.setValue(QString());
|
2014-08-27 12:42:54 +02:00
|
|
|
d_ptr->VariantValue.convert(QVariant::String);
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *VPE::VStringProperty::createEditor(QWidget *parent, const QStyleOptionViewItem &options,
|
|
|
|
const QAbstractItemDelegate *delegate)
|
|
|
|
{
|
|
|
|
Q_UNUSED(options);
|
|
|
|
Q_UNUSED(delegate);
|
|
|
|
|
|
|
|
QLineEdit* tmpEditor = new QLineEdit(parent);
|
2015-02-11 11:33:13 +01:00
|
|
|
tmpEditor->setLocale(parent->locale());
|
2014-08-27 12:42:54 +02:00
|
|
|
tmpEditor->setReadOnly(readOnly);
|
2016-08-23 20:24:14 +02:00
|
|
|
tmpEditor->installEventFilter(this);
|
2015-12-09 12:13:34 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
tmpEditor->setClearButtonEnabled(clearButton);
|
|
|
|
#endif
|
2014-08-27 12:42:54 +02:00
|
|
|
tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
tmpEditor->setText(d_ptr->VariantValue.toString());
|
|
|
|
|
|
|
|
d_ptr->editor = tmpEditor;
|
|
|
|
return d_ptr->editor;
|
|
|
|
}
|
|
|
|
|
2014-09-14 11:16:59 +02:00
|
|
|
QVariant VPE::VStringProperty::getEditorData(const QWidget *editor) const
|
2014-08-27 12:42:54 +02:00
|
|
|
{
|
2014-09-14 11:16:59 +02:00
|
|
|
const QLineEdit* tmpEditor = qobject_cast<const QLineEdit*>(editor);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpEditor)
|
|
|
|
{
|
2014-08-27 12:42:54 +02:00
|
|
|
return tmpEditor->text();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-08-27 12:42:54 +02:00
|
|
|
|
2014-10-24 16:27:41 +02:00
|
|
|
return QVariant(QString());
|
2014-08-27 12:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VPE::VStringProperty::setReadOnly(bool readOnly)
|
|
|
|
{
|
|
|
|
this->readOnly = readOnly;
|
|
|
|
}
|
|
|
|
|
2016-08-23 20:24:14 +02:00
|
|
|
void VStringProperty::setOsSeparator(bool separator)
|
|
|
|
{
|
|
|
|
m_osSeparator = separator;
|
|
|
|
}
|
|
|
|
|
2015-12-09 12:13:34 +01:00
|
|
|
void VStringProperty::setClearButtonEnable(bool value)
|
|
|
|
{
|
|
|
|
this->clearButton = value;
|
|
|
|
}
|
|
|
|
|
2014-08-27 12:42:54 +02:00
|
|
|
void VPE::VStringProperty::setSetting(const QString &key, const QVariant &value)
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (key == QLatin1String("ReadOnly"))
|
|
|
|
{
|
2014-08-27 12:42:54 +02:00
|
|
|
setReadOnly(value.toBool());
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
|
|
|
if (key == QLatin1String("TypeForParent"))
|
|
|
|
{
|
2014-08-29 11:19:11 +02:00
|
|
|
setTypeForParent(value.toInt());
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-08-27 12:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant VPE::VStringProperty::getSetting(const QString &key) const
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (key == QLatin1String("ReadOnly"))
|
|
|
|
{
|
2014-08-27 12:42:54 +02:00
|
|
|
return readOnly;
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-08-29 11:19:11 +02:00
|
|
|
else if (key == QLatin1String("TypeForParent"))
|
2014-09-10 19:57:08 +02:00
|
|
|
{
|
2014-08-29 11:19:11 +02:00
|
|
|
return typeForParent;
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-08-27 12:42:54 +02:00
|
|
|
else
|
|
|
|
return VProperty::getSetting(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList VPE::VStringProperty::getSettingKeys() const
|
|
|
|
{
|
2014-08-29 11:19:11 +02:00
|
|
|
QStringList settings;
|
|
|
|
settings << QStringLiteral("ReadOnly") << QStringLiteral("TypeForParent");
|
|
|
|
return settings;
|
2014-08-27 12:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString VPE::VStringProperty::type() const
|
|
|
|
{
|
2014-08-29 11:19:11 +02:00
|
|
|
return QStringLiteral("string");
|
2014-08-27 12:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VPE::VProperty *VPE::VStringProperty::clone(bool include_children, VPE::VProperty *container) const
|
|
|
|
{
|
2014-08-29 11:19:11 +02:00
|
|
|
return VProperty::clone(include_children, container ? container : new VStringProperty(getName(), getSettings()));
|
2014-08-27 12:42:54 +02:00
|
|
|
}
|
2014-08-29 11:19:11 +02:00
|
|
|
|
|
|
|
void VStringProperty::UpdateParent(const QVariant &value)
|
|
|
|
{
|
|
|
|
emit childChanged(value, typeForParent);
|
|
|
|
}
|
|
|
|
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-08-29 11:19:11 +02:00
|
|
|
int VStringProperty::getTypeForParent() const
|
|
|
|
{
|
|
|
|
return typeForParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VStringProperty::setTypeForParent(int value)
|
|
|
|
{
|
|
|
|
typeForParent = value;
|
|
|
|
}
|
2016-08-23 20:24:14 +02:00
|
|
|
|
|
|
|
bool VStringProperty::eventFilter(QObject *object, QEvent *event)
|
|
|
|
{
|
|
|
|
if (QLineEdit *textEdit = qobject_cast<QLineEdit *>(object))
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::KeyPress)
|
|
|
|
{
|
|
|
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
|
|
|
if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
|
|
|
|
{
|
|
|
|
if (m_osSeparator)
|
|
|
|
{
|
|
|
|
textEdit->insert(QLocale::system().decimalPoint());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textEdit->insert(QLocale::c().decimalPoint());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// pass the event on to the parent class
|
|
|
|
return VProperty::eventFilter(object, event);
|
|
|
|
}
|
|
|
|
return false;// pass the event to the widget
|
|
|
|
}
|