Add notes for the base point tool to property browser.

This commit is contained in:
Roman Telezhynskyi 2020-10-27 18:26:33 +02:00
parent fe8552cec1
commit de401b2d06
11 changed files with 295 additions and 16 deletions

View File

@ -897,6 +897,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolSinglePoint(VPE::VProperty *prop
case 1: // QLatin1String("position") case 1: // QLatin1String("position")
i->SetBasePointPos(value.toPointF()); i->SetBasePointPos(value.toPointF());
break; break;
case 61: // AttrNotes
i->SetNotes(value.toString());
break;
default: default:
qWarning()<<"Unknown property type. id = "<<id; qWarning()<<"Unknown property type. id = "<<id;
break; break;
@ -1986,6 +1989,10 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSinglePoint(QGraphicsItem *item
VPE::VPointFProperty* itemPosition = new VPE::VPointFProperty(tr("Position:")); VPE::VPointFProperty* itemPosition = new VPE::VPointFProperty(tr("Position:"));
itemPosition->setValue(i->GetBasePointPos()); itemPosition->setValue(i->GetBasePointPos());
AddProperty(itemPosition, QLatin1String("position")); AddProperty(itemPosition, QLatin1String("position"));
VPE::VTextProperty* itemNotes = new VPE::VTextProperty(tr("Notes:"));
itemNotes->setValue(i->GetNotes());
AddProperty(itemNotes, AttrNotes);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -2501,6 +2508,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint()
VToolBasePoint *i = qgraphicsitem_cast<VToolBasePoint *>(currentItem); VToolBasePoint *i = qgraphicsitem_cast<VToolBasePoint *>(currentItem);
idToProperty[AttrName]->setValue(i->name()); idToProperty[AttrName]->setValue(i->name());
idToProperty[QLatin1String("position")]->setValue(i->GetBasePointPos()); idToProperty[QLatin1String("position")]->setValue(i->GetBasePointPos());
idToProperty[AttrNotes]->setValue(i->GetNotes());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -3406,6 +3414,7 @@ QStringList VToolOptionsPropertyBrowser::PropertiesList() const
<< AttrPoint3 /* 57 */ << AttrPoint3 /* 57 */
<< AttrPoint4 /* 58 */ << AttrPoint4 /* 58 */
<< AttrPenStyle /* 59 */ << AttrPenStyle /* 59 */
<< AttrAScale; /* 60 */ << AttrAScale /* 60 */
<< AttrNotes; /* 61 */
return attr; return attr;
} }

View File

@ -0,0 +1,134 @@
/************************************************************************
**
** @file vtextproperty.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 27 10, 2020
**
** @brief
** @copyright
** 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
**
** This library 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
** Lesser General Public License for more details.
**
*************************************************************************/
#include "vtextproperty.h"
#include "../vproperty_p.h"
#include <QPlainTextEdit>
#include <QTextEdit>
namespace
{
//---------------------------------------------------------------------------------------------------------------------
void SetTabStopDistance(QPlainTextEdit *edit, int tabWidthChar=4);
void SetTabStopDistance(QPlainTextEdit *edit, int tabWidthChar)
{
const auto fontMetrics = edit->fontMetrics();
const QString testString(" ");
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
const int singleCharWidth = fontMetrics.width(testString);
edit->setTabStopWidth(tabWidthChar * singleCharWidth);
#else
// compute the size of a char in double-precision
static constexpr int bigNumber = 1000; // arbitrary big number.
const int many_char_width = fontMetrics.width(testString.repeated(bigNumber));
const double singleCharWidthDouble = many_char_width / double(bigNumber);
// set the tab stop with double precision
edit->setTabStopDistance(tabWidthChar * singleCharWidthDouble);
#endif
}
}
VPE::VTextProperty::VTextProperty(const QString &name, const QMap<QString, QVariant> &settings)
: VProperty(name, QVariant::String),
readOnly(false)
{
VProperty::setSettings(settings);
d_ptr->VariantValue.setValue(QString());
d_ptr->VariantValue.convert(QVariant::String);
}
VPE::VTextProperty::VTextProperty(const QString &name)
: VProperty(name),
readOnly(false)
{
d_ptr->VariantValue.setValue(QString());
d_ptr->VariantValue.convert(QVariant::String);
}
QWidget *VPE::VTextProperty::createEditor(QWidget *parent, const QStyleOptionViewItem &options,
const QAbstractItemDelegate *delegate)
{
Q_UNUSED(options)
Q_UNUSED(delegate)
QPlainTextEdit* tmpEditor = new QPlainTextEdit(parent);
tmpEditor->setLocale(parent->locale());
tmpEditor->setReadOnly(readOnly);
tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tmpEditor->setPlainText(d_ptr->VariantValue.toString());
SetTabStopDistance(tmpEditor);
d_ptr->editor = tmpEditor;
return d_ptr->editor;
}
QVariant VPE::VTextProperty::getEditorData(const QWidget *editor) const
{
const QPlainTextEdit* tmpEditor = qobject_cast<const QPlainTextEdit*>(editor);
if (tmpEditor)
{
return tmpEditor->toPlainText();
}
return QVariant(QString());
}
void VPE::VTextProperty::setReadOnly(bool readOnly)
{
this->readOnly = readOnly;
}
void VPE::VTextProperty::setSetting(const QString &key, const QVariant &value)
{
if (key == QLatin1String("ReadOnly"))
{
setReadOnly(value.toBool());
}
}
QVariant VPE::VTextProperty::getSetting(const QString &key) const
{
if (key == QLatin1String("ReadOnly"))
{
return readOnly;
}
else
return VProperty::getSetting(key);
}
QStringList VPE::VTextProperty::getSettingKeys() const
{
QStringList settings;
settings << QStringLiteral("ReadOnly");
return settings;
}
QString VPE::VTextProperty::type() const
{
return QStringLiteral("string");
}
VPE::VProperty *VPE::VTextProperty::clone(bool include_children, VPE::VProperty *container) const
{
return VProperty::clone(include_children, container ? container : new VTextProperty(getName(), getSettings()));
}

