mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-30 08:24:11 +01:00
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
This commit is contained in:
parent
875437f483
commit
0634f8ec53
@ -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<QVariant> sizesQVariant;
|
||||
QList<int> sizes = m_splitter->sizes();
|
||||
QList<int>::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<QVariant> sizesQVariant = qSettings->value("splitterSizes").toList();
|
||||
QList<int> sizes;
|
||||
QList<QVariant>::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<SplitterOrView*>(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<SplitterOrView*>(m_splitter->widget(0))->restoreState(first);
|
||||
static_cast<SplitterOrView*>(m_splitter->widget(1))->restoreState(second);
|
||||
} else if (mode == "uavGadget") {
|
||||
|
@ -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<int> m_sizes;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user