version 2.4.0

ImageView now optionally save QImage when setImage()
piqt many stream operatorsand new helpers:
 * qSerialize
 * qDeserialize
 * piqSerialize
 * piqDeserialize
This commit is contained in:
2021-08-01 22:09:55 +03:00
parent 29e68e6e6b
commit c0ac0002e6
8 changed files with 120 additions and 114 deletions

View File

@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
project(qad)
set(qad_MAJOR 2)
set(qad_MINOR 3)
set(qad_MINOR 4)
set(qad_REVISION 0)
set(qad_SUFFIX )
set(qad_COMPANY SHS)

View File

@@ -21,8 +21,10 @@
#define PIQT_H
#include <QVector3D>
#include <QPolygonF>
#include <QDateTime>
#include <QColor>
#include <QImage>
#include "pimathmatrix.h"
#include "pipropertystorage.h"
@@ -120,6 +122,12 @@ inline const QColor PI2QColor(const PIVariantTypes::Color & v) {return QColor::f
inline const PIVariantTypes::Color Q2PIColor(const QColor & v) {return PIVariantTypes::Color(v.rgba());}
template<typename T>
inline const QVector<T> PI2QVector(const PIVector<T> & v) {QVector<T> ret(v.size_s()); for (int i = 0; i < v.size_s(); ++i) ret[i] = v[i]; return ret;}
template<typename T>
inline const PIVector<T> Q2PIVector(const QVector<T> & v) {PIVector<T> ret(v.size_s()); for (int i = 0; i < v.size_s(); ++i) ret[i] = v[i]; return ret;}
inline PIPropertyStorage Q2PIPropertyStorage(const PropertyStorage & props) {
PIPropertyStorage ret;
foreach (const PropertyStorage::Property & p, props)
@@ -176,4 +184,107 @@ _PIQt_CONVERT(PIMathVectorT3d, QVector3D, PI2QVector3, Q2PIVector3)
#define piqt __PIQtConvert
#define qtpi __PIQtConvert
inline PIByteArray & operator <<(PIByteArray & s, const QString & v) {s << Q2PIString(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QString & v) {PIString t; s >> t; v = PI2QString(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QStringList & v) {s << Q2PIStringList(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QStringList & v) {PIStringList t; s >> t; v = PI2QStringList(t); return s;}
template <typename T> inline PIByteArray & operator <<(PIByteArray & s, const QVector<T> & v) {s << PIVector<T>(v.constData(), (size_t)v.size()); return s;}
template <typename T> inline PIByteArray & operator >>(PIByteArray & s, QVector<T> & v) {
PIVector<T> t; s >> t;
v.resize(t.size_s());
for (int i = 0; i < t.size_s(); ++i)
v[i] = t[i];
return s;}
template <typename K, typename T> inline PIByteArray & operator <<(PIByteArray & s, const QMap<K, T> & v) {
PIMap<K, T> t;
t.reserve(v.size());
QMapIterator<K, T> it(v);
while (it.hasNext()) {it.next(); t[it.key()] = it.value();}
s >> t;
return s;}
template <typename K, typename T> inline PIByteArray & operator >>(PIByteArray & s, QMap<K, T> & v) {
v.clear();
PIMap<K, T> t; s >> t;
auto it = t.makeIterator();
while (it.hasNext()) {it.next(); v[it.key()] = it.value();}
return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QPolygonF & v) {s << (QVector<QPointF>)v; return s;}
inline PIByteArray & operator >>(PIByteArray & s, QPolygonF & v) {QVector<QPointF> t; s >> t; v = t; return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QByteArray & v) {s << Q2PIByteArray(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QByteArray & v) {PIByteArray t; s >> t; v = PI2QByteArray(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QDate & v) {s << Q2PIDate(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QDate & v) {PIDate t; s >> t; v = PI2QDate(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QTime & v) {s << Q2PITime(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QTime & v) {PITime t; s >> t; v = PI2QTime(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QDateTime & v) {s << Q2PIDateTime(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QDateTime & v) {PIDateTime t; s >> t; v = PI2QDateTime(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QVariant & v) {s << Q2PIVariant(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QVariant & v) {PIVariant t; s >> t; v = PI2QVariant(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const PropertyStorage & v) {s << Q2PIPropertyStorage(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, PropertyStorage & v) {PIPropertyStorage t; s >> t; v = PI2QPropertyStorage(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QColor & v) {s << Q2PIColor(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QColor & v) {PIVariantTypes::Color t; s >> t; v = PI2QColor(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QAD::Enum & v) {s << QAD2PIEnum(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QAD::Enum & v) {PIVariantTypes::Enum t; s >> t; v = PI2QADEnum(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QAD::File & v) {s << QAD2PIFile(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QAD::File & v) {PIVariantTypes::File t; s >> t; v = PI2QADFile(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QAD::Dir & v) {s << QAD2PIDir(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QAD::Dir & v) {PIVariantTypes::Dir t; s >> t; v = PI2QADDir(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QAD::IODevice & v) {s << QAD2PIIODevice(v); return s;}
inline PIByteArray & operator >>(PIByteArray & s, QAD::IODevice & v) {PIVariantTypes::IODevice t; s >> t; v = PI2QADIODevice(t); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const QImage & v) {
QByteArray ba; QBuffer buf(&ba);
v.save(&buf, "png");
s << Q2PIByteArray(ba);
return s;}
inline PIByteArray & operator >>(PIByteArray & s, QImage & v) {
PIByteArray pba; s >> pba;
QByteArray ba = PI2QByteArray(pba);
if (!v.loadFromData(ba, "png"))
v = QImage();
return s;}
/// pure Qt
template <typename T> QByteArray qSerialize(const T & value) {
QByteArray ret;
QDataStream s(&ret, QIODevice::ReadWrite);
s << value;
return ret;
}
template <typename T> T qDeserialize(const QByteArray & data) {
T ret;
if (!data.isEmpty()) {
QDataStream s(data);
s >> ret;
}
return ret;
}
/// PIP with QByteArray
template <typename T> QByteArray piqSerialize(const T & value) {
PIByteArray ret;
ret << value;
return PI2QByteArray(ret);
}
template <typename T> T piqDeserialize(const QByteArray & data) {
T ret;
if (!data.isEmpty()) {
PIByteArray ba = Q2PIByteArray(data);
ba >> ret;
}
return ret;
}
#endif // PIQT_H

View File

@@ -40,16 +40,18 @@ void ImageView::setPixmap(QPixmap pixmap) {
}
void ImageView::setImage(const QImage & i) {
void ImageView::setImage(const QImage & i, bool save) {
im_data.clear();
if (i.isNull()) {
item.setPixmap(QPixmap());
map = QPixmap();
return;
}
if (save) {
QBuffer b(&im_data); b.open(QIODevice::ReadWrite);
i.save(&b, "png");
b.close();
}
map = QPixmap::fromImage(i);
adjustView();
}

View File

@@ -33,7 +33,7 @@ public:
ImageView(QWidget * parent = 0);
~ImageView();
void setImage(const QImage & i);
void setImage(const QImage & i, bool save = true);
void setImage(const QByteArray & i);
QByteArray image() const {return im_data;}
QPixmap pixmap() const;

View File

@@ -1,69 +0,0 @@
#include "chardialog.h"
#include "chardialogplugin.h"
#include <QtCore/QtPlugin>
CharDialogPlugin::CharDialogPlugin(QObject * parent): QObject(parent) {
m_initialized = false;
}
void CharDialogPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
if (m_initialized)
return;
// Add extension registrations, etc. here
m_initialized = true;
}
bool CharDialogPlugin::isInitialized() const {
return m_initialized;
}
QWidget * CharDialogPlugin::createWidget(QWidget * parent) {
return new CharDialog(parent);
}
QString CharDialogPlugin::name() const {
return QLatin1String("CharDialog");
}
QString CharDialogPlugin::group() const {
return QLatin1String("Dialogs");
}
QIcon CharDialogPlugin::icon() const {
return QIcon(":/icons/chardialog.png");
}
QString CharDialogPlugin::toolTip() const {
return QLatin1String("Character Select Dialog");
}
QString CharDialogPlugin::whatsThis() const {
return QLatin1String("Character Select Dialog");
}
bool CharDialogPlugin::isContainer() const {
return false;
}
QString CharDialogPlugin::domXml() const {
return QLatin1String("<widget class=\"CharDialog\" name=\"charDialog\">\n</widget>\n");
}
QString CharDialogPlugin::includeFile() const {
return QLatin1String("chardialog.h");
}

View File

@@ -1,36 +0,0 @@
#ifndef CHARDIALOGPLUGIN_H
#define CHARDIALOGPLUGIN_H
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
#else
# include <QDesignerCustomWidgetInterface>
#endif
class CharDialogPlugin: public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
CharDialogPlugin(QObject * parent = 0);
bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget * createWidget(QWidget * parent);
void initialize(QDesignerFormEditorInterface * core);
private:
bool m_initialized;
};
#endif // CHARDIALOGPLUGIN_H

View File

@@ -1,7 +1,6 @@
#include "qad_widgets.h"
#include "spinsliderplugin.h"
#include "colorbuttonplugin.h"
#include "chardialogplugin.h"
#include "shortcutsplugin.h"
#include "clineeditplugin.h"
#include "qipeditplugin.h"
@@ -22,7 +21,6 @@
QADWidgets::QADWidgets(QObject * parent): QObject(parent) {
m_widgets.append(new SpinSliderPlugin(this));
m_widgets.append(new ColorButtonPlugin(this));
m_widgets.append(new CharDialogPlugin(this));
m_widgets.append(new ShortcutsPlugin(this));
m_widgets.append(new CLineEditPlugin(this));
m_widgets.append(new QIPEditPlugin(this));

View File

@@ -34,7 +34,7 @@ QString ShortcutsPlugin::name() const {
QString ShortcutsPlugin::group() const {
return QLatin1String("Input Widgets");
return QLatin1String("Editor Widgets");
}