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/vknownmeasurements.h"
#include "../vformat/knownmeasurements/vknownmeasurementsdatabase.h"
#include "../vmisc/def.h"
#include "ui_dialogmdatabase.h"
#include <QKeyEvent>
@ -105,11 +106,21 @@ auto DialogMDataBase::ImgTag(const VPatternImage &image) -> QString
{
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\"/>")
.arg(image.ContentType(), QString(image.ContentData()));
QString size;
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 <QCompleter>
#include <QDesktopServices>
#include <QDoubleSpinBox>
#include <QEvent>
#include <QFileInfo>
#include <QImageReader>
@ -1213,6 +1214,10 @@ void TKMMainWindow::ShowImageData()
disconnect(ui->lineEditImageTitle, &QLineEdit::editingFinished, this, &TKMMainWindow::SaveImageTitle);
ui->lineEditImageTitle->setText(image.Title());
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();
}
//---------------------------------------------------------------------------------------------------------------------
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)
//---------------------------------------------------------------------------------------------------------------------
@ -1707,6 +1737,8 @@ void TKMMainWindow::InitWindow()
connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &TKMMainWindow::ShowImageData);
connect(ui->lineEditImageTitle, &QLineEdit::editingFinished, this, &TKMMainWindow::SaveImageTitle);
connect(ui->doubleSpinBoxImageSize, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&TKMMainWindow::SaveImageSizeScale);
// Tab info
ui->plainTextEditKMDescription->setEnabled(true);
@ -2403,6 +2435,7 @@ void TKMMainWindow::ImageFields(bool enabled)
ui->lineEditImageTitle->setEnabled(enabled);
ui->toolButtonRemoveImage->setEnabled(enabled);
ui->toolButtonSaveImage->setEnabled(enabled);
ui->doubleSpinBoxImageSize->setEnabled(enabled);
}
//---------------------------------------------------------------------------------------------------------------------

View File

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

View File

@ -365,8 +365,7 @@
<string notr="true"/>
</property>
<property name="icon">
<iconset theme="go-top">
<normaloff>.</normaloff>.</iconset>
<iconset theme="go-top"/>
</property>
</widget>
</item>
@ -382,8 +381,7 @@
<string notr="true"/>
</property>
<property name="icon">
<iconset theme="go-up">
<normaloff>.</normaloff>.</iconset>
<iconset theme="go-up"/>
</property>
</widget>
</item>
@ -399,8 +397,7 @@
<string notr="true"/>
</property>
<property name="icon">
<iconset theme="go-down">
<normaloff>.</normaloff>.</iconset>
<iconset theme="go-down"/>
</property>
</widget>
</item>
@ -416,8 +413,7 @@
<string notr="true"/>
</property>
<property name="icon">
<iconset theme="go-bottom">
<normaloff>.</normaloff>.</iconset>
<iconset theme="go-bottom"/>
</property>
</widget>
</item>
@ -446,8 +442,7 @@
<string notr="true"/>
</property>
<property name="icon">
<iconset theme="list-remove">
<normaloff>.</normaloff>.</iconset>
<iconset theme="list-remove"/>
</property>
</widget>
</item>
@ -788,8 +783,7 @@
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="document-save-as">
<normaloff>.</normaloff>.</iconset>
<iconset theme="document-save-as"/>
</property>
</widget>
</item>
@ -812,6 +806,35 @@
</property>
</widget>
</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>
</widget>
</widget>
@ -820,8 +843,7 @@
</widget>
<widget class="QWidget" name="tabInformation">
<attribute name="icon">
<iconset theme="documentinfo">
<normaloff>.</normaloff>.</iconset>
<iconset theme="documentinfo"/>
</attribute>
<attribute name="title">
<string>Information</string>
@ -1035,8 +1057,7 @@
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="document-save">
<normaloff>.</normaloff>.</iconset>
<iconset theme="document-save"/>
</property>
<property name="text">
<string>&amp;Save</string>
@ -1050,8 +1071,7 @@
<bool>false</bool>
</property>
<property name="icon">
<iconset theme="document-save-as">
<normaloff>.</normaloff>.</iconset>
<iconset theme="document-save-as"/>
</property>
<property name="text">
<string>Save &amp;As …</string>
@ -1062,8 +1082,7 @@
</action>
<action name="actionQuit">
<property name="icon">
<iconset theme="application-exit">
<normaloff>.</normaloff>.</iconset>
<iconset theme="application-exit"/>
</property>
<property name="text">
<string>&amp;Quit</string>
@ -1082,8 +1101,7 @@
</action>
<action name="actionAboutTape">
<property name="icon">
<iconset theme="help-about">
<normaloff>.</normaloff>.</iconset>
<iconset theme="help-about"/>
</property>
<property name="text">
<string>&amp;About Tape</string>
@ -1094,8 +1112,7 @@
</action>
<action name="actionNew">
<property name="icon">
<iconset theme="document-new">
<normaloff>.</normaloff>.</iconset>
<iconset theme="document-new"/>
</property>
<property name="text">
<string>&amp;New</string>
@ -1132,8 +1149,7 @@
</action>
<action name="actionOpen">
<property name="icon">
<iconset theme="document-open">
<normaloff>.</normaloff>.</iconset>
<iconset theme="document-open"/>
</property>
<property name="text">
<string>&amp;Open</string>

View File

@ -20,6 +20,7 @@
<xs:attribute type="contentType" name="contentType" use="optional"/>
<xs:attribute type="uuid" name="uid" use="required"/>
<xs:attribute type="xs:string" name="title" use="optional"/>
<xs:attribute type="imageScale" name="size" use="optional"/>
</xs:extension>
</xs:simpleContent>
</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:restriction>
</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>

View File

@ -227,3 +227,15 @@ void VPatternImage::SetTitle(const QString &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;
void SetTitle(const QString &newTitle);
qreal GetSizeScale() const;
void SetSizeScale(qreal newSizeScale);
private:
QString m_contentType{};
QByteArray m_contentData{};
mutable QString m_errorString{};
QString m_title{};
qreal m_sizeScale{100};
};
#endif // VPATTERNIMAGE_H

View File

@ -29,6 +29,7 @@
#include "../ifc/ifcdef.h"
#include "../ifc/xml/vknownmeasurementsconverter.h"
#include "../ifc/xml/vpatternimage.h"
#include "../vmisc/def.h"
#include "../vmisc/literals.h"
#include "../vmisc/projectversion.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, attrUId, ("uid"_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, attrDescription, ("description"_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)
{
@ -588,7 +605,7 @@ auto VKnownMeasurementsDocument::FindImage(const QUuid &id) const -> QDomElement
//---------------------------------------------------------------------------------------------------------------------
void VKnownMeasurementsDocument::ReadImages(VKnownMeasurements &known) const
{
QDomNodeList list = elementsByTagName(*tagImage);
QDomNodeList const list = elementsByTagName(*tagImage);
for (int i = 0; i < list.size(); ++i)
{
@ -601,6 +618,7 @@ void VKnownMeasurementsDocument::ReadImages(VKnownMeasurements &known) const
VPatternImage image;
image.SetContentData(domElement.text().toLatin1(), domElement.attribute(*attrContentType));
image.SetTitle(domElement.attribute(*attrTitle));
image.SetSizeScale(GetParametrDouble(domElement, *attrSize, QStringLiteral("100.0")));
known.AddImage(QUuid(domElement.attribute(*attrUId)), image);
}

View File

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