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
|
* 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
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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();
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user