Skip to content

Commit d571f0f

Browse files
Marco Bernasocchipka
Marco Bernasocchi
authored andcommitted
Added runtime stereo selection to settings dialog and at plugin start
1 parent 55e7f21 commit d571f0f

File tree

5 files changed

+137
-41
lines changed

5 files changed

+137
-41
lines changed

src/plugins/globe/globe_plugin_dialog.cpp

+74-31
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@
3131
#include <QStringList>
3232
#include <QVariant>
3333

34+
#include <osgViewer/Viewer>
35+
3436
//constructor
3537
QgsGlobePluginDialog::QgsGlobePluginDialog( QWidget* parent, Qt::WFlags fl )
3638
: QDialog( parent, fl )
3739
{
3840
setupUi( this );
41+
stereoMode = settings.value( "/Plugin-Globe/stereoMode", "OFF" ).toString();
42+
comboStereoMode->setCurrentIndex( comboStereoMode->findText( stereoMode ) );
43+
44+
earthFile = settings.value( "/Plugin-Globe/earthFile", QgsApplication::pkgDataPath() + "/globe/globe.earth" ).toString();
45+
inputEarthFile->setText( earthFile );
3946
}
4047

4148
//destructor
@@ -44,19 +51,64 @@ QgsGlobePluginDialog::~QgsGlobePluginDialog()
4451
}
4552

4653
QString QgsGlobePluginDialog::openFile()
47-
{
48-
QSettings sets;
54+
{
4955
QString path = QFileDialog::getOpenFileName( this,
50-
tr( "Open Earthfile" ),
51-
"/home",
52-
tr( "Earthfiles (*.earth)" ) );
56+
tr( "Open earth file" ),
57+
earthFile,
58+
tr( "Earth files (*.earth)" ) );
5359

5460
return path;
5561
}
5662

63+
void QgsGlobePluginDialog::setStereoMode()
64+
{
65+
if("OFF" == stereoMode)
66+
{
67+
osg::DisplaySettings::instance()->setStereo( false );
68+
}
69+
else if("ADVANCED" == stereoMode)
70+
{
71+
//osg::DisplaySettings::instance()->set
72+
}
73+
else
74+
{
75+
osg::DisplaySettings::instance()->setStereo( true );
76+
77+
if("ANAGLYPHIC" == stereoMode)
78+
{
79+
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::ANAGLYPHIC );
80+
}
81+
else if("VERTICAL_SPLIT" == stereoMode)
82+
{
83+
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::VERTICAL_SPLIT );
84+
}
85+
else
86+
{
87+
showMessageBox("This stereo mode has not been implemented yet. Defaulting to ANAGLYPHIC");
88+
}
89+
}
90+
}
91+
92+
void QgsGlobePluginDialog::setEarthFile()
93+
{
94+
showMessageBox("TODO: set earth file to " + earthFile);
95+
}
96+
97+
void QgsGlobePluginDialog::restartGlobe()
98+
{
99+
//showMessageBox("TODO: restart globe");
100+
}
101+
102+
bool QgsGlobePluginDialog::globeRunning()
103+
{
104+
//TODO: method that tells if the globe plugin is running
105+
return true;
106+
}
107+
57108
void QgsGlobePluginDialog::on_buttonBox_accepted()
58109
{
59110
/*
111+
*
60112
// Validate input settings
61113
QString srcUrl( inputSrcDataset->text() );
62114
QString srcLayer( comboSrcLayer->currentText() );
@@ -138,6 +190,13 @@ void QgsGlobePluginDialog::on_buttonBox_accepted()
138190
139191
// Close dialog box
140192
*/
193+
setStereoMode();
194+
setEarthFile();
195+
196+
if ( globeRunning() )
197+
{
198+
restartGlobe();
199+
}
141200
accept();
142201
}
143202

@@ -146,48 +205,32 @@ void QgsGlobePluginDialog::on_buttonBox_rejected()
146205
reject();
147206
}
148207