View File

@ -0,0 +1,88 @@
/************************************************************************
**
** @file vtextproperty.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 27 10, 2020
**
** @brief
** @copyright
** 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
**
** This library 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
** Lesser General Public License for more details.
**
*************************************************************************/
#ifndef VTEXTPROPERTY_H
#define VTEXTPROPERTY_H
#include <qcompilerdetection.h>
#include <QMap>
#include <QMetaObject>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QStyleOptionViewItem>
#include <QVariant>
#include <QtGlobal>
#include "../vproperty.h"
#include "../vpropertyexplorer_global.h"
namespace VPE
{
//! Class for holding a text property
class VPROPERTYEXPLORERSHARED_EXPORT VTextProperty : public VProperty
{
public:
VTextProperty(const QString& name, const QMap<QString, QVariant>& settings);
explicit VTextProperty(const QString& name);
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate) override;
//! Gets the data from the widget
virtual QVariant getEditorData(const QWidget* editor) const override;
void setReadOnly(bool readOnly);
//! Sets the settings.
virtual void setSetting(const QString& key, const QVariant& value) override;
//! Get the settings. This function has to be implemented in a subclass in order to have an effect
virtual QVariant getSetting(const QString& key) const override;
//! Returns the list of keys of the property's settings
virtual QStringList getSettingKeys() const override;
//! Returns a string containing the type of the property
virtual QString type() const override;
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
Q_REQUIRED_RESULT virtual VProperty* clone(bool include_children = true,
VProperty* container = nullptr) const override;
protected:
bool readOnly;
private:
Q_DISABLE_COPY(VTextProperty)
};
}
#endif // VTEXTPROPERTY_H

View File

@ -37,5 +37,6 @@
#include "plugins/vwidgetproperty.h" #include "plugins/vwidgetproperty.h"
#include "plugins/vlinecolorproperty.h" #include "plugins/vlinecolorproperty.h"
#include "plugins/vlabelproperty.h" #include "plugins/vlabelproperty.h"
#include "plugins/vtextproperty.h"
#endif // VPROPERTIES_H #endif // VPROPERTIES_H

View File

@ -2,6 +2,7 @@
# This need for corect working file translations.pro # This need for corect working file translations.pro
SOURCES += \ SOURCES += \
$$PWD/plugins/vtextproperty.cpp \
$$PWD/vproperty.cpp \ $$PWD/vproperty.cpp \
$$PWD/vpropertydelegate.cpp \ $$PWD/vpropertydelegate.cpp \
$$PWD/vpropertyfactorymanager.cpp \ $$PWD/vpropertyfactorymanager.cpp \
@ -35,6 +36,7 @@ SOURCES += \
*msvc*:SOURCES += $$PWD/stable.cpp *msvc*:SOURCES += $$PWD/stable.cpp
HEADERS +=\ HEADERS +=\
$$PWD/plugins/vtextproperty.h \
$$PWD/vpropertyexplorer_global.h \ $$PWD/vpropertyexplorer_global.h \
$$PWD/vpropertyfactorymanager_p.h \ $$PWD/vpropertyfactorymanager_p.h \
$$PWD/vpropertytreeview_p.h \ $$PWD/vpropertytreeview_p.h \

