Merge remote-tracking branch 'origin/5.9' into 5.10

Change-Id: I6b40ecee4db13e6329e7a0433b57c5bca473c63f
This commit is contained in:
Liang Qi 2018-01-29 20:49:23 +01:00
commit 27e8612fa4
11 changed files with 162 additions and 58 deletions

View File

@ -3,4 +3,8 @@ requires(qtHaveModule(widgets))
TEMPLATE = subdirs
qtConfig(sharedmemory): SUBDIRS = sharedmemory
qtHaveModule(network): SUBDIRS += localfortuneserver localfortuneclient
qtHaveModule(network) {
QT_FOR_CONFIG += network
qtConfig(localserver): SUBDIRS += localfortuneserver localfortuneclient
}

View File

@ -64,6 +64,8 @@
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QSurfaceFormat fmt;
fmt.setDepthBufferSize(24);
@ -79,8 +81,6 @@ int main(int argc, char *argv[])
QSurfaceFormat::setDefaultFormat(fmt);
QGuiApplication app(argc, argv);
GLWindow glWindow;
glWindow.showMaximized();

View File

@ -51,6 +51,7 @@ import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.widget.PopupWindow;
import android.app.Activity;
import android.util.TypedValue;
import android.view.ViewTreeObserver;
/* This view represents one of the handle (selection or cursor handle) */
@ -58,8 +59,9 @@ class CursorView extends ImageView
{
private CursorHandle mHandle;
// The coordinare which where clicked
private int m_offsetX;
private int m_offsetY;
private float m_offsetX;
private float m_offsetY;
private boolean m_pressed = false;
CursorView (Context context, CursorHandle handle) {
super(context);
@ -76,21 +78,23 @@ class CursorView extends ImageView
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
m_offsetX = Math.round(ev.getRawX());
m_offsetY = Math.round(ev.getRawY());
m_offsetX = ev.getRawX();
m_offsetY = ev.getRawY() + getHeight() / 2;
m_pressed = true;
break;
}
case MotionEvent.ACTION_MOVE: {
mHandle.updatePosition(Math.round(ev.getRawX()) - m_offsetX,
Math.round(ev.getRawY()) - m_offsetY);
if (!m_pressed)
return false;
mHandle.updatePosition(Math.round(ev.getRawX() - m_offsetX),
Math.round(ev.getRawY() - m_offsetY));
break;
}
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_CANCEL:
m_pressed = false;
break;
}
return true;
@ -113,6 +117,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
private int m_lastY;
int tolerance;
private boolean m_rtl;
int m_yShift;
public CursorHandle(Activity activity, View layout, int id, int attr, boolean rtl) {
m_activity = activity;
@ -121,7 +126,8 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
m_layout = layout;
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
tolerance = Math.round(2 * metrics.density);
m_yShift = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1f, metrics);
tolerance = Math.min(1, (int)(m_yShift / 2f));
m_lastX = m_lastY = -1 - tolerance;
m_rtl = rtl;
}
@ -158,7 +164,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
m_layout.getLocationOnScreen(location);
int x2 = x + location[0];
int y2 = y + location[1];
int y2 = y + location[1] + m_yShift;
if (m_id == QtNative.IdCursorHandle) {
x2 -= m_cursorView.getWidth() / 2 ;
@ -187,6 +193,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
// The handle was dragged by a given relative position
public void updatePosition(int x, int y) {
y -= m_yShift;
if (Math.abs(m_lastX - x) > tolerance || Math.abs(m_lastY - y) > tolerance) {
QtNative.handleLocationChanged(m_id, x + m_posX, y + m_posY);
m_lastX = x;

View File

@ -287,6 +287,8 @@ void QPlatformInputContext::setSelectionOnFocusObject(const QPointF &anchorPos,
if (success) {
int cursor = QInputMethod::queryFocusObject(Qt::ImCursorPosition, cursorPos * mapToLocal).toInt(&success);
if (success) {
if (anchor == cursor && anchorPos != cursorPos)
return;
QList<QInputMethodEvent::Attribute> imAttributes;
imAttributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, anchor, cursor - anchor, QVariant()));
QInputMethodEvent event(QString(), imAttributes);

View File

@ -438,6 +438,16 @@ QAndroidInputContext::QAndroidInputContext()
QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged,
this, &QAndroidInputContext::updateSelectionHandles);
QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::anchorRectangleChanged,
this, &QAndroidInputContext::updateSelectionHandles);
QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::inputItemClipRectangleChanged, this, [this]{
auto im = qGuiApp->inputMethod();
if (!im->inputItemClipRectangle().contains(im->anchorRectangle()) ||
!im->inputItemClipRectangle().contains(im->cursorRectangle())) {
m_cursorHandleShown = CursorHandleNotShown;
updateSelectionHandles();
}
});
}
QAndroidInputContext::~QAndroidInputContext()
@ -595,27 +605,63 @@ void QAndroidInputContext::handleLocationChanged(int handleId, int x, int y)
double pixelDensity = window
? QHighDpiScaling::factor(window)
: QHighDpiScaling::factor(QtAndroid::androidPlatformIntegration()->screen());
QPoint point(x / pixelDensity, y / pixelDensity);
y -= leftRect.width() / 2;
QPointF point(x / pixelDensity, y / pixelDensity);
point.setY(point.y() - leftRect.width() / 2);
if (handleId == 1) {
setSelectionOnFocusObject(point, point);
return;
}
QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition);
QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition | Qt::ImCurrentSelection);
QCoreApplication::sendEvent(m_focusObject, &query);
int cpos = query.value(Qt::ImCursorPosition).toInt();
int anchor = query.value(Qt::ImAnchorPosition).toInt();
bool rtl = query.value(Qt::ImCurrentSelection).toString().isRightToLeft();
auto rightRect = im->anchorRectangle();
if (cpos > anchor)
std::swap(leftRect, rightRect);
auto checkLeftHandle = [&rightRect](QPointF &handlePos) {
if (handlePos.y() > rightRect.center().y())
handlePos.setY(rightRect.center().y()); // adjust Y handle pos
if (handlePos.y() >= rightRect.y() && handlePos.y() <= rightRect.bottom() && handlePos.x() >= rightRect.x())
return false; // same line and wrong X pos ?
return true;
};
auto checkRtlRightHandle = [&rightRect](QPointF &handlePos) {
if (handlePos.y() > rightRect.center().y())
handlePos.setY(rightRect.center().y()); // adjust Y handle pos
if (handlePos.y() >= rightRect.y() && handlePos.y() <= rightRect.bottom() && rightRect.x() >= handlePos.x())
return false; // same line and wrong X pos ?
return true;
};
auto checkRightHandle = [&leftRect](QPointF &handlePos) {
if (handlePos.y() < leftRect.center().y())
handlePos.setY(leftRect.center().y()); // adjust Y handle pos
if (handlePos.y() >= leftRect.y() && handlePos.y() <= leftRect.bottom() && leftRect.x() >= handlePos.x())
return false; // same line and wrong X pos ?
return true;
};
auto checkRtlLeftHandle = [&leftRect](QPointF &handlePos) {
if (handlePos.y() < leftRect.center().y())
handlePos.setY(leftRect.center().y()); // adjust Y handle pos
if (handlePos.y() >= leftRect.y() && handlePos.y() <= leftRect.bottom() && handlePos.x() >= leftRect.x())
return false; // same line and wrong X pos ?
return true;
};
if (handleId == 2) {
QPoint rightPoint(rightRect.center().toPoint());
QPointF rightPoint(rightRect.center());
if ((!rtl && !checkLeftHandle(point)) || (rtl && !checkRtlRightHandle(point)))
return;
setSelectionOnFocusObject(point, rightPoint);
} else if (handleId == 3) {
QPoint leftPoint(leftRect.center().toPoint());
QPointF leftPoint(leftRect.center());
if ((!rtl && !checkRightHandle(point)) || (rtl && !checkRtlLeftHandle(point)))
return;
setSelectionOnFocusObject(leftPoint, point);
}
}

