Better control over known measurement image size in description.

This commit is contained in:
Roman Telezhynskyi 2024-01-19 10:34:43 +02:00
parent 717225ce03
commit 8b6ee824ae
9 changed files with 133 additions and 30 deletions

View file

@ -31,6 +31,7 @@
#include "../vformat/knownmeasurements/vknownmeasurement.h" #include "../vformat/knownmeasurements/vknownmeasurement.h"
#include "../vformat/knownmeasurements/vknownmeasurements.h" #include "../vformat/knownmeasurements/vknownmeasurements.h"
#include "../vformat/knownmeasurements/vknownmeasurementsdatabase.h" #include "../vformat/knownmeasurements/vknownmeasurementsdatabase.h"
#include "../vmisc/def.h"
#include "ui_dialogmdatabase.h" #include "ui_dialogmdatabase.h"
#include <QKeyEvent> #include <QKeyEvent>
@ -105,11 +106,21 @@ auto DialogMDataBase::ImgTag(const VPatternImage &image) -> QString
{ {
if (!image.IsValid()) if (!image.IsValid())
{ {
return QStringLiteral("<img src=\"wrong.png\" align=\"center\"/>"); // In case of error return QStringLiteral(R"(<img src="wrong.png" align="center" />)"); // In case of error
} }
return QStringLiteral("<img src=\"data:%1;base64,%2\" align=\"center\"/>") QString size;
.arg(image.ContentType(), QString(image.ContentData()));
if (!VFuzzyComparePossibleNulls(image.GetSizeScale(), 100.0))
{
QSizeF const imaheSize = image.Size();
size = QStringLiteral(R"(width="%1" height="%2")")
.arg(imaheSize.width() * image.GetSizeScale() / 100)
.arg(imaheSize.height() * image.GetSizeScale() / 100);
}
return QStringLiteral(R"(<img src="data:%1;base64,%2" align="center" %3% />)")
.arg(image.ContentType(), QString(image.ContentData()), size);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -50,6 +50,7 @@
#include <QCloseEvent> #include <QCloseEvent>
#include <QCompleter> #include <QCompleter>
#include <QDesktopServices> #include <QDesktopServices>
#include <QDoubleSpinBox>
#include <QEvent> #include <QEvent>
#include <QFileInfo> #include <QFileInfo>
#include <QImageReader> #include <QImageReader>
@ -1213,6 +1214,10 @@ void TKMMainWindow::ShowImageData()
disconnect(ui->lineEditImageTitle, &QLineEdit::editingFinished, this, &TKMMainWindow::SaveImageTitle); disconnect(ui->lineEditImageTitle, &QLineEdit::editingFinished, this, &TKMMainWindow::SaveImageTitle);
ui->lineEditImageTitle->setText(image.Title()); ui->lineEditImageTitle->setText(image.Title());
connect(ui->lineEditImageTitle, &QLineEdit::editingFinished, this, &TKMMainWindow::SaveImageTitle); connect(ui->lineEditImageTitle, &QLineEdit::editingFinished, this, &TKMMainWindow::SaveImageTitle);
ui->doubleSpinBoxImageSize->blockSignals(true);
ui->doubleSpinBoxImageSize->setValue(image.GetSizeScale());
ui->doubleSpinBoxImageSize->blockSignals(false);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1466,6 +1471,31 @@ void TKMMainWindow::SaveImageTitle()
ShowMData(); ShowMData();
} }
//---------------------------------------------------------------------------------------------------------------------
void TKMMainWindow::SaveImageSizeScale()
{
auto *item = ui->listWidget->currentItem();
int row = ui->listWidget->currentRow();
if (item == nullptr)
{
return;
}
m_m->SetImageSizeScale(item->data(Qt::UserRole).toUuid(), ui->doubleSpinBoxImageSize->value());
MeasurementsWereSaved(false);
m_known = VKnownMeasurements();
RefreshImages();
ui->listWidget->blockSignals(true);
ui->listWidget->setCurrentRow(row);
ui->listWidget->blockSignals(false);
ShowMData();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1707,6 +1737,8 @@ void TKMMainWindow::InitWindow()
connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &TKMMainWindow::ShowImageData); connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &TKMMainWindow::ShowImageData);
connect(ui->lineEditImageTitle, &QLineEdit::editingFinished, this, &TKMMainWindow::SaveImageTitle); connect(ui->lineEditImageTitle, &QLineEdit::editingFinished, this, &TKMMainWindow::SaveImageTitle);
connect(ui->doubleSpinBoxImageSize, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&TKMMainWindow::SaveImageSizeScale);
// Tab info // Tab info
ui->plainTextEditKMDescription->setEnabled(true); ui->plainTextEditKMDescription->setEnabled(true);
@ -2403,6 +2435,7 @@ void TKMMainWindow::ImageFields(bool enabled)
ui->lineEditImageTitle->setEnabled(enabled); ui->lineEditImageTitle->setEnabled(enabled);
ui->toolButtonRemoveImage->setEnabled(enabled); ui->toolButtonRemoveImage->setEnabled(enabled);
ui->toolButtonSaveImage->setEnabled(enabled); ui->toolButtonSaveImage->setEnabled(enabled);
ui->doubleSpinBoxImageSize->setEnabled(enabled);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -115,6 +115,7 @@ private slots:
void SaveMDiagram(); void SaveMDiagram();
void SaveImageTitle(); void SaveImageTitle();
void SaveImageSizeScale();
void AskDefaultSettings(); void AskDefaultSettings();

