From c0ac0002e6159c3933f1ad43d78ec7e33915396b Mon Sep 17 00:00:00 2001 From: peri4 Date: Sun, 1 Aug 2021 22:09:55 +0300 Subject: [PATCH] version 2.4.0 ImageView now optionally save QImage when setImage() piqt many stream operatorsand new helpers: * qSerialize * qDeserialize * piqSerialize * piqDeserialize --- CMakeLists.txt | 2 +- libs/piqt/piqt.h | 111 +++++++++++++++++++++++ libs/widgets/image_view.cpp | 10 +- libs/widgets/image_view.h | 2 +- libs/widgets/plugin/chardialogplugin.cpp | 69 -------------- libs/widgets/plugin/chardialogplugin.h | 36 -------- libs/widgets/plugin/qad_widgets.cpp | 2 - libs/widgets/plugin/shortcutsplugin.cpp | 2 +- 8 files changed, 120 insertions(+), 114 deletions(-) delete mode 100644 libs/widgets/plugin/chardialogplugin.cpp delete mode 100644 libs/widgets/plugin/chardialogplugin.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 85dfbc2..b68c1f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/libs/piqt/piqt.h b/libs/piqt/piqt.h index 47bdc88..237f650 100644 --- a/libs/piqt/piqt.h +++ b/libs/piqt/piqt.h @@ -21,8 +21,10 @@ #define PIQT_H #include +#include #include #include +#include #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 +inline const QVector PI2QVector(const PIVector & v) {QVector ret(v.size_s()); for (int i = 0; i < v.size_s(); ++i) ret[i] = v[i]; return ret;} +template +inline const PIVector Q2PIVector(const QVector & v) {PIVector 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 inline PIByteArray & operator <<(PIByteArray & s, const QVector & v) {s << PIVector(v.constData(), (size_t)v.size()); return s;} +template inline PIByteArray & operator >>(PIByteArray & s, QVector & v) { + PIVector t; s >> t; + v.resize(t.size_s()); + for (int i = 0; i < t.size_s(); ++i) + v[i] = t[i]; + return s;} +template inline PIByteArray & operator <<(PIByteArray & s, const QMap & v) { + PIMap t; + t.reserve(v.size()); + QMapIterator it(v); + while (it.hasNext()) {it.next(); t[it.key()] = it.value();} + s >> t; + return s;} +template inline PIByteArray & operator >>(PIByteArray & s, QMap & v) { + v.clear(); + PIMap 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)v; return s;} +inline PIByteArray & operator >>(PIByteArray & s, QPolygonF & v) {QVector 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 QByteArray qSerialize(const T & value) { + QByteArray ret; + QDataStream s(&ret, QIODevice::ReadWrite); + s << value; + return ret; +} + +template T qDeserialize(const QByteArray & data) { + T ret; + if (!data.isEmpty()) { + QDataStream s(data); + s >> ret; + } + return ret; +} + + +/// PIP with QByteArray + + +template QByteArray piqSerialize(const T & value) { + PIByteArray ret; + ret << value; + return PI2QByteArray(ret); +} + +template T piqDeserialize(const QByteArray & data) { + T ret; + if (!data.isEmpty()) { + PIByteArray ba = Q2PIByteArray(data); + ba >> ret; + } + return ret; +} + + #endif // PIQT_H diff --git a/libs/widgets/image_view.cpp b/libs/widgets/image_view.cpp index 9537609..bb52119 100644 --- a/libs/widgets/image_view.cpp +++ b/libs/widgets/image_view.cpp @@ -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; } - QBuffer b(&im_data); b.open(QIODevice::ReadWrite); - i.save(&b, "png"); - b.close(); + if (save) { + QBuffer b(&im_data); b.open(QIODevice::ReadWrite); + i.save(&b, "png"); + b.close(); + } map = QPixmap::fromImage(i); adjustView(); } diff --git a/libs/widgets/image_view.h b/libs/widgets/image_view.h index 5598a1b..d4bce49 100644 --- a/libs/widgets/image_view.h +++ b/libs/widgets/image_view.h @@ -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; diff --git a/libs/widgets/plugin/chardialogplugin.cpp b/libs/widgets/plugin/chardialogplugin.cpp deleted file mode 100644 index 4ad02db..0000000 --- a/libs/widgets/plugin/chardialogplugin.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "chardialog.h" -#include "chardialogplugin.h" -#include - - -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("\n\n"); -} - - -QString CharDialogPlugin::includeFile() const { - return QLatin1String("chardialog.h"); -} - diff --git a/libs/widgets/plugin/chardialogplugin.h b/libs/widgets/plugin/chardialogplugin.h deleted file mode 100644 index 9e624ee..0000000 --- a/libs/widgets/plugin/chardialogplugin.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef CHARDIALOGPLUGIN_H -#define CHARDIALOGPLUGIN_H - -#include -#if QT_VERSION >= 0x050000 -# include -#else -# include -#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 diff --git a/libs/widgets/plugin/qad_widgets.cpp b/libs/widgets/plugin/qad_widgets.cpp index 4d045bd..bb243ee 100644 --- a/libs/widgets/plugin/qad_widgets.cpp +++ b/libs/widgets/plugin/qad_widgets.cpp @@ -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)); diff --git a/libs/widgets/plugin/shortcutsplugin.cpp b/libs/widgets/plugin/shortcutsplugin.cpp index 774f4e3..c5eb5e9 100644 --- a/libs/widgets/plugin/shortcutsplugin.cpp +++ b/libs/widgets/plugin/shortcutsplugin.cpp @@ -34,7 +34,7 @@ QString ShortcutsPlugin::name() const { QString ShortcutsPlugin::group() const { - return QLatin1String("Input Widgets"); + return QLatin1String("Editor Widgets"); }