on xenial help sign in
Fix mock MirSurfaceItem::orientationAngle implementation
3de69ceDaniel d'Andrada
tests/mocks/Unity/Application/MirSurfaceItem.cpp+36−10
@@ -68,6 +68,7 @@ MirSurfaceItem::~MirSurfaceItem()
68{
68{
69 DEBUG_MSG((void*)(this) << name());
69 DEBUG_MSG((void*)(this) << name());
70 setSurface(nullptr);
70 setSurface(nullptr);
71+ delete m_orientationAngle;
71}
72}
72
73
73void MirSurfaceItem::printComponentErrors()
74void MirSurfaceItem::printComponentErrors()
@@ -125,7 +126,10 @@ Mir::ShellChrome MirSurfaceItem::shellChrome() const
125
126
126Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
127Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
127{
128{
129+ if (m_orientationAngle) {
130+ Q_ASSERT(!m_qmlSurface);
131+ return *m_orientationAngle;
128− if (m_qmlSurface) {
132+ } else if (m_qmlSurface) {
129 return m_qmlSurface->orientationAngle();
133 return m_qmlSurface->orientationAngle();
130 } else {
134 } else {
131 return Mir::Angle0;
135 return Mir::Angle0;
@@ -134,16 +138,24 @@ Mir::OrientationAngle MirSurfaceItem::orientationAngle() const
134
138
135void MirSurfaceItem::setOrientationAngle(Mir::OrientationAngle angle)
139void MirSurfaceItem::setOrientationAngle(Mir::OrientationAngle angle)
136{
140{
137− if (!m_qmlSurface)
141+ DEBUG_MSG(angle);
138− return;
139−
140− if (m_qmlSurface->orientationAngle() == angle)
141− return;
142
142
143+ if (m_qmlSurface) {
144+ Q_ASSERT(!m_orientationAngle);
143− m_qmlSurface->setOrientationAngle(angle);
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+ }
144
154
155+ if (m_qmlItem) {
145− QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
156+ QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
146− orientationProp.write(QVariant::fromValue(m_qmlSurface->orientationAngle()));
157+ orientationProp.write(QVariant::fromValue(orientationAngle()));
158+ }
147}
159}
148
160
149void MirSurfaceItem::updateScreenshot(QUrl screenshotUrl)
161void MirSurfaceItem::updateScreenshot(QUrl screenshotUrl)
@@ -175,6 +187,11 @@ void MirSurfaceItem::createQmlContentItem()
175 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
187 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
176 screenshotSource.write(QVariant::fromValue(m_qmlSurface->screenshotUrl()));
188 screenshotSource.write(QVariant::fromValue(m_qmlSurface->screenshotUrl()));
177 }
189 }
190+
191+ {
192+ QQmlProperty orientationProp(m_qmlItem, "orientationAngle");
193+ orientationProp.write(QVariant::fromValue(orientationAngle()));
194+ }
178}
195}
179
196
180void MirSurfaceItem::touchEvent(QTouchEvent * event)
197void MirSurfaceItem::touchEvent(QTouchEvent * event)
@@ -255,7 +272,16 @@ void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
255 updateSurfaceSize();
272 updateSurfaceSize();
256 updateMirSurfaceVisibility();
273 updateMirSurfaceVisibility();
257
274
275+ if (m_orientationAngle) {
276+ m_qmlSurface->setOrientationAngle(*m_orientationAngle);
258− connect(m_qmlSurface, &MirSurface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
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+
259 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
285 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
260 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
286 connect(m_qmlSurface, &MirSurface::liveChanged, this, &MirSurfaceItem::liveChanged);
261 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
287 connect(m_qmlSurface, &MirSurface::stateChanged, this, &MirSurfaceItem::surfaceStateChanged);
tests/mocks/Unity/Application/MirSurfaceItem.h+2
@@ -117,6 +117,8 @@ private:
117
117
118 bool m_consumesInput;
118 bool m_consumesInput;
119
119
120+ Mir::OrientationAngle *m_orientationAngle{nullptr};
121+
120 int m_surfaceWidth;
122 int m_surfaceWidth;
121 int m_surfaceHeight;
123 int m_surfaceHeight;
122
124