Save and load for .lyimg formats in image properties dialog.

This commit is contained in:
Matthias Koefferlein 2020-04-28 22:41:35 +02:00
parent 807487eace
commit cab03a5829
6 changed files with 190 additions and 103 deletions

View File

@ -53,6 +53,13 @@
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="2">
<widget class="QPushButton" name="browse_pb">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label_12">
<property name="sizePolicy">
@ -77,109 +84,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QFrame" name="frame_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="file_name_lbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;Filename&gt;</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="browse_pb">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLabel" name="file_info_lbl">
<property name="text">
<string>&lt;File info&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_18">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="text">
<string>File </string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<item row="4" column="0" colspan="3">
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
@ -442,6 +347,108 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_18">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="text">
<string>File </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QFrame" name="frame_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="file_name_lbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;Filename&gt;</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="save_pb">
<property name="text">
<string>Save As ...</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="file_info_lbl">
<property name="text">
<string>&lt;File info&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -23,6 +23,7 @@
#include "imgObject.h"
#include "imgWidgets.h" // for interpolate_color()
#include "imgStream.h"
#include "tlLog.h"
#include "tlTimer.h"
#include "layPlugin.h"
@ -1487,6 +1488,24 @@ Object::read_file ()
tl::info << "Reading image file " << m_filename;
}
try {
tl::InputFile file (m_filename);
tl::InputStream stream (file);
std::auto_ptr<img::Object> read;
read.reset (img::ImageStreamer::read (stream));
read->m_filename = m_filename;
// for now we need to copy here ...
*this = *read;
// exit on success
return;
} catch (...) {
// continue with other formats ...
}
QImage qimage (tl::to_qstring (m_filename));
if (! qimage.isNull ()) {
@ -1717,6 +1736,25 @@ Object::to_string () const
return os.str ();
}
void
Object::swap (Object &other)
{
m_filename.swap (other.m_filename);
std::swap (m_trans, other.m_trans);
std::swap (mp_data, other.mp_data);
std::swap (m_id, other.m_id);
std::swap (m_min_value, other.m_min_value);
std::swap (m_max_value, other.m_max_value);
std::swap (m_min_value_set, other.m_min_value_set);
std::swap (m_max_value_set, other.m_max_value_set);
std::swap (m_data_mapping, other.m_data_mapping);
std::swap (m_visible, other.m_visible);
std::swap (mp_pixel_data, other.mp_pixel_data);
m_landmarks.swap (other.m_landmarks);
std::swap (m_z_position, other.m_z_position);
std::swap (m_updates_enabled, other.m_updates_enabled);
}
size_t
Object::width () const
{

View File

@ -946,6 +946,11 @@ public:
*/
virtual std::string to_string () const;
/**
* @brief Swap with another image object
*/
void swap (img::Object &other);
/**
* @brief Return the memory used in bytes
*/

View File

@ -23,9 +23,11 @@
#include "imgPropertiesPage.h"
#include "imgLandmarksDialog.h"
#include "imgStream.h"
#include "layLayoutView.h"
#include "layFileDialog.h"
#include "tlExceptions.h"
#include "tlFileUtils.h"
namespace img
{
@ -127,6 +129,7 @@ PropertiesPage::init ()
connect (value_le, SIGNAL (returnPressed ()), this, SLOT (value_return_pressed ()));
connect (reset_pb, SIGNAL (clicked ()), this, SLOT (reset_pressed ()));
connect (save_pb, SIGNAL (clicked ()), this, SLOT (save_pressed ()));
connect (preview_cbx, SIGNAL (clicked ()), this, SLOT (preview_checked ()));
connect (define_landmarks_pb, SIGNAL (clicked ()), this, SLOT (define_landmarks_pressed ()));
}
@ -838,6 +841,31 @@ BEGIN_PROTECTED
END_PROTECTED
}
void
PropertiesPage::save_pressed ()
{
BEGIN_PROTECTED
apply ();
lay::FileDialog file_dialog (this, tl::to_string (QObject::tr ("Save As KLayout Image File")), tl::to_string (QObject::tr ("KLayout image files (*.lyimg);;All files (*)")));
std::string filename = mp_direct_image->filename ();
if (! filename.empty () && tl::extension (filename) != "lyimg") {
filename = tl::basename (filename) + ".lyimg";
}
if (file_dialog.get_save (filename)) {
tl::OutputFile file (filename);
tl::OutputStream stream (file);
img::ImageStreamer::write (stream, *mp_direct_image);
}
END_PROTECTED
}
void
PropertiesPage::reset_pressed ()
{

View File

@ -86,6 +86,7 @@ private slots:
void min_max_return_pressed ();
void preview_checked ();
void reset_pressed ();
void save_pressed ();
void define_landmarks_pressed ();
private:

View File

@ -130,6 +130,14 @@ TEST(1)
EXPECT_EQ (copy2.data_mapping ().false_color_nodes.size (), size_t (4));
EXPECT_EQ (copy2.equals (&image), true);
img::Object copy3, empty;
copy3.swap (copy2);
EXPECT_EQ (copy3.equals (&image), true);
EXPECT_EQ (copy2.equals (&empty), true);
copy3.swap (copy2);
EXPECT_EQ (copy2.equals (&image), true);
EXPECT_EQ (copy3.equals (&empty), true);
EXPECT_EQ (image.to_string (), copy2.to_string ());
EXPECT_EQ (image.mask (1, 2), true);