on xenial help sign in
Fix mock MirSurfaceItem::orientationAngle implementation

Mirroring what the real implementation in qtmir does.

commit3de69ce86c0b090a695caffe8679a8e80042c2a7 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateWed 22 Jun 2016, 10:52 (10 years ago) parentbb92044
2 files changed+38−10
tests/mocks/Unity/Application/MirSurfaceItem.cpp+36−10 tests/mocks/Unity/Application/MirSurfaceItem.h+2
tests/mocks/Unity/Application/MirSurfaceItem.cpp+36−10
@@ -68,6 +68,7 @@ MirSurfaceItem::~MirSurfaceItem()
6868{
6969 DEBUG_MSG((void*)(this) << name());
7070 setSurface(nullptr);
71+ delete m_orientationAngle;
7172}
7273
7374void MirSurfaceItem::printComponentErrors()
@@ -125,7 +126,10 @@ Mir::ShellChrome MirSurfaceItem::shellChrome() const
125126
126127Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
127128{
128− if (m_qmlSurface) {
129+ if (m_orientationAngle) {
130+ Q_ASSERT(!m_qmlSurface);
131+ return *m_orientationAngle;
132+ } else if (m_qmlSurface) {
129133 return m_qmlSurface->orientationAngle();
130134 } else {
131135 return Mir::Angle0;
@@ -134,16 +138,24 @@ Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
134138
135139void MirSurfaceItem::setOrientationAngle(Mir::OrientationAngle angle)
136140{
137− if (!m_qmlSurface)
138− return;
139−
140− if (m_qmlSurface->orientationAngle() == angle)
141− return;
141+ DEBUG_MSG(angle);
142142
143− m_qmlSurface->setOrientationAngle(angle);
143+ if (m_qmlSurface) {
144+ Q_ASSERT(!m_orientationAngle);
145+ m_qmlSurface->setOrientationAngle(angle);
146+ } else if (!m_orientationAngle) {
147+ m_orientationAngle = new Mir::OrientationAngle;
148+ *m_orientationAngle = angle;
149+ Q_EMIT orientationAngleChanged(angle);
150+ } else if (*m_orientationAngle != angle) {
151+ *m_orientationAngle = angle;
152+ Q_EMIT orientationAngleChanged(angle);
153+ }
144154
145− QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
146− orientationProp.write(QVariant::fromValue(m_qmlSurface->orientationAngle()));
155+ if (m_qmlItem) {
156+ QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
157+ orientationProp.write(QVariant::fromValue(orientationAngle()));
158+ }
147159}
148160
149161void MirSurfaceItem::updateScreenshot(QUrl screenshotUrl)
@@ -175,6 +187,11 @@ void MirSurfaceItem::createQmlContentItem()
175187 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
176188 screenshotSource.write(QVariant::fromValue(m_qmlSurface->screenshotUrl()));
177189 }
190+
191+ {
192+ QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
193+ orientationProp.write(QVariant::fromValue(orientationAngle()));
194+ }
178195}
179196
180197void MirSurfaceItem::touchEvent(QTouchEvent * event)
@@ -255,7 +272,16 @@ void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
255272 updateSurfaceSize();
256273 updateMirSurfaceVisibility();
257274
258− connect(m_qmlSurface, &MirSurface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
275+ if (m_orientationAngle) {
276+ m_qmlSurface->setOrientationAngle(*m_orientationAngle);
277+ connect(m_qmlSurface, &MirSurfaceInterface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
278+ delete m_orientationAngle;
279+ m_orientationAngle = nullptr;
280+ } else {
281+ connect(m_qmlSurface, &MirSurfaceInterface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
282+ Q_EMIT orientationAngleChanged(m_qmlSurface->orientationAngle());
283+ }
284+
259285 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
260286 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
261287 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
tests/mocks/Unity/Application/MirSurfaceItem.h+2
@@ -117,6 +117,8 @@ private:
117117
118118 bool m_consumesInput;
119119
120+ Mir::OrientationAngle *m_orientationAngle{nullptr};
121+
120122 int m_surfaceWidth;
121123 int m_surfaceHeight;
122124