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
*/
#if 0
#if 1
#define ADS_NAMESPACE_BEGIN namespace ads {
#define ADS_NAMESPACE_END }
#define ADS_NS ads

View File

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

View File

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

View File

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

View File

@ -73,8 +73,8 @@ int main(int argc, char *argv[])
// );
MainWindow mw;
resizeWidgetPerCent(&mw, 60, 80);
centerWidget(&mw);
// resizeWidgetPerCent(&mw, 60, 80);
// centerWidget(&mw);
mw.show();
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));
}
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) :
@ -92,17 +114,8 @@ MainWindow::MainWindow(QWidget *parent) :
section->addContent(createCalendarSC());
_container->addSection(section);
if (true)
{
QByteArray ba;
QFile f("test.dat");
if (f.open(QFile::ReadOnly))
{
ba = f.readAll();
f.close();
}
_container->restoreGeometry(ba);
}
restoreGeometry(loadDataHelper("MainWindow"));
_container->restoreState(loadDataHelper("ContainerWidget"));
}
MainWindow::~MainWindow()
@ -134,14 +147,6 @@ void MainWindow::contextMenuEvent(QContextMenuEvent* e)
void MainWindow::closeEvent(QCloseEvent* e)
{
Q_UNUSED(e);
if (true)
{
QByteArray ba = _container->saveGeometry();
QFile f("test.dat");
if (f.open(QFile::WriteOnly))
{
f.write(ba);
f.close();
}
}
storeDataHelper("MainWindow", saveGeometry());
storeDataHelper("ContainerWidget", _container->saveState());
}

View File

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