From b9b2df9b7ea33021d4fc67ec08bf72b65d35eefc Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 3 Oct 2014 02:28:41 +0100 Subject: [PATCH] Improve saving of custom struct in QSettings --- source/app/PlaYUVerSettings.h | 2 +- source/app/SubWindowHandle.cpp | 37 +++++++++++++++++++++++++++++++++- source/app/SubWindowHandle.h | 11 ++++++++-- source/app/main.cpp | 1 + source/app/plaYUVerApp.cpp | 2 -- source/app/plaYUVerApp.h | 2 +- 6 files changed, 48 insertions(+), 7 deletions(-) diff --git a/source/app/PlaYUVerSettings.h b/source/app/PlaYUVerSettings.h index 3f20953..4449a75 100644 --- a/source/app/PlaYUVerSettings.h +++ b/source/app/PlaYUVerSettings.h @@ -61,7 +61,7 @@ public: Void getDockVisibility( Bool& statusStreamProperties, Bool& statusFrameProperties, Bool& statusQualityMeasurement ); // - - - - - - - - - - Recent Files Settings - - - - - - - - - - - - - - Void setRecentFileList( PlaYUVerRecentFileListInfo ); + Void setRecentFileList( PlaYUVerRecentFileListInfo recentFileList ); PlaYUVerRecentFileListInfo getRecentFileList(); // - - - - - - - - - - - - Grid Settings - - - - - - - - - - - - - - - diff --git a/source/app/SubWindowHandle.cpp b/source/app/SubWindowHandle.cpp index 66b8a69..2f20357 100644 --- a/source/app/SubWindowHandle.cpp +++ b/source/app/SubWindowHandle.cpp @@ -29,6 +29,41 @@ namespace plaYUVer { +QDataStream& operator<<( QDataStream& out, const plaYUVer::PlaYUVerRecentFileListInfo& array ) +{ + PlaYUVerStreamInfo d; + out << array.size(); + for( Int i = 0; i < array.size(); i++ ) + { + d = array.at( i ); + out << d.m_cFilename << d.m_cResolution.width() + << d.m_cResolution.height() + << d.m_iPelFormat + << d.m_uiFrameRate; + + } + return out; +} + +QDataStream& operator>>( QDataStream& in, plaYUVer::PlaYUVerRecentFileListInfo& array ) +{ + PlaYUVerStreamInfo d; + Int array_size; + in >> array_size; + for( Int i = 0; i < array_size; i++ ) + { + in >> d.m_cFilename; + Int x, y; + in >> x; + in >> y; + in >> d.m_iPelFormat; + in >> d.m_uiFrameRate; + d.m_cResolution = QSize( x, y ); + array.append( d ); + } + return in; +} + SubWindowHandle::SubWindowHandle( QWidget * parent, Bool isModule ) : QMdiSubWindow( parent ), m_pCurrStream( NULL ), @@ -113,7 +148,7 @@ Bool SubWindowHandle::loadFile( QString cFilename, Bool bForceDialog ) refreshFrame(); m_sStreamInfo.m_cFilename = cFilename; - m_sStreamInfo.m_cResolution = QSize( Width, Height); + m_sStreamInfo.m_cResolution = QSize( Width, Height ); m_sStreamInfo.m_iPelFormat = InputFormat; m_sStreamInfo.m_uiFrameRate = FrameRate; diff --git a/source/app/SubWindowHandle.h b/source/app/SubWindowHandle.h index b2a8b35..d9d0bca 100644 --- a/source/app/SubWindowHandle.h +++ b/source/app/SubWindowHandle.h @@ -49,10 +49,14 @@ struct structPlaYUVERStreamInfo UInt m_uiFrameRate; }; -//typedef QVector PlaYUVerRecentFileListInfo; -typedef struct structPlaYUVERStreamInfo PlaYUVerRecentFileListInfo; +typedef QVector PlaYUVerRecentFileListInfo; +//typedef structPlaYUVERStreamInfo PlaYUVerRecentFileListInfo; typedef struct structPlaYUVERStreamInfo PlaYUVerStreamInfo; +QDataStream& operator<<(QDataStream& out, const plaYUVer::PlaYUVerRecentFileListInfo& d); +QDataStream& operator>>(QDataStream& in, plaYUVer::PlaYUVerRecentFileListInfo& d); + + class SubWindowHandle: public QMdiSubWindow { Q_OBJECT @@ -230,6 +234,9 @@ public Q_SLOTS: } // NAMESPACE + + Q_DECLARE_METATYPE(plaYUVer::PlaYUVerRecentFileListInfo); +//Q_DECLARE_METATYPE(plaYUVer::structPlaYUVERStreamInfo) #endif // __SUBWINDOWHANDLE_H__ diff --git a/source/app/main.cpp b/source/app/main.cpp index f82e4c2..d53d776 100644 --- a/source/app/main.cpp +++ b/source/app/main.cpp @@ -44,6 +44,7 @@ int main( int argc, char *argv[] ) QApplication::setOrganizationDomain("playuver.pixlra"); qRegisterMetaType("PlaYUVerRecentFileListInfo"); + qRegisterMetaTypeStreamOperators("PlaYUVerRecentFileListInfo"); plaYUVerApp w; w.show(); diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index 72f8626..658c313 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -179,8 +179,6 @@ Void plaYUVerApp::loadFile( QString fileName ) interfaceChild->zoomToFit(); interfaceChild->getViewArea()->setTool( m_appTool ); updateZoomFactorSBox(); - //m_aRecentFileStreamInfo.append( interfaceChild->getStreamInfo() ); - m_aRecentFileStreamInfo = interfaceChild->getStreamInfo(); statusBar()->showMessage( tr( "File loaded" ), 2000 ); } else diff --git a/source/app/plaYUVerApp.h b/source/app/plaYUVerApp.h index d9a1071..fd701a9 100644 --- a/source/app/plaYUVerApp.h +++ b/source/app/plaYUVerApp.h @@ -54,7 +54,7 @@ public: enum RecentFileList { - MAXRECENTFILES, + MAXRECENTFILES = 2, }; protected: