Skip to content

Commit f31b955

Browse files
vcloarecnyalldawson
authored andcommittedOct 21, 2020
remove spins
1 parent 55ee533 commit f31b955

File tree

3 files changed

+119
-170
lines changed

3 files changed

+119
-170
lines changed
 

‎src/app/3d/qgslightswidget.cpp

Lines changed: 24 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,13 @@ QgsLightsWidget::QgsLightsWidget( QWidget *parent )
5151
connect( btnRemoveDirectionalLight, &QToolButton::clicked, this, &QgsLightsWidget::onRemoveDirectionalLight );
5252

5353
connect( cboDirectionalLights, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsLightsWidget::onCurrentDirectionalLightChanged );
54-
connect( spinDirectionX, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onSpinBoxDirectionChanged );
55-
connect( spinDirectionY, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onSpinBoxDirectionChanged );
56-
connect( spinDirectionZ, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onSpinBoxDirectionChanged );
5754
connect( spinDirectionalIntensity, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::updateCurrentDirectionalLightParameters );
5855
connect( btnDirectionalColor, &QgsColorButton::colorChanged, this, &QgsLightsWidget::updateCurrentDirectionalLightParameters );
5956

6057
connect( dialAzimuth, &QSlider::valueChanged, [this]( int value ) {spinBoxAzimuth->setValue( ( value + 180 ) % 360 );} );
61-
connect( spinBoxAzimuth, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onSpinBoxAzimuthChange );
62-
connect( spinBoxAltitude, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onSpinBoxAltitudeChange );
6358
connect( sliderAltitude, &QSlider::valueChanged, spinBoxAltitude, &QgsDoubleSpinBox::setValue );
59+
connect( spinBoxAzimuth, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onDirectionChange );
60+
connect( spinBoxAltitude, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onDirectionChange );
6461

6562
tabWidget->setCurrentIndex( QgsSettings().value( QStringLiteral( "UI/last3DLightsTab" ), 1 ).toInt() );
6663
}
@@ -118,12 +115,12 @@ void QgsLightsWidget::onCurrentDirectionalLightChanged( int index )
118115
return;
119116

120117
QgsDirectionalLightSettings light = mDirectionalLights.at( index );
121-
whileBlocking( spinDirectionX )->setValue( light.direction().x() );
122-
whileBlocking( spinDirectionY )->setValue( light.direction().y() );
123-
whileBlocking( spinDirectionZ )->setValue( light.direction().z() );
118+
mDirectionX = light.direction().x();
119+
mDirectionY = light.direction().y();
120+
mDirectionZ = light.direction().z();
124121
whileBlocking( btnDirectionalColor )->setColor( light.color() );
125122
whileBlocking( spinDirectionalIntensity )->setValue( light.intensity() );
126-
onSpinBoxDirectionChanged();
123+
setAzimuthAltitude();
127124
}
128125

129126

@@ -145,12 +142,16 @@ void QgsLightsWidget::updateCurrentLightParameters()
145142

146143
void QgsLightsWidget::updateCurrentDirectionalLightParameters()
147144
{
145+
labelX->setText( QString::number( mDirectionX, 'f', 2 ) );
146+
labelY->setText( QString::number( mDirectionY, 'f', 2 ) );
147+
labelZ->setText( QString::number( mDirectionZ, 'f', 2 ) );
148+
148149
int index = cboDirectionalLights->currentIndex();
149150
if ( index < 0 || index >= cboDirectionalLights->count() )
150151
return;
151152

152153
QgsDirectionalLightSettings light;
153-
light.setDirection( QgsVector3D( spinDirectionX->value(), spinDirectionY->value(), spinDirectionZ->value() ) );
154+
light.setDirection( QgsVector3D( mDirectionX, mDirectionY, mDirectionZ ) );
154155
light.setColor( btnDirectionalColor->color() );
155156
light.setIntensity( spinDirectionalIntensity->value() );
156157
mDirectionalLights[index] = light;
@@ -218,88 +219,49 @@ void QgsLightsWidget::onRemoveDirectionalLight()
218219
emit directionalLightsCountChanged( cboDirectionalLights->count() );
219220
}
220221

221-
void QgsLightsWidget::onSpinBoxDirectionChanged()
222+
void QgsLightsWidget::setAzimuthAltitude()
222223
{
223-
double x = spinDirectionX->value();
224-
double y = spinDirectionY->value();
225-
double z = spinDirectionZ->value();
226224
double azimuthAngle;
227225
double altitudeAngle;
228226

229-
double horizontalVectorMagnitude = sqrt( x * x + z * z );
227+
double horizontalVectorMagnitude = sqrt( mDirectionX * mDirectionX + mDirectionZ * mDirectionZ );
228+
230229
if ( horizontalVectorMagnitude == 0 )
231230
azimuthAngle = 0;
232231
else
233232
{
234-
azimuthAngle = ( asin( -x / horizontalVectorMagnitude ) ) / M_PI * 180;
235-
if ( z < 0 )
233+
azimuthAngle = ( asin( -mDirectionX / horizontalVectorMagnitude ) ) / M_PI * 180;
234+
if ( mDirectionZ < 0 )
236235
azimuthAngle = 180 - azimuthAngle;
237236
azimuthAngle = std::fmod( azimuthAngle + 360.0, 360.0 );
238237
}
239238

240-
241239
dialAzimuth->setValue( int( azimuthAngle + 180 ) % 360 );
242240
spinBoxAzimuth->setValue( azimuthAngle );
243241

244242
if ( horizontalVectorMagnitude == 0 )
245-
altitudeAngle = y >= 0 ? 90 : -90;
243+
altitudeAngle = mDirectionY >= 0 ? 90 : -90;
246244
else
247-
altitudeAngle = -atan( y / horizontalVectorMagnitude ) / M_PI * 180;
245+
altitudeAngle = -atan( mDirectionY / horizontalVectorMagnitude ) / M_PI * 180;
248246

249247
spinBoxAltitude->setValue( altitudeAngle );
250248
sliderAltitude->setValue( altitudeAngle );
251249

252250
updateCurrentDirectionalLightParameters();
253251
}
254252

255-
void QgsLightsWidget::onSpinBoxAzimuthChange()
253+
void QgsLightsWidget::onDirectionChange()
256254
{
257-
double x = spinDirectionX->value();
258-
double z = spinDirectionZ->value();
259-
double horizontalVectorMagnitude = sqrt( x * x + z * z );
260-
261-
double azimuthValue = spinBoxAzimuth->value();
262-
x = -horizontalVectorMagnitude * sin( azimuthValue / 180 * M_PI );
263-
z = horizontalVectorMagnitude * cos( azimuthValue / 180 * M_PI );
264-
265-
whileBlocking( dialAzimuth )->setValue( int( azimuthValue + 180 ) % 360 );
266-
whileBlocking( spinDirectionX )->setValue( x );
267-
whileBlocking( spinDirectionZ )->setValue( z );
268-
269-
updateCurrentDirectionalLightParameters();
270-
}
271-
272-
void QgsLightsWidget::onSpinBoxAltitudeChange()
273-
{
274-
double x = spinDirectionX->value();
275-
double y = spinDirectionY->value();
276-
double z = spinDirectionZ->value();
277-
double horizontalVectorMagnitude = sqrt( x * x + z * z );
278-
double vectorMagnitude = sqrt( x * x + y * y + z * z );
279-
280255
double altitudeValue = spinBoxAltitude->value();
281256
double azimuthValue = spinBoxAzimuth->value();
282-
if ( fabs( altitudeValue ) == 90 )
283-
{
284-
x = 0;
285-
z = 0;
286-
y = -vectorMagnitude * fabs( altitudeValue ) / altitudeValue;
287-
}
288-
else
289-
{
290-
if ( horizontalVectorMagnitude == 0 )
291-
horizontalVectorMagnitude = vectorMagnitude * cos( altitudeValue / 180 * M_PI );;
292257

293-
x = -horizontalVectorMagnitude * sin( azimuthValue / 180 * M_PI );
294-
z = horizontalVectorMagnitude * cos( azimuthValue / 180 * M_PI );
295-
y = -tan( altitudeValue / 180 * M_PI ) * horizontalVectorMagnitude;
296-
}
258+
double horizontalVectorMagnitude = cos( altitudeValue / 180 * M_PI );
259+
mDirectionX = -horizontalVectorMagnitude * sin( azimuthValue / 180 * M_PI );
260+
mDirectionZ = horizontalVectorMagnitude * cos( azimuthValue / 180 * M_PI );
261+
mDirectionY = -sin( altitudeValue / 180 * M_PI );
297262

298-
whileBlocking( spinDirectionX )->setValue( x );
299-
whileBlocking( spinDirectionZ )->setValue( z );
300-
whileBlocking( spinDirectionY )->setValue( y );
301-
whileBlocking( sliderAltitude )->setValue( altitudeValue );
302263

264+
whileBlocking( sliderAltitude )->setValue( altitudeValue );
303265
updateCurrentDirectionalLightParameters();
304266
}
305267

