Refactoring: Renames saveGeometry to saveState.. same for restore.

This commit is contained in:
mfreiholz 2016-02-12 11:43:34 +01:00
parent 93ddfb6413
commit 893d9f4e43
7 changed files with 35 additions and 30 deletions

View File

@ -12,7 +12,7 @@ class QSplitter;
* Developed by Manuel Freiholz * Developed by Manuel Freiholz
*/ */
#if 0 #if 1
#define ADS_NAMESPACE_BEGIN namespace ads { #define ADS_NAMESPACE_BEGIN namespace ads {
#define ADS_NAMESPACE_END } #define ADS_NAMESPACE_END }
#define ADS_NS ads #define ADS_NS ads

View File

@ -47,8 +47,8 @@ public:
QRect outerLeftDropRect() const; QRect outerLeftDropRect() const;
// Geometry and state serialization // Geometry and state serialization
QByteArray saveGeometry() const; QByteArray saveState() const;
bool restoreGeometry(const QByteArray& data); bool restoreState(const QByteArray& data);
QMenu* createContextMenu() const; QMenu* createContextMenu() const;

View File

@ -15,7 +15,7 @@ class FloatingWidget;
class SectionTitleWidget : public QFrame class SectionTitleWidget : public QFrame
{ {
Q_OBJECT Q_OBJECT
//Q_PROPERTY(bool activeTab MEMBER _activeTab NOTIFY activeTabChanged) Q_PROPERTY(bool activeTab MEMBER _activeTab NOTIFY activeTabChanged)
friend class SectionWidget; friend class SectionWidget;

View File

@ -290,7 +290,7 @@ QRect ContainerWidget::outerLeftDropRect() const
return QRect(r.left(), r.top(), w, r.height()); return QRect(r.left(), r.top(), w, r.height());
} }
QByteArray ContainerWidget::saveGeometry() const QByteArray ContainerWidget::saveState() const
{ {
QByteArray ba; QByteArray ba;
QDataStream out(&ba, QIODevice::WriteOnly); QDataStream out(&ba, QIODevice::WriteOnly);
@ -310,7 +310,7 @@ QByteArray ContainerWidget::saveGeometry() const
return ba; return ba;
} }
bool ContainerWidget::restoreGeometry(const QByteArray& data) bool ContainerWidget::restoreState(const QByteArray& data)
{ {
QDataStream in(data); QDataStream in(data);
in.setVersion(QDataStream::Qt_4_5); in.setVersion(QDataStream::Qt_4_5);

View File

@ -73,8 +73,8 @@ int main(int argc, char *argv[])
// ); // );
MainWindow mw; MainWindow mw;
resizeWidgetPerCent(&mw, 60, 80); // resizeWidgetPerCent(&mw, 60, 80);
centerWidget(&mw); // centerWidget(&mw);
mw.show(); mw.show();
return a.exec(); return a.exec();

View File

@ -54,6 +54,28 @@ static ADS_NS::SectionContent::RefPtr createFileSystemTreeSC()
return ADS_NS::SectionContent::newSectionContent(new IconTitleWidget(QIcon(), QString("Filesystem %1").arg(index)), w, QString("uname-%1").arg(index)); return ADS_NS::SectionContent::newSectionContent(new IconTitleWidget(QIcon(), QString("Filesystem %1").arg(index)), w, QString("uname-%1").arg(index));
} }
static void storeDataHelper(const QString& fname, const QByteArray& ba)
{
QFile f(fname + QString(".dat"));
if (f.open(QFile::WriteOnly))
{
f.write(ba);
f.close();
}
}
static QByteArray loadDataHelper(const QString& fname)
{
QFile f(fname + QString(".dat"));
if (f.open(QFile::ReadOnly))
{
QByteArray ba = f.readAll();
f.close();
return ba;
}
return QByteArray();
}
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
@ -92,17 +114,8 @@ MainWindow::MainWindow(QWidget *parent) :
section->addContent(createCalendarSC()); section->addContent(createCalendarSC());
_container->addSection(section); _container->addSection(section);
if (true) restoreGeometry(loadDataHelper("MainWindow"));
{ _container->restoreState(loadDataHelper("ContainerWidget"));
QByteArray ba;
QFile f("test.dat");
if (f.open(QFile::ReadOnly))
{
ba = f.readAll();
f.close();
}
_container->restoreGeometry(ba);
}
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -134,14 +147,6 @@ void MainWindow::contextMenuEvent(QContextMenuEvent* e)
void MainWindow::closeEvent(QCloseEvent* e) void MainWindow::closeEvent(QCloseEvent* e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
if (true) storeDataHelper("MainWindow", saveGeometry());
{ storeDataHelper("ContainerWidget", _container->saveState());
QByteArray ba = _container->saveGeometry();
QFile f("test.dat");
if (f.open(QFile::WriteOnly))
{
f.write(ba);
f.close();
}
}
} }

View File

@ -2,4 +2,4 @@ TEMPLATE = subdirs
SUBDIRS = \ SUBDIRS = \
AdvancedDockingSystem \ AdvancedDockingSystem \
AdvancedDockingSystemDemo AdvancedDockingSystemDemo