149-
void QgsGlobePluginDialog::on_comboStereo_currentIndexChanged( int stereoMode )
208+
void QgsGlobePluginDialog::on_comboStereoMode_currentIndexChanged( QString mode )
150209
{
151-
QMessageBox msgBox;
152-
msgBox.setText("stereo mode changed");
153-
msgBox.exec();
154-
//showText("stereo mode changed");
155-
/*
156-
// Select destination data format
157-
QString frmtCode = comboDstFormats->currentText();
158-
mDstFormat = mFrmts.find( frmtCode );
159-
160-
resetDstUi();
161-
*/
210+
stereoMode = mode;
211+
settings.setValue( "/Plugin-Globe/stereoMode", stereoMode );
162212
}
163213

164-
void QgsGlobePluginDialog::on_buttonSelectEarthfile_clicked()
214+
void QgsGlobePluginDialog::on_buttonSelectEarthFile_clicked()
165215
{
166-
QMessageBox msgBox;
167-
msgBox.setText("select file");
168-
msgBox.exec();
169-
/*
170-
QSettings settings;
171216
QString src;
172217

173218
src = openFile();
174219

175-
inputSrcDataset->setText( src );
220+
inputEarthFile->setText( src );
176221

177222
if ( !src.isEmpty() )
178223
{
179-
QMessageBox msgBox;
180-
msgBox.setText(src);
181-
msgBox.exec();
182-
//showText( src.toString() );
224+
earthFile = src;
225+
settings.setValue( "/Plugin-Globe/earthFile", earthFile );
183226
}
184-
*/
227+
185228
}
186229

187-
/*void QgsGlobePluginDialog::showText(QString text)
230+
void QgsGlobePluginDialog::showMessageBox( QString text )
188231
{
189232
QMessageBox msgBox;
190233
msgBox.setText(text);
191234
msgBox.exec();
192235
}
193-
*/
236+

src/plugins/globe/globe_plugin_dialog.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <ui_globe_plugin_dialog_guibase.h>
2222
#include <QDialog>
23+
#include <QSettings>
2324
#include "qgscontexthelp.h"
2425

2526
class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBase
@@ -31,14 +32,21 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa
3132
~QgsGlobePluginDialog();
3233

3334
private:
35+
QString stereoMode;
36+
QString earthFile;
3437
QString openFile();
35-
void showText( int text);
38+
QSettings settings;
39+
void setStereoMode();
40+
void setEarthFile();
41+
void restartGlobe();
42+
bool globeRunning();
43+
void showMessageBox( QString text);
3644

3745
private slots:
3846
void on_buttonBox_accepted();
3947
void on_buttonBox_rejected();
40-
void on_buttonSelectEarthfile_clicked();
41-
void on_comboStereo_currentIndexChanged( int stereoMode );
48+
void on_buttonSelectEarthFile_clicked();
49+
void on_comboStereoMode_currentIndexChanged( QString mode );
4250
};
4351

4452
#endif // QGIS_GLOBE_PLUGIN_DIALOG_H

src/plugins/globe/globe_plugin_dialog_guibase.ui

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</property>
4545
<layout class="QGridLayout" name="gridLayout_2">
4646
<item row="0" column="0">
47-
<widget class="QLineEdit" name="inputEarthfileDataset">
47+
<widget class="QLineEdit" name="inputEarthFile">
4848
<property name="minimumSize">
4949
<size>
5050
<width>200</width>
@@ -54,7 +54,7 @@
5454
</widget>
5555
</item>
5656
<item row="0" column="1">
57-
<widget class="QPushButton" name="buttonSelectEarthfile">
57+
<widget class="QPushButton" name="buttonSelectEarthFile">
5858
<property name="text">
5959
<string>Browse</string>
6060
</property>
@@ -76,7 +76,7 @@
7676
</property>
7777
<layout class="QGridLayout" name="gridLayout_3">
7878
<item row="0" column="0" colspan="2">
79-
<widget class="QComboBox" name="comboStereo">
79+
<widget class="QComboBox" name="comboStereoMode">
8080
<property name="minimumSize">
8181
<size>
8282
<width>300</width>
@@ -98,7 +98,7 @@
9898
</item>
9999
<item>
100100
<property name="text">
101-
<string>CHECKERBOARD</string>
101+
<string>VERTICAL_SPLIT</string>
102102
</property>
103103
</item>
104104
</widget>
@@ -117,9 +117,9 @@
117117
</widget>
118118
<layoutdefault spacing="6" margin="11"/>
119119
<tabstops>
120-
<tabstop>inputEarthfileDataset</tabstop>
121-
<tabstop>buttonSelectEarthfile</tabstop>
122-
<tabstop>comboStereo</tabstop>
120+
<tabstop>inputEarthFile</tabstop>
121+
<tabstop>buttonSelectEarthFile</tabstop>
122+
<tabstop>comboStereoMode</tabstop>
123123
<tabstop>buttonBox</tabstop>
124124
</tabstops>
125125
<resources/>

