Skip to content

Commit

Permalink
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integ…
Browse files Browse the repository at this point in the history
…ration

* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml:
  Document section behavior when not ordered by section
  Fix TextInput cursor position unchanged when selection length is 0.
  Fix TextInput echoMode clearing inputMethodHints set by the user.
  Elide has unexpected effect on Text's implicitWidth
  • Loading branch information
Qt Continuous Integration System committed Apr 21, 2011
2 parents 43bce78 + f14ac31 commit 87c0329
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/declarative/graphicsitems/qdeclarativelistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2302,11 +2302,19 @@ void QDeclarativeListView::setCacheBuffer(int b)
depending on the "size" property of the model item. The \c sectionHeading
delegate component provides the light blue bar that marks the beginning of
each section.
\snippet examples/declarative/modelviews/listview/sections.qml 0
\image qml-listview-sections-example.png
\note Adding sections to a ListView does not automatically re-order the
list items by the section criteria.
If the model is not ordered by section, then it is possible that
the sections created will not be unique; each boundary between
differing sections will result in a section header being created
even if that section exists elsewhere.
\sa {declarative/modelviews/listview}{ListView examples}
*/
QDeclarativeViewSection *QDeclarativeListView::sectionCriteria()
Expand Down
23 changes: 18 additions & 5 deletions src/declarative/graphicsitems/qdeclarativetext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ QDeclarativeTextPrivate::QDeclarativeTextPrivate()
format(QDeclarativeText::AutoText), wrapMode(QDeclarativeText::NoWrap), lineHeight(1),
lineHeightMode(QDeclarativeText::ProportionalHeight), lineCount(1), truncated(false), maximumLineCount(INT_MAX),
maximumLineCountValid(false), imageCacheDirty(true), updateOnComponentComplete(true), richText(false), singleline(false),
cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), hAlignImplicit(true), rightToLeftText(false), naturalWidth(0), doc(0)
cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), hAlignImplicit(true),
rightToLeftText(false), layoutTextElided(false), naturalWidth(0), doc(0)
{
cacheAllTextAsImage = enableImageCache();
QGraphicsItemPrivate::acceptedMouseButtons = Qt::LeftButton;
Expand Down Expand Up @@ -217,6 +218,7 @@ void QDeclarativeTextPrivate::updateLayout()
return;
}

layoutTextElided = false;
// Setup instance of QTextLayout for all cases other than richtext
if (!richText) {
layout.clearLayout();
Expand All @@ -227,10 +229,13 @@ void QDeclarativeTextPrivate::updateLayout()
singleline = !tmp.contains(QChar::LineSeparator);
if (singleline && !maximumLineCountValid && elideMode != QDeclarativeText::ElideNone && q->widthValid()) {
QFontMetrics fm(font);
tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); // XXX still worth layout...?
if (tmp != text && !truncated) {
truncated = true;
emit q->truncatedChanged();
tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width());
if (tmp != text) {
layoutTextElided = true;
if (!truncated) {
truncated = true;
emit q->truncatedChanged();
}
}
}
layout.setText(tmp);
Expand Down Expand Up @@ -377,6 +382,12 @@ QRect QDeclarativeTextPrivate::setupTextLayout()

if (requireImplicitWidth && q->widthValid()) {
// requires an extra layout
QString elidedText;
if (layoutTextElided) {
// We have provided elided text to the layout, but we must calculate unelided width.
elidedText = layout.text();
layout.setText(text);
}
layout.beginLayout();
forever {
QTextLine line = layout.createLine();
Expand All @@ -390,6 +401,8 @@ QRect QDeclarativeTextPrivate::setupTextLayout()
br = br.united(line.naturalTextRect());
}
naturalWidth = br.width();
if (layoutTextElided)
layout.setText(elidedText);
}

if (maximumLineCountValid) {
Expand Down
1 change: 1 addition & 0 deletions src/declarative/graphicsitems/qdeclarativetext_p_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextPrivate : public QDeclarativeImplicitSiz
bool requireImplicitWidth:1;
bool hAlignImplicit:1;
bool rightToLeftText:1;
bool layoutTextElided:1;

QRect layedOutTextRect;
QSize paintedSize;
Expand Down
40 changes: 30 additions & 10 deletions src/declarative/graphicsitems/qdeclarativetextinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,20 @@ bool QDeclarativeTextInput::hasAcceptableInput() const
state.
*/

void QDeclarativeTextInputPrivate::updateInputMethodHints()
{
Q_Q(QDeclarativeTextInput);
Qt::InputMethodHints hints = inputMethodHints;
uint echo = control->echoMode();
if (echo == QDeclarativeTextInput::Password || echo == QDeclarativeTextInput::NoEcho)
hints |= Qt::ImhHiddenText;
else if (echo == QDeclarativeTextInput::PasswordEchoOnEdit)
hints &= ~Qt::ImhHiddenText;
if (echo != QDeclarativeTextInput::Normal)
hints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
q->setInputMethodHints(hints);
}

/*!
\qmlproperty enumeration TextInput::echoMode
Expand All @@ -884,21 +898,27 @@ void QDeclarativeTextInput::setEchoMode(QDeclarativeTextInput::EchoMode echo)
Q_D(QDeclarativeTextInput);
if (echoMode() == echo)
return;
Qt::InputMethodHints imHints = inputMethodHints();
if (echo == Password || echo == NoEcho)
imHints |= Qt::ImhHiddenText;
else
imHints &= ~Qt::ImhHiddenText;
if (echo != Normal)
imHints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
else
imHints &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
setInputMethodHints(imHints);
d->control->setEchoMode((uint)echo);
d->updateInputMethodHints();
q_textChanged();
emit echoModeChanged(echoMode());
}

Qt::InputMethodHints QDeclarativeTextInput::imHints() const
{
Q_D(const QDeclarativeTextInput);
return d->inputMethodHints;
}

void QDeclarativeTextInput::setIMHints(Qt::InputMethodHints hints)
{
Q_D(QDeclarativeTextInput);
if (d->inputMethodHints == hints)
return;
d->inputMethodHints = hints;
d->updateInputMethodHints();
}

/*!
\qmlproperty Component TextInput::cursorDelegate
The delegate for the cursor in the TextInput.
Expand Down
5 changes: 4 additions & 1 deletion src/declarative/graphicsitems/qdeclarativetextinput_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInput : public QDeclarativeImplicitSizeP
Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
#endif
Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ imHints WRITE setIMHints)

Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
Expand Down Expand Up @@ -215,6 +215,9 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInput : public QDeclarativeImplicitSizeP

bool isInputMethodComposing() const;

Qt::InputMethodHints imHints() const;
void setIMHints(Qt::InputMethodHints hints);

Q_SIGNALS:
void textChanged();
void cursorPositionChanged();
Expand Down
4 changes: 3 additions & 1 deletion src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInputPrivate : public QDeclarativeImplic
QDeclarativeTextInputPrivate() : control(new QLineControl(QString())),
color((QRgb)0), style(QDeclarativeText::Normal),
styleColor((QRgb)0), hAlign(QDeclarativeTextInput::AlignLeft),
mouseSelectionMode(QDeclarativeTextInput::SelectCharacters),
mouseSelectionMode(QDeclarativeTextInput::SelectCharacters), inputMethodHints(Qt::ImhNone),
hscroll(0), oldScroll(0), oldValidity(false), focused(false), focusOnPress(true),
showInputPanelOnFocus(true), clickCausedFocus(false), cursorVisible(false),
autoScroll(true), selectByMouse(false), canPaste(false), hAlignImplicit(true)
Expand Down Expand Up @@ -108,6 +108,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInputPrivate : public QDeclarativeImplic
void mirrorChange();
int calculateTextWidth();
bool sendMouseEventToInputContext(QGraphicsSceneMouseEvent *event, QEvent::Type eventType);
void updateInputMethodHints();

QLineControl* control;

Expand All @@ -120,6 +121,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInputPrivate : public QDeclarativeImplic
QColor styleColor;
QDeclarativeTextInput::HAlignment hAlign;
QDeclarativeTextInput::SelectionMode mouseSelectionMode;
Qt::InputMethodHints inputMethodHints;
QPointer<QDeclarativeComponent> cursorComponent;
QPointer<QDeclarativeItem> cursorItem;
QPointF pressPos;
Expand Down
10 changes: 9 additions & 1 deletion src/gui/widgets/qlinecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,20 @@ void QLineControl::setSelection(int start, int length)
m_selstart = start;
m_selend = qMin(start + length, (int)m_text.length());
m_cursor = m_selend;
} else {
} else if (length < 0){
if (start == m_selend && start + length == m_selstart)
return;
m_selstart = qMax(start + length, 0);
m_selend = start;
m_cursor = m_selstart;
} else if (m_selstart != m_selend) {
m_selstart = 0;
m_selend = 0;
m_cursor = start;
} else {
m_cursor = start;
emitCursorPositionChanged();
return;
}
emit selectionChanged();
emitCursorPositionChanged();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import QtQuick 1.1

Text {
text: "Hello World"
elide: Text.ElideRight
width: 30
}
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ void tst_qdeclarativetext::elide()
QCOMPARE(textObject->width(), 100.);
}
}

// QTBUG-18627
QUrl qmlfile = QUrl::fromLocalFile(SRCDIR "/data/elideimplicitwidth.qml");
QDeclarativeComponent textComponent(&engine, qmlfile);
QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(textComponent.create());
QVERIFY(item != 0);
QVERIFY(item->implicitWidth() > item->width());
}

void tst_qdeclarativetext::textFormat()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,14 @@ void tst_qdeclarativetextedit::selection()
QCOMPARE(textEditObject->selectionEnd(), i);
QVERIFY(textEditObject->selectedText().isNull());
}
//Test cursor follows selection
for(int i=0; i<= testStr.size(); i++) {
textEditObject->select(i,i);
QCOMPARE(textEditObject->cursorPosition(), i);
QCOMPARE(textEditObject->selectionStart(), i);
QCOMPARE(textEditObject->selectionEnd(), i);
}


textEditObject->setCursorPosition(0);
QVERIFY(textEditObject->cursorPosition() == 0);
Expand All @@ -812,10 +820,12 @@ void tst_qdeclarativetextedit::selection()
for(int i=0; i<= testStr.size(); i++) {
textEditObject->select(0,i);
QCOMPARE(testStr.mid(0,i), textEditObject->selectedText());
QCOMPARE(textEditObject->cursorPosition(), i);
}
for(int i=0; i<= testStr.size(); i++) {
textEditObject->select(i,testStr.size());
QCOMPARE(testStr.mid(i,testStr.size()-i), textEditObject->selectedText());
QCOMPARE(textEditObject->cursorPosition(), testStr.size());
}

textEditObject->setCursorPosition(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ void tst_qdeclarativetextinput::selection()
QCOMPARE(textinputObject->selectionEnd(), i);
QVERIFY(textinputObject->selectedText().isNull());
}
//Test cursor follows selection
for(int i=0; i<= testStr.size(); i++) {
textinputObject->select(i,i);
QCOMPARE(textinputObject->cursorPosition(), i);
QCOMPARE(textinputObject->selectionStart(), i);
QCOMPARE(textinputObject->selectionEnd(), i);
}

textinputObject->setCursorPosition(0);
QVERIFY(textinputObject->cursorPosition() == 0);
Expand All @@ -399,10 +406,12 @@ void tst_qdeclarativetextinput::selection()
for(int i=0; i<= testStr.size(); i++) {
textinputObject->select(0,i);
QCOMPARE(testStr.mid(0,i), textinputObject->selectedText());
QCOMPARE(textinputObject->cursorPosition(), i);
}
for(int i=0; i<= testStr.size(); i++) {
textinputObject->select(i,testStr.size());
QCOMPARE(testStr.mid(i,testStr.size()-i), textinputObject->selectedText());
QCOMPARE(textinputObject->cursorPosition(), testStr.size());
}

textinputObject->setCursorPosition(0);
Expand Down Expand Up @@ -1364,8 +1373,10 @@ void tst_qdeclarativetextinput::inputMethods()
QVERIFY(canvas->rootObject() != 0);
QDeclarativeTextInput *input = qobject_cast<QDeclarativeTextInput *>(canvas->rootObject());
QVERIFY(input != 0);
QVERIFY(input->imHints() & Qt::ImhNoPredictiveText);
QVERIFY(input->inputMethodHints() & Qt::ImhNoPredictiveText);
input->setInputMethodHints(Qt::ImhUppercaseOnly);
input->setIMHints(Qt::ImhUppercaseOnly);
QVERIFY(input->imHints() & Qt::ImhUppercaseOnly);
QVERIFY(input->inputMethodHints() & Qt::ImhUppercaseOnly);

QVERIFY(canvas->rootObject() != 0);
Expand Down Expand Up @@ -1805,6 +1816,7 @@ void tst_qdeclarativetextinput::echoMode()
ref &= ~Qt::ImhHiddenText;
ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
QCOMPARE(input->imHints(), Qt::ImhNone);
input->setEchoMode(QDeclarativeTextInput::NoEcho);
QCOMPARE(input->text(), initial);
QCOMPARE(input->displayText(), QLatin1String(""));
Expand All @@ -1813,13 +1825,15 @@ void tst_qdeclarativetextinput::echoMode()
ref |= Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
QCOMPARE(input->imHints(), Qt::ImhNone);
input->setEchoMode(QDeclarativeTextInput::Password);
//Password
ref |= Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->text(), initial);
QCOMPARE(input->displayText(), QLatin1String("********"));
QCOMPARE(input->inputMethodHints(), ref);
QCOMPARE(input->imHints(), Qt::ImhNone);
input->setPasswordCharacter(QChar('Q'));
QCOMPARE(input->passwordCharacter(), QLatin1String("Q"));
QCOMPARE(input->text(), initial);
Expand All @@ -1829,6 +1843,7 @@ void tst_qdeclarativetextinput::echoMode()
ref &= ~Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
QCOMPARE(input->imHints(), Qt::ImhNone);
QCOMPARE(input->text(), initial);
QCOMPARE(input->displayText(), QLatin1String("QQQQQQQQ"));
QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QLatin1String("QQQQQQQQ"));
Expand All @@ -1849,6 +1864,40 @@ void tst_qdeclarativetextinput::echoMode()
QCOMPARE(input->displayText(), initial);
QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), initial);

// Test echo mode doesn't override imHints.
input->setIMHints(Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
ref |= Qt::ImhDialableCharactersOnly;
//Normal
input->setEchoMode(QDeclarativeTextInput::Normal);
ref |= Qt::ImhHiddenText;
ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
//NoEcho
input->setEchoMode(QDeclarativeTextInput::NoEcho);
ref |= Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
//Password
input->setEchoMode(QDeclarativeTextInput::Password);
ref |= Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
//PasswordEchoOnEdit
input->setEchoMode(QDeclarativeTextInput::PasswordEchoOnEdit);
ref &= ~Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
//Normal
input->setEchoMode(QDeclarativeTextInput::Normal);
ref |= Qt::ImhHiddenText;
ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);

delete canvas;
}

Expand Down

0 comments on commit 87c0329

Please sign in to comment.