View file

@ -365,8 +365,7 @@
<string notr="true"/> <string notr="true"/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="go-top"> <iconset theme="go-top"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
</widget> </widget>
</item> </item>
@ -382,8 +381,7 @@
<string notr="true"/> <string notr="true"/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="go-up"> <iconset theme="go-up"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
</widget> </widget>
</item> </item>
@ -399,8 +397,7 @@
<string notr="true"/> <string notr="true"/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="go-down"> <iconset theme="go-down"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
</widget> </widget>
</item> </item>
@ -416,8 +413,7 @@
<string notr="true"/> <string notr="true"/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="go-bottom"> <iconset theme="go-bottom"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
</widget> </widget>
</item> </item>
@ -446,8 +442,7 @@
<string notr="true"/> <string notr="true"/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="list-remove"> <iconset theme="list-remove"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
</widget> </widget>
</item> </item>
@ -788,8 +783,7 @@
<string notr="true">...</string> <string notr="true">...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="document-save-as"> <iconset theme="document-save-as"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
</widget> </widget>
</item> </item>
@ -812,6 +806,35 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxImageSize">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string notr="true">%</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.100000000000000</double>
</property>
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
@ -820,8 +843,7 @@
</widget> </widget>
<widget class="QWidget" name="tabInformation"> <widget class="QWidget" name="tabInformation">
<attribute name="icon"> <attribute name="icon">
<iconset theme="documentinfo"> <iconset theme="documentinfo"/>
<normaloff>.</normaloff>.</iconset>
</attribute> </attribute>
<attribute name="title"> <attribute name="title">
<string>Information</string> <string>Information</string>
@ -1035,8 +1057,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="document-save"> <iconset theme="document-save"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Save</string> <string>&amp;Save</string>
@ -1050,8 +1071,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset theme="document-save-as"> <iconset theme="document-save-as"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>Save &amp;As …</string> <string>Save &amp;As …</string>
@ -1062,8 +1082,7 @@
</action> </action>
<action name="actionQuit"> <action name="actionQuit">
<property name="icon"> <property name="icon">
<iconset theme="application-exit"> <iconset theme="application-exit"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Quit</string> <string>&amp;Quit</string>
@ -1082,8 +1101,7 @@
</action> </action>
<action name="actionAboutTape"> <action name="actionAboutTape">
<property name="icon"> <property name="icon">
<iconset theme="help-about"> <iconset theme="help-about"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;About Tape</string> <string>&amp;About Tape</string>
@ -1094,8 +1112,7 @@
</action> </action>
<action name="actionNew"> <action name="actionNew">
<property name="icon"> <property name="icon">
<iconset theme="document-new"> <iconset theme="document-new"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;New</string> <string>&amp;New</string>
@ -1132,8 +1149,7 @@
</action> </action>
<action name="actionOpen"> <action name="actionOpen">
<property name="icon"> <property name="icon">
<iconset theme="document-open"> <iconset theme="document-open"/>
<normaloff>.</normaloff>.</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Open</string> <string>&amp;Open</string>

View file

@ -20,6 +20,7 @@
<xs:attribute type="contentType" name="contentType" use="optional"/> <xs:attribute type="contentType" name="contentType" use="optional"/>
<xs:attribute type="uuid" name="uid" use="required"/> <xs:attribute type="uuid" name="uid" use="required"/>
<xs:attribute type="xs:string" name="title" use="optional"/> <xs:attribute type="xs:string" name="title" use="optional"/>
<xs:attribute type="imageScale" name="size" use="optional"/>
</xs:extension> </xs:extension>
</xs:simpleContent> </xs:simpleContent>
</xs:complexType> </xs:complexType>
@ -78,4 +79,10 @@
<xs:pattern value="|\{[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}\}"/> <xs:pattern value="|\{[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}\}"/>
</xs:restriction> </xs:restriction>
</xs:simpleType> </xs:simpleType>
<xs:simpleType name="imageScale">
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0.1"/>
<xs:maxInclusive value="100.0"/>
</xs:restriction>
</xs:simpleType>
</xs:schema> </xs:schema>