‎src/app/3d/qgslightswidget.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,18 @@ class QgsLightsWidget : public QWidget, private Ui::QgsLightsWidget
5252
void updateCurrentDirectionalLightParameters();
5353
void onAddDirectionalLight();
5454
void onRemoveDirectionalLight();
55-
void onSpinBoxDirectionChanged();
56-
void onSpinBoxAzimuthChange();
57-
void onSpinBoxAltitudeChange();
55+
void setAzimuthAltitude();
56+
void onDirectionChange();
5857
private:
5958
void updateLightsList();
6059
void updateDirectionalLightsList();
6160

6261
private:
6362
QList<QgsPointLightSettings> mPointLights;
6463
QList<QgsDirectionalLightSettings> mDirectionalLights;
65-
// QwtCompass *mDirectionCompass = nullptr;
64+
double mDirectionX = 0;
65+
double mDirectionY = -1;
66+
double mDirectionZ = 0;
6667
};
6768

6869
#endif // QGSLIGHTSWIDGET_H

‎src/ui/3d/qgslightswidget.ui

Lines changed: 90 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -216,107 +216,7 @@
216216
<layout class="QGridLayout" name="gridLayout_4">
217217
<item row="1" column="0" colspan="3">
218218
<layout class="QGridLayout" name="gridLayout_3">
219-
<item row="4" column="1">
220-
<widget class="QgsDoubleSpinBox" name="spinDirectionZ">
221-
<property name="decimals">
222-
<number>2</number>
223-
</property>
224-
<property name="minimum">
225-
<double>-9999999.000000000000000</double>
226-
</property>
227-
<property name="maximum">
228-
<double>9999999.000000000000000</double>
229-
</property>
230-
</widget>
231-
</item>
232-
<item row="4" column="0">
233-
<widget class="QLabel" name="label_10">
234-
<property name="text">
235-
<string>Z</string>
236-
</property>
237-
</widget>
238-
</item>
239-
<item row="5" column="0">
240-
<widget class="QLabel" name="label_16">
241-
<property name="text">
242-
<string>Color</string>
243-
</property>
244-
</widget>
245-
</item>
246-
<item row="2" column="1">
247-
<widget class="QgsDoubleSpinBox" name="spinDirectionX">
248-
<property name="decimals">
249-
<number>2</number>
250-
</property>
251-
<property name="minimum">
252-
<double>-9999999.000000000000000</double>
253-
</property>
254-
<property name="maximum">
255-
<double>9999999.000000000000000</double>
256-
</property>
257-
</widget>
258-
</item>
259-
<item row="3" column="0">
260-
<widget class="QLabel" name="label_13">
261-
<property name="text">
262-
<string>Y</string>
263-
</property>
264-
</widget>
265-
</item>
266-
<item row="6" column="1">
267-
<widget class="QgsDoubleSpinBox" name="spinDirectionalIntensity">
268-
<property name="decimals">
269-
<number>1</number>
270-
</property>
271-
<property name="maximum">
272-
<double>999999.000000000000000</double>
273-
</property>
274-
</widget>
275-
</item>
276-
<item row="3" column="1">
277-
<widget class="QgsDoubleSpinBox" name="spinDirectionY">
278-
<property name="decimals">
279-
<number>2</number>
280-
</property>
281-
<property name="minimum">
282-
<double>-9999999.000000000000000</double>
283-
</property>
284-
<property name="maximum">
285-
<double>9999999.000000000000000</double>
286-
</property>
287-
</widget>
288-
</item>
289-
<item row="5" column="1">
290-
<widget class="QgsColorButton" name="btnDirectionalColor">
291-
<property name="sizePolicy">
292-
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
293-
<horstretch>0</horstretch>
294-
<verstretch>0</verstretch>
295-
</sizepolicy>
296-
</property>
297-
<property name="minimumSize">
298-
<size>
299-
<width>120</width>
300-
<height>0</height>
301-
</size>
302-
</property>
303-
</widget>
304-
</item>
305-
<item row="2" column="0">
306-
<widget class="QLabel" name="label_17">
307-
<property name="text">
308-
<string>X</string>
309-
</property>
310-
</widget>
311-
</item>
312-
<item row="0" column="0" colspan="2">
313-
<widget class="QLabel" name="label_11">
314-
<property name="text">
315-
<string>Light Direction</string>
316-
</property>
317-
</widget>
318-
</item>
319-
<item row="6" column="0">
219+
<item row="7" column="0">
320220
<widget class="QLabel" name="label_14">
321221
<property name="text">
322222
<string>Intensity</string>
@@ -440,6 +340,95 @@
440340
</item>
441341
</layout>
442342
</item>
343+
<item row="7" column="1">
344+
<widget class="QgsDoubleSpinBox" name="spinDirectionalIntensity">
345+
<property name="decimals">
346+
<number>1</number>
347+
</property>
348+
<property name="maximum">
349+
<double>999999.000000000000000</double>
350+
</property>
351+
</widget>
352+
</item>
353+
<item row="6" column="0">
354+
<widget class="QLabel" name="label_16">
355+
<property name="text">
356+
<string>Color</string>
357+
</property>
358+
</widget>
359+
</item>
360+
<item row="6" column="1">
361+
<widget class="QgsColorButton" name="btnDirectionalColor">
362+
<property name="sizePolicy">
363+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
364+
<horstretch>0</horstretch>
365+
<verstretch>0</verstretch>
366+
</sizepolicy>
367+
</property>
368+
<property name="minimumSize">
369+
<size>
370+
<width>120</width>
371+
<height>0</height>
372+
</size>
373+
</property>
374+
</widget>
375+
</item>
376+
<item row="0" column="0" colspan="2">
377+
<widget class="QLabel" name="label_11">
378+
<property name="text">
379+
<string>Light Direction</string>
380+
</property>
381+
</widget>
382+
</item>
383+
<item row="2" column="1">
384+
<layout class="QGridLayout" name="gridLayout_5">
385+
<property name="topMargin">
386+
<number>0</number>
387+
</property>
388+
<item row="0" column="2">
389+
<widget class="QLabel" name="label_13">
390+
<property name="text">
391+
<string>Y</string>
392+
</property>
393+
</widget>
394+
</item>
395+
<item row="0" column="3">
396+
<widget class="QLabel" name="labelY">
397+
<property name="text">
398+
<string>--</string>
399+
</property>
400+
</widget>
401+
</item>
402+
<item row="0" column="4">
403+
<widget class="QLabel" name="label_10">
404+
<property name="text">
405+
<string>Z</string>
406+
</property>
407+
</widget>
408+
</item>
409+
<item row="0" column="0">
410+
<widget class="QLabel" name="label_17">
411+
<property name="text">
412+
<string>X</string>
413+
</property>
414+
</widget>
415+
</item>
416+
<item row="0" column="1">
417+
<widget class="QLabel" name="labelX">
418+
<property name="text">
419+
<string>--</string>
420+
</property>
421+
</widget>
422+
</item>
423+
<item row="0" column="5">
424+
<widget class="QLabel" name="labelZ">
425+
<property name="text">
426+
<string>--</string>
427+
</property>
428+
</widget>
429+
</item>
430+
</layout>
431+
</item>
443432
</layout>
444433
</item>
445434
<item row="0" column="2">
@@ -507,9 +496,6 @@
507496
<tabstop>cboDirectionalLights</tabstop>
508497
<tabstop>btnAddDirectionalLight</tabstop>
509498
<tabstop>btnRemoveDirectionalLight</tabstop>
510-
<tabstop>spinDirectionX</tabstop>
511-
<tabstop>spinDirectionY</tabstop>
512-
<tabstop>spinDirectionZ</tabstop>
513499
<tabstop>btnDirectionalColor</tabstop>
514500
<tabstop>spinDirectionalIntensity</tabstop>
515501
</tabstops>

0 commit comments

Comments
 (0)
Please sign in to comment.