View File

@ -26,6 +26,7 @@
#include <QLayout> #include <QLayout>
#include <QLayoutItem> #include <QLayoutItem>
#include <QMargins> #include <QMargins>
#include <QPlainTextEdit>
#include <QStyleOptionViewItem> #include <QStyleOptionViewItem>
#include <QVariant> #include <QVariant>
#include <QWidget> #include <QWidget>
@ -303,6 +304,24 @@ bool VPE::VPropertyFormWidget::eventFilter(QObject *object, QEvent *event)
} }
if (event->type() == QEvent::KeyPress) if (event->type() == QEvent::KeyPress)
{
if (QPlainTextEdit *textEdit = qobject_cast<QPlainTextEdit *>(editor))
{
switch (static_cast<QKeyEvent *>(event)->key())
{
case Qt::Key_Escape:
commitData(editor);
event->accept();
return true;
case Qt::Key_Tab:
case Qt::Key_Backtab:
case Qt::Key_Enter:
case Qt::Key_Return:
default:
return false;
}
}
else
{ {
switch (static_cast<QKeyEvent *>(event)->key()) switch (static_cast<QKeyEvent *>(event)->key())
{ {
@ -318,6 +337,8 @@ bool VPE::VPropertyFormWidget::eventFilter(QObject *object, QEvent *event)
return false; return false;
} }
} }
return false;
}
else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow())) else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow()))
{ {
commitData(editor); commitData(editor);

View File

@ -486,3 +486,24 @@ void CurrentCurveLength(vidtype curveId, VContainer *data)
data->AddVariable(length); data->AddVariable(length);
} }
//---------------------------------------------------------------------------------------------------------------------
void SetTabStopDistance(QPlainTextEdit *edit, int tabWidthChar)
{
SCASSERT(edit != nullptr)
const auto fontMetrics = edit->fontMetrics();
const QString testString(" ");
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
const int single_char_width = fontMetrics.width(testString);
edit->setTabStopWidth(tabWidthChar * single_char_width);
#else
// compute the size of a char in double-precision
static constexpr int bigNumber = 1000; // arbitrary big number.
const int many_char_width = fontMetrics.width(testString.repeated(bigNumber));
const double singleCharWidthDouble = many_char_width / double(bigNumber);
// set the tab stop with double precision
edit->setTabStopDistance(tabWidthChar * singleCharWidthDouble);
#endif
}

View File

@ -86,5 +86,6 @@ bool EachPointLabelIsUnique(QListWidget *listWidget);
QString DialogWarningIcon(); QString DialogWarningIcon();
QFont NodeFont(QFont font, bool nodeExcluded = false); QFont NodeFont(QFont font, bool nodeExcluded = false);
void CurrentCurveLength(vidtype curveId, VContainer *data); void CurrentCurveLength(vidtype curveId, VContainer *data);
void SetTabStopDistance(QPlainTextEdit *edit, int tabWidthChar=4);
#endif // DIALOGTOOLBOX_H #endif // DIALOGTOOLBOX_H

View File

@ -64,6 +64,7 @@ DialogSinglePoint::DialogSinglePoint(const VContainer *data, quint32 toolId, QWi
}); });
ui->tabWidget->setCurrentIndex(0); ui->tabWidget->setCurrentIndex(0);
SetTabStopDistance(ui->plainTextEditToolNotes);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -134,11 +135,11 @@ QString DialogSinglePoint::GetPointName() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSinglePoint::SetNotes(const QString &notes) void DialogSinglePoint::SetNotes(const QString &notes)
{ {
ui->textEditToolNotes->setText(notes); ui->plainTextEditToolNotes->setPlainText(notes);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogSinglePoint::GetNotes() const QString DialogSinglePoint::GetNotes() const
{ {
return ui->textEditToolNotes->toPlainText(); return ui->plainTextEditToolNotes->toPlainText();
} }

View File

@ -126,7 +126,7 @@
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QTextEdit" name="textEditToolNotes"/> <widget class="QPlainTextEdit" name="plainTextEditToolNotes"/>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -374,6 +374,7 @@ void VToolBasePoint::ShowContextMenu(QGraphicsSceneContextMenuEvent *event, quin
*/ */
void VToolBasePoint::FullUpdateFromFile() void VToolBasePoint::FullUpdateFromFile()
{ {
ReadAttributes();
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(m_id)); RefreshPointGeometry(*VAbstractTool::data.GeometricObject<VPointF>(m_id));
} }