mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
Refactoring: Renames saveGeometry to saveState.. same for restore.
This commit is contained in:
parent
93ddfb6413
commit
893d9f4e43
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user