View file

@ -227,3 +227,15 @@ void VPatternImage::SetTitle(const QString &newTitle)
{ {
m_title = newTitle; m_title = newTitle;
} }
//---------------------------------------------------------------------------------------------------------------------
auto VPatternImage::GetSizeScale() const -> qreal
{
return m_sizeScale;
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternImage::SetSizeScale(qreal newSizeScale)
{
m_sizeScale = qBound(0.1, newSizeScale, 100.0);
}

View file

@ -64,11 +64,15 @@ public:
auto Title() const -> QString; auto Title() const -> QString;
void SetTitle(const QString &newTitle); void SetTitle(const QString &newTitle);
qreal GetSizeScale() const;
void SetSizeScale(qreal newSizeScale);
private: private:
QString m_contentType{}; QString m_contentType{};
QByteArray m_contentData{}; QByteArray m_contentData{};
mutable QString m_errorString{}; mutable QString m_errorString{};
QString m_title{}; QString m_title{};
qreal m_sizeScale{100};
}; };
#endif // VPATTERNIMAGE_H #endif // VPATTERNIMAGE_H

View file

@ -29,6 +29,7 @@
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "../ifc/xml/vknownmeasurementsconverter.h" #include "../ifc/xml/vknownmeasurementsconverter.h"
#include "../ifc/xml/vpatternimage.h" #include "../ifc/xml/vpatternimage.h"
#include "../vmisc/def.h"
#include "../vmisc/literals.h" #include "../vmisc/literals.h"
#include "../vmisc/projectversion.h" #include "../vmisc/projectversion.h"
#include "vknownmeasurement.h" #include "vknownmeasurement.h"
@ -63,6 +64,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrName, ("name"_L1))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrContentType, ("contentType"_L1)) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrContentType, ("contentType"_L1)) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrUId, ("uid"_L1)) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrUId, ("uid"_L1)) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrTitle, ("title"_L1)) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrTitle, ("title"_L1)) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrSize, ("size"_L1)) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrReadOnly, ("read-only"_L1)) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrReadOnly, ("read-only"_L1)) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrDescription, ("description"_L1)) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrDescription, ("description"_L1)) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrFullName, ("full_name"_L1)) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, attrFullName, ("full_name"_L1)) // NOLINT
@ -487,6 +489,21 @@ void VKnownMeasurementsDocument::SetImageTitle(const QUuid &id, const QString &t
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VKnownMeasurementsDocument::SetImageSizeScale(const QUuid &id, qreal scale)
{
QDomElement node = FindImage(id);
if (not node.isNull())
{
SetAttributeOrRemoveIf<qreal>(node, *attrSize, scale,
[](qreal scale) noexcept { return VFuzzyComparePossibleNulls(scale, 100.0); });
}
else
{
qWarning() << tr("Can't find image by id '%1'").arg(id.toString());
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VKnownMeasurementsDocument::SetImageId(const QUuid &id, const QUuid &newId) void VKnownMeasurementsDocument::SetImageId(const QUuid &id, const QUuid &newId)
{ {
@ -588,7 +605,7 @@ auto VKnownMeasurementsDocument::FindImage(const QUuid &id) const -> QDomElement
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VKnownMeasurementsDocument::ReadImages(VKnownMeasurements &known) const void VKnownMeasurementsDocument::ReadImages(VKnownMeasurements &known) const
{ {
QDomNodeList list = elementsByTagName(*tagImage); QDomNodeList const list = elementsByTagName(*tagImage);
for (int i = 0; i < list.size(); ++i) for (int i = 0; i < list.size(); ++i)
{ {
@ -601,6 +618,7 @@ void VKnownMeasurementsDocument::ReadImages(VKnownMeasurements &known) const
VPatternImage image; VPatternImage image;
image.SetContentData(domElement.text().toLatin1(), domElement.attribute(*attrContentType)); image.SetContentData(domElement.text().toLatin1(), domElement.attribute(*attrContentType));
image.SetTitle(domElement.attribute(*attrTitle)); image.SetTitle(domElement.attribute(*attrTitle));
image.SetSizeScale(GetParametrDouble(domElement, *attrSize, QStringLiteral("100.0")));
known.AddImage(QUuid(domElement.attribute(*attrUId)), image); known.AddImage(QUuid(domElement.attribute(*attrUId)), image);
} }

View file

@ -84,6 +84,7 @@ public:
void SetImageContent(const QUuid &id, const VPatternImage &image); void SetImageContent(const QUuid &id, const VPatternImage &image);
void SetImageTitle(const QUuid &id, const QString &text); void SetImageTitle(const QUuid &id, const QString &text);
void SetImageSizeScale(const QUuid &id, qreal scale);
void SetImageId(const QUuid &id, const QUuid &newId); void SetImageId(const QUuid &id, const QUuid &newId);
private: private: