From 0634f8ec53aac84f425f10f7f9c2406288b8a7a6 Mon Sep 17 00:00:00 2001 From: cranphin Date: Mon, 20 Sep 2010 20:11:16 +0000 Subject: [PATCH] This should fix the problem with splitter positions not being stored when the workspace their on isn't viewed before closing GCS, as Edouard found out. The source of this problem is that QSplitter.sizes() only returns the sizes set by setSizes() after the QSplitter is actually shown. Even though save/restoreState manages to retrieve them in the same situation. I think it's a bug, not sure if I can be motivated enough to report it though :) git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1699 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../uavgadgetmanager/uavgadgetview.cpp | 35 +++++++++++++------ .../uavgadgetmanager/uavgadgetview.h | 4 +++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp index a882d65f8..f222200dd 100644 --- a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp @@ -498,6 +498,7 @@ void SplitterOrView::split(Qt::Orientation orientation) Q_ASSERT(m_view && (m_splitter == 0)); m_splitter = new MiniSplitter(this); m_splitter->setOrientation(orientation); + connect(m_splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(onSplitterMoved(int,int))); m_layout->addWidget(m_splitter); Core::IUAVGadget *e = m_view->gadget(); @@ -521,6 +522,11 @@ void SplitterOrView::split(Qt::Orientation orientation) } } +void SplitterOrView::onSplitterMoved( int pos, int index ) { + // Update when the splitter is actually moved. + m_sizes = m_splitter->sizes(); +} + void SplitterOrView::unsplitAll() { m_splitter->hide(); @@ -580,13 +586,9 @@ void SplitterOrView::saveState(QSettings* qSettings) const { if (m_splitter) { qSettings->setValue("type", "splitter"); qSettings->setValue("splitterOrientation", (qint32)m_splitter->orientation()); -// qSettings->setValue("splitterSizes", m_splitter->saveState()); - // Bit clunky, but makes it more readable in the ini file. QList sizesQVariant; - QList sizes = m_splitter->sizes(); - QList::iterator sizesIterator; - for (sizesIterator = sizes.begin(); sizesIterator != sizes.end(); sizesIterator++) { - sizesQVariant.append(*sizesIterator); + foreach (int value, m_sizes) { + sizesQVariant.append(value); } qSettings->setValue("splitterSizes", sizesQVariant); qSettings->beginGroup("side0"); @@ -612,13 +614,12 @@ void SplitterOrView::restoreState(QSettings* qSettings) if (mode == "splitter") { qint32 orientation = qSettings->value("splitterOrientation").toInt(); QList sizesQVariant = qSettings->value("splitterSizes").toList(); - QList sizes; - QList::iterator sizesIterator; - for (sizesIterator = sizesQVariant.begin(); sizesIterator != sizesQVariant.end(); sizesIterator++) { - sizes.append((*sizesIterator).toInt()); + m_sizes.clear(); + foreach (QVariant value, sizesQVariant) { + m_sizes.append(value.toInt()); } split((Qt::Orientation)orientation); - m_splitter->setSizes(sizes); + m_splitter->setSizes(m_sizes); qSettings->beginGroup("side0"); static_cast(m_splitter->widget(0))->restoreState(qSettings); qSettings->endGroup(); @@ -648,6 +649,18 @@ void SplitterOrView::restoreState(const QByteArray &state) stream >> orientation >> splitter >> first >> second; split((Qt::Orientation)orientation); m_splitter->restoreState(splitter); + + // TODO: Lots of ugly, but this whole method should dissapear ASAP, + // It's here only for temporary backwards compatability. + m_sizes.clear(); + QDataStream stream(&splitter, QIODevice::ReadOnly); + qint32 marker; + qint32 v; + stream >> marker; + stream >> v; + stream >> m_sizes; + + static_cast(m_splitter->widget(0))->restoreState(first); static_cast(m_splitter->widget(1))->restoreState(second); } else if (mode == "uavGadget") { diff --git a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.h b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.h index e4cb93a1e..65a75d15d 100644 --- a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.h +++ b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.h @@ -142,6 +142,9 @@ protected: // void paintEvent(QPaintEvent *); void mousePressEvent(QMouseEvent *e); +private slots: + void onSplitterMoved( int pos, int index ); + private: void unsplitAll_helper(); SplitterOrView *findNextView_helper(SplitterOrView *view, bool *found); @@ -150,6 +153,7 @@ private: QStackedLayout *m_layout; UAVGadgetView *m_view; QSplitter *m_splitter; + QList m_sizes; }; }