//---------------------------------------------------------------- // getElidedText // static QString getElidedText(double maxWidth, const Text & item, const QFontMetricsF & fm, int flags) { QString text = item.text_.get().toString(); if (item.elide_ != Qt::ElideNone) { QString textElided = fm.elidedText(text, item.elide_, maxWidth, flags); #if 0 if (text != textElided) { std::cerr << "original: " << text.toUtf8().constData() << std::endl << " elided: " << textElided.toUtf8().constData() << std::endl; YAE_ASSERT(false); } #endif text = textElided; } return text; }
void tst_QQuickTextMetrics::functionsWithArguments() { QFETCH(QString, text); QFETCH(Qt::TextElideMode, mode); QFETCH(qreal, width); QQuickTextMetrics metrics; // Ensures that the values actually change. metrics.setText(text + "extra"); metrics.setElideWidth(width + 1); switch (mode) { case Qt::ElideNone: metrics.setElide(Qt::ElideMiddle); break; case Qt::ElideLeft: metrics.setElide(Qt::ElideRight); break; case Qt::ElideMiddle: metrics.setElide(Qt::ElideNone); break; case Qt::ElideRight: metrics.setElide(Qt::ElideLeft); break; } QSignalSpy textSpy(&metrics, SIGNAL(textChanged())); QSignalSpy metricsSpy(&metrics, SIGNAL(metricsChanged())); metrics.setText(text); QCOMPARE(textSpy.count(), 1); QCOMPARE(metricsSpy.count(), 1); QSignalSpy elideSpy(&metrics, SIGNAL(elideChanged())); metrics.setElide(mode); QCOMPARE(elideSpy.count(), 1); QCOMPARE(metricsSpy.count(), 2); QSignalSpy elideWidthSpy(&metrics, SIGNAL(elideWidthChanged())); metrics.setElideWidth(width); QCOMPARE(elideWidthSpy.count(), 1); QCOMPARE(metricsSpy.count(), 3); QFontMetricsF expected = QFontMetricsF(QFont()); QCOMPARE(metrics.elidedText(), expected.elidedText(text, mode, width, 0)); QCOMPARE(metrics.advanceWidth(), expected.width(text)); QCOMPARE(metrics.boundingRect(), expected.boundingRect(text)); QCOMPARE(metrics.width(), expected.boundingRect(text).width()); QCOMPARE(metrics.height(), expected.boundingRect(text).height()); QCOMPARE(metrics.tightBoundingRect(), expected.tightBoundingRect(text)); }