src/plugins/globe/qgsosgviewer.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
#include <osgViewer/ViewerEventHandlers>
2222

23+
#include <QString>
2324

2425
QgsGLWidgetAdapter::QgsGLWidgetAdapter( QWidget * parent, const char * name, const QGLWidget * shareWidget, WindowFlags f):
2526
QGLWidget(parent, shareWidget, f)
2627
{
2728
_gw = new osgViewer::GraphicsWindowEmbedded(0,0,width(),height());
29+
setStereoMode();
2830
setFocusPolicy(Qt::ClickFocus);
2931
setMouseTracking ( true );
3032
}
@@ -82,3 +84,40 @@ void QgsGLWidgetAdapter::wheelEvent(QWheelEvent *event)
8284
{
8385
_gw->getEventQueue()->mouseScroll((event->delta()>0) ? osgGA::GUIEventAdapter::SCROLL_DOWN : osgGA::GUIEventAdapter::SCROLL_UP);
8486
}
87+
88+
void QgsGLWidgetAdapter::setStereoMode()
89+
{
90+
//TODO: maybe consolidate this method somewhere else since it is repeated in globe_plugin_dialog.cpp
91+
92+
//osg::DisplaySettings::instance()->setStereo( (bool) settings.value( "/Plugin-Globe/stereo", 0 ).toInt() );
93+
//osg::DisplaySettings::instance()->setStereoMode( (osg::DisplaySettings::StereoMode) settings.value( "/Plugin-Globe/stereoMode", 1 ).toInt());
94+
95+
QString stereoMode;
96+
stereoMode = settings.value( "/Plugin-Globe/stereoMode", "OFF" ).toString();
97+
98+
if("OFF" == stereoMode)
99+
{
100+
osg::DisplaySettings::instance()->setStereo( false );
101+
}
102+
else if("ADVANCED" == stereoMode)
103+
{
104+
//osg::DisplaySettings::instance()->set
105+
}
106+
else
107+
{
108+
osg::DisplaySettings::instance()->setStereo( true );
109+
110+
if("ANAGLYPHIC" == stereoMode)
111+
{
112+
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::ANAGLYPHIC );
113+
}
114+
else if("VERTICAL_SPLIT" == stereoMode)
115+
{
116+
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::VERTICAL_SPLIT );
117+
}
118+
else
119+
{
120+
//should never get here
121+
}
122+
}
123+
}

src/plugins/globe/qgsosgviewer.h

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QtOpenGL/QGLWidget>
2626
#include <QtGui/QKeyEvent>
2727
#include <QtCore/QTimer>
28+
#include <QSettings>
2829

2930
using Qt::WindowFlags;
3031

@@ -51,6 +52,11 @@ class QgsGLWidgetAdapter : public QGLWidget
5152
virtual void wheelEvent( QWheelEvent * event );
5253

5354
osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> _gw;
55+
56+
private:
57+
58+
QSettings settings;
59+
void setStereoMode();
5460
};
5561

5662

0 commit comments

Comments
 (0)