View File

@ -72,8 +72,6 @@
**
****************************************************************************/
#define QT_MAC_SYSTEMTRAY_USE_GROWL
#include "qcocoasystemtrayicon.h"
#ifndef QT_NO_SYSTEMTRAYICON

View File

@ -351,7 +351,7 @@ void QHeaderView::setModel(QAbstractItemModel *model)
if (model == this->model())
return;
Q_D(QHeaderView);
d->persistentHiddenSections.clear();
d->layoutChangePersistentSections.clear();
if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
if (d->orientation == Qt::Horizontal) {
QObject::disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
@ -2072,14 +2072,28 @@ void QHeaderViewPrivate::_q_layoutAboutToBeChanged()
|| model->columnCount(root) == 0)
return;
if (hiddenSectionSize.count() == 0)
return;
layoutChangePersistentSections.clear();
layoutChangePersistentSections.reserve(std::min(10, sectionItems.count()));
// after layoutChanged another section can be last stretched section
if (stretchLastSection) {
const int visual = visualIndex(lastSectionLogicalIdx);
sectionItems[visual].size = lastSectionSize;
}
for (int i = 0; i < sectionItems.size(); ++i) {
const auto &s = sectionItems.at(i);
// only add if the section is not default and not visually moved
if (s.size == defaultSectionSize && !s.isHidden && s.resizeMode == globalResizeMode)
continue;
for (int i = 0; i < sectionItems.count(); ++i)
if (isVisualIndexHidden(i)) // ### note that we are using column or row 0
persistentHiddenSections.append(orientation == Qt::Horizontal
? model->index(0, logicalIndex(i), root)
: model->index(logicalIndex(i), 0, root));
// ### note that we are using column or row 0
layoutChangePersistentSections.append({orientation == Qt::Horizontal
? model->index(0, logicalIndex(i), root)
: model->index(logicalIndex(i), 0, root),
s});
if (layoutChangePersistentSections.size() > 1000)
break;
}
}
void QHeaderViewPrivate::_q_layoutChanged()
@ -2087,25 +2101,57 @@ void QHeaderViewPrivate::_q_layoutChanged()
Q_Q(QHeaderView);
viewport->update();
const auto hiddenSections = persistentHiddenSections;
persistentHiddenSections.clear();
const auto oldPersistentSections = layoutChangePersistentSections;
layoutChangePersistentSections.clear();
clear();
q->initializeSections();
invalidateCachedSizeHint();
if (modelIsEmpty()) {
const int newCount = modelSectionCount();
const int oldCount = sectionItems.size();
if (newCount == 0) {
clear();
if (oldCount != 0)
emit q->sectionCountChanged(oldCount, 0);
return;
}
for (const auto &index : hiddenSections) {
if (index.isValid()) {
const int logical = (orientation == Qt::Horizontal
? index.column()
: index.row());
q->setSectionHidden(logical, true);
// adjust section size
if (newCount != oldCount) {
const int min = qBound(0, oldCount, newCount - 1);
q->initializeSections(min, newCount - 1);
}
// reset sections
sectionItems.fill(SectionItem(defaultSectionSize, globalResizeMode), newCount);
// all hidden sections are in oldPersistentSections
hiddenSectionSize.clear();
for (const auto &item : oldPersistentSections) {
const auto &index = item.index;
if (!index.isValid())
continue;
const int newLogicalIndex = (orientation == Qt::Horizontal
? index.column()
: index.row());
// the new visualIndices are already adjusted / reset by initializeSections()
const int newVisualIndex = visualIndex(newLogicalIndex);
auto &newSection = sectionItems[newVisualIndex];
newSection = item.section;
if (newSection.isHidden) {
// otherwise setSectionHidden will return without doing anything
newSection.isHidden = false;
q->setSectionHidden(newLogicalIndex, true);
}
}
recalcSectionStartPos();
length = headerLength();
if (stretchLastSection) {
// force rebuild of stretched section later on
lastSectionLogicalIdx = -1;
maybeRestorePrevLastSectionAndStretchLast();
}
}
/*!

View File

@ -231,10 +231,6 @@ public:
: model->rowCount(root));
}
inline bool modelIsEmpty() const {
return (model->rowCount(root) == 0 || model->columnCount(root) == 0);
}
inline void doDelayedResizeSections() {
if (!delayedResize.isActive())
delayedResize.start(0, q_func());
@ -304,7 +300,6 @@ public:
QLabel *sectionIndicator;
#endif
QHeaderView::ResizeMode globalResizeMode;
QList<QPersistentModelIndex> persistentHiddenSections;
mutable bool sectionStartposRecalc;
int resizeContentsPrecision;
// header sections
@ -335,6 +330,11 @@ public:
};
QVector<SectionItem> sectionItems;
struct LayoutChangeItem {
QPersistentModelIndex index;
SectionItem section;
};
QVector<LayoutChangeItem> layoutChangePersistentSections;
void createSectionItems(int start, int end, int size, QHeaderView::ResizeMode mode);
void removeSectionsFromSectionItems(int start, int end);
@ -388,6 +388,7 @@ public:
};
Q_DECLARE_TYPEINFO(QHeaderViewPrivate::SectionItem, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(QHeaderViewPrivate::LayoutChangeItem, Q_MOVABLE_TYPE);
QT_END_NAMESPACE

View File

@ -987,7 +987,7 @@ void QTreeView::setTreePosition(int index)
{
Q_D(QTreeView);
d->treePosition = index;
update();
d->viewport->update();
}
/*!

View File

@ -111,9 +111,7 @@ static QIcon messageIcon2qIcon(QSystemTrayIcon::MessageIcon icon)
\li All X11 desktop environments that implement the D-Bus
\l{http://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem}
specification, including recent versions of KDE and Unity.
\li All supported versions of \macos. Note that the Growl
notification system must be installed for
QSystemTrayIcon::showMessage() to display messages on \macos prior to 10.8 (Mountain Lion).
\li All supported versions of \macos.
\endlist
To check whether a system tray is present on the user's desktop,
@ -420,9 +418,6 @@ bool QSystemTrayIcon::supportsMessages()
On Windows, the \a millisecondsTimeoutHint is usually ignored by the system
when the application has focus.
On \macos, the Growl notification system must be installed for this function to
display messages.
Has been turned into a slot in Qt 5.2.
\sa show(), supportsMessages()

View File

@ -2251,10 +2251,6 @@ void tst_QHeaderView::QTBUG6058_reset()
void tst_QHeaderView::QTBUG7833_sectionClicked()
{
QTableView tv;
QStandardItemModel *sim = new QStandardItemModel(&tv);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(&tv);
@ -2278,11 +2274,20 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
tv.horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
tv.setModel(proxyModel);
const int section4Size = tv.horizontalHeader()->sectionSize(4) + 1;
tv.horizontalHeader()->resizeSection(4, section4Size);
tv.setColumnHidden(5, true);
tv.setColumnHidden(6, true);
tv.horizontalHeader()->swapSections(8, 10);
tv.sortByColumn(1, Qt::AscendingOrder);
QCOMPARE(tv.isColumnHidden(5), true);
QCOMPARE(tv.isColumnHidden(6), true);
QCOMPARE(tv.horizontalHeader()->sectionsMoved(), true);
QCOMPARE(tv.horizontalHeader()->logicalIndex(8), 10);
QCOMPARE(tv.horizontalHeader()->logicalIndex(10), 8);
QCOMPARE(tv.horizontalHeader()->sectionSize(4), section4Size);
QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int)));
QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int)));