diff options
Diffstat (limited to 'src/gui/itemviews')
21 files changed, 142 insertions, 140 deletions
diff --git a/src/gui/itemviews/qabstractitemdelegate.cpp b/src/gui/itemviews/qabstractitemdelegate.cpp index 22b96fc..447538a 100644 --- a/src/gui/itemviews/qabstractitemdelegate.cpp +++ b/src/gui/itemviews/qabstractitemdelegate.cpp @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE data items from a model. \ingroup model-view - \mainclass + A QAbstractItemDelegate provides the interface and common functionality for delegates in the model/view architecture. Delegates display diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 78f81cb..8f8eae5 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -74,6 +74,7 @@ QAbstractItemViewPrivate::QAbstractItemViewPrivate() currentlyCommittingEditor(0), pressedModifiers(Qt::NoModifier), pressedPosition(QPoint(-1, -1)), + pressedAlreadySelected(false), viewportEnteredNeeded(false), state(QAbstractItemView::NoState), editTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed), @@ -166,7 +167,7 @@ void QAbstractItemViewPrivate::checkMouseMove(const QPersistentModelIndex &index item view classes. \ingroup model-view - \mainclass + QAbstractItemView class is the base class for every standard view that uses a QAbstractItemModel. QAbstractItemView is an abstract @@ -584,7 +585,7 @@ void QAbstractItemView::setModel(QAbstractItemModel *model) "QAbstractItemView::setModel", "The parent of a top level index should be invalid"); - if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) { + if (d->model != QAbstractItemModelPrivate::staticEmptyModel()) { connect(d->model, SIGNAL(destroyed()), this, SLOT(_q_modelDestroyed())); connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), diff --git a/src/gui/itemviews/qcolumnview.cpp b/src/gui/itemviews/qcolumnview.cpp index fd8106f..9597656 100644 --- a/src/gui/itemviews/qcolumnview.cpp +++ b/src/gui/itemviews/qcolumnview.cpp @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE \brief The QColumnView class provides a model/view implementation of a column view. \ingroup model-view \ingroup advanced - \mainclass + QColumnView displays a model in a number of QListViews, one for each hierarchy in the tree. This is sometimes referred to as a cascading list. diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp index efbddde..5d3bb12 100644 --- a/src/gui/itemviews/qheaderview.cpp +++ b/src/gui/itemviews/qheaderview.cpp @@ -88,7 +88,7 @@ QDataStream &operator>>(QDataStream &in, QHeaderViewPrivate::SectionSpan &span) item views. \ingroup model-view - \mainclass + A QHeaderView displays the headers used in item views such as the QTableView and QTreeView classes. It takes the place of Qt3's \c QHeader @@ -2615,7 +2615,7 @@ void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bot int first = orientation() == Qt::Horizontal ? topLeft.column() : topLeft.row(); int last = orientation() == Qt::Horizontal ? bottomRight.column() : bottomRight.row(); for (int i = first; i <= last && !resizeRequired; ++i) - resizeRequired = (resizeRequired && resizeMode(i)); + resizeRequired = (resizeMode(i) == ResizeToContents); if (resizeRequired) d->doDelayedResizeSections(); } diff --git a/src/gui/itemviews/qitemdelegate.cpp b/src/gui/itemviews/qitemdelegate.cpp index 3e42ea6..5b69f44 100644 --- a/src/gui/itemviews/qitemdelegate.cpp +++ b/src/gui/itemviews/qitemdelegate.cpp @@ -185,7 +185,7 @@ QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const data items from a model. \ingroup model-view - \mainclass + QItemDelegate can be used to provide custom display features and editor widgets for item views based on QAbstractItemView subclasses. Using a @@ -352,7 +352,10 @@ void QItemDelegate::setClipping(bool clip) QString QItemDelegatePrivate::valueToText(const QVariant &value, const QStyleOptionViewItemV4 &option) { QString text; - switch (value.type()) { + switch (value.userType()) { + case QMetaType::Float: + text = option.locale.toString(value.toFloat(), 'g'); + break; case QVariant::Double: text = option.locale.toString(value.toDouble(), 'g', DBL_DIG); break; @@ -719,8 +722,6 @@ void QItemDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &o //let's add the last line (after the last QChar::LineSeparator) elided += option.fontMetrics.elidedText(text.mid(start), option.textElideMode, textRect.width()); - if (end != -1) - elided += QChar::LineSeparator; } d->textLayout.setText(elided); textLayoutSize = d->doTextLayout(textRect.width()); diff --git a/src/gui/itemviews/qitemselectionmodel_p.h b/src/gui/itemviews/qitemselectionmodel_p.h index 6e1046c..e9e6bb1 100644 --- a/src/gui/itemviews/qitemselectionmodel_p.h +++ b/src/gui/itemviews/qitemselectionmodel_p.h @@ -65,7 +65,7 @@ public: QItemSelectionModelPrivate() : model(0), currentCommand(QItemSelectionModel::NoUpdate), - tableSelected(false) {} + tableSelected(false), tableColCount(0), tableRowCount(0) {} QItemSelection expandSelection(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) const; diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp index 945d5e7..ea38f5f 100644 --- a/src/gui/itemviews/qlistview.cpp +++ b/src/gui/itemviews/qlistview.cpp @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE \ingroup model-view \ingroup advanced - \mainclass + A QListView presents items stored in a model, either as a simple non-hierarchical list, or as a collection of icons. This class is used @@ -1957,7 +1957,6 @@ bool QListView::event(QEvent *e) QListViewPrivate::QListViewPrivate() : QAbstractItemViewPrivate(), dynamicListView(0), - staticListView(0), wrap(false), space(0), flow(QListView::TopToBottom), @@ -1968,14 +1967,17 @@ QListViewPrivate::QListViewPrivate() modeProperties(0), column(0), uniformItemSizes(false), - batchSize(100) + batchSize(100), + showElasticBand(false) { } QListViewPrivate::~QListViewPrivate() { - delete staticListView; - delete dynamicListView; + if (viewMode == QListView::ListMode) + delete staticListView; + else + delete dynamicListView; } void QListViewPrivate::clear() diff --git a/src/gui/itemviews/qlistview_p.h b/src/gui/itemviews/qlistview_p.h index 1131059..6c8d324 100644 --- a/src/gui/itemviews/qlistview_p.h +++ b/src/gui/itemviews/qlistview_p.h @@ -351,9 +351,10 @@ public: QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const; - // ### FIXME: we only need one at a time - QDynamicListViewBase *dynamicListView; - QStaticListViewBase *staticListView; + union { + QDynamicListViewBase *dynamicListView; + QStaticListViewBase *staticListView; + }; // ### FIXME: see if we can move the members into the dynamic/static classes diff --git a/src/gui/itemviews/qlistwidget.cpp b/src/gui/itemviews/qlistwidget.cpp index 2792bbd..232b4d2 100644 --- a/src/gui/itemviews/qlistwidget.cpp +++ b/src/gui/itemviews/qlistwidget.cpp @@ -708,9 +708,7 @@ QVariant QListWidgetItem::data(int role) const bool QListWidgetItem::operator<(const QListWidgetItem &other) const { const QVariant v1 = data(Qt::DisplayRole), v2 = other.data(Qt::DisplayRole); - if (QAbstractItemModelPrivate::canConvertToDouble(v1) && QAbstractItemModelPrivate::canConvertToDouble(v2)) - return v1.toDouble() < v2.toDouble(); - return v1.toString() < v2.toString(); + return QAbstractItemModelPrivate::variantLessThan(v1, v2); } #ifndef QT_NO_DATASTREAM @@ -1127,7 +1125,7 @@ void QListWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, \brief The QListWidget class provides an item-based list widget. \ingroup model-view - \mainclass + QListWidget is a convenience class that provides a list view similar to the one supplied by QListView, but with a classic item-based interface for diff --git a/src/gui/itemviews/qlistwidget_p.h b/src/gui/itemviews/qlistwidget_p.h index 124222c..0851e20 100644 --- a/src/gui/itemviews/qlistwidget_p.h +++ b/src/gui/itemviews/qlistwidget_p.h @@ -163,7 +163,6 @@ class QListWidgetItemPrivate public: QListWidgetItemPrivate(QListWidgetItem *item) : q(item), theid(-1) {} QListWidgetItem *q; - int id; QVector<QWidgetItemData> values; int theid; }; diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp index d39506d..d173efe 100644 --- a/src/gui/itemviews/qsortfilterproxymodel.cpp +++ b/src/gui/itemviews/qsortfilterproxymodel.cpp @@ -1278,82 +1278,76 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsRemoved( /*! \since 4.1 \class QSortFilterProxyModel - \brief The QSortFilterProxyModel class provides support for sorting and filtering data passed - between another model and a view. + \brief The QSortFilterProxyModel class provides support for sorting and + filtering data passed between another model and a view. \ingroup model-view - QSortFilterProxyModel can be used for sorting items, filtering - out items, or both. The model transforms the structure of a - source model by mapping the model indexes it supplies to new - indexes, corresponding to different locations, for views to use. - This approach allows a given source model to be restructured as - far as views are concerned without requiring any transformations - on the underlying data, and without duplicating the data in + QSortFilterProxyModel can be used for sorting items, filtering out items, + or both. The model transforms the structure of a source model by mapping + the model indexes it supplies to new indexes, corresponding to different + locations, for views to use. This approach allows a given source model to + be restructured as far as views are concerned without requiring any + transformations on the underlying data, and without duplicating the data in memory. - Let's assume that we want to sort and filter the items provided - by a custom model. The code to set up the model and the view, \e - without sorting and filtering, would look like this: + Let's assume that we want to sort and filter the items provided by a custom + model. The code to set up the model and the view, \e without sorting and + filtering, would look like this: \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 1 - To add sorting and filtering support to \c MyItemModel, we need - to create a QSortFilterProxyModel, call setSourceModel() with the - \c MyItemModel as argument, and install the QSortFilterProxyModel - on the view: + To add sorting and filtering support to \c MyItemModel, we need to create + a QSortFilterProxyModel, call setSourceModel() with the \c MyItemModel as + argument, and install the QSortFilterProxyModel on the view: \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 0 \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 2 - At this point, neither sorting nor filtering is enabled; the - original data is displayed in the view. Any changes made through - the QSortFilterProxyModel are applied to the original model. + At this point, neither sorting nor filtering is enabled; the original data + is displayed in the view. Any changes made through the + QSortFilterProxyModel are applied to the original model. - The QSortFilterProxyModel acts as a wrapper for the original - model. If you need to convert source \l{QModelIndex}es to - sorted/filtered model indexes or vice versa, use mapToSource(), - mapFromSource(), mapSelectionToSource(), and - mapSelectionFromSource(). + The QSortFilterProxyModel acts as a wrapper for the original model. If you + need to convert source \l{QModelIndex}es to sorted/filtered model indexes + or vice versa, use mapToSource(), mapFromSource(), mapSelectionToSource(), + and mapSelectionFromSource(). - \note By default, the model does not dynamically re-sort and re-filter - data whenever the original model changes. This behavior can be - changed by setting the \l{QSortFilterProxyModel::dynamicSortFilter} - {dynamicSortFilter} property. + \note By default, the model does not dynamically re-sort and re-filter data + whenever the original model changes. This behavior can be changed by + setting the \l{QSortFilterProxyModel::dynamicSortFilter}{dynamicSortFilter} + property. - The \l{itemviews/basicsortfiltermodel}{Basic Sort/Filter Model} - and \l{itemviews/customsortfiltermodel}{Custom Sort/Filter Model} - examples illustrate how to use QSortFilterProxyModel to perform - basic sorting and filtering and how to subclass it to implement - custom behavior. + The \l{itemviews/basicsortfiltermodel}{Basic Sort/Filter Model} and + \l{itemviews/customsortfiltermodel}{Custom Sort/Filter Model} examples + illustrate how to use QSortFilterProxyModel to perform basic sorting and + filtering and how to subclass it to implement custom behavior. \section1 Sorting QTableView and QTreeView have a - \l{QTreeView::sortingEnabled}{sortingEnabled} property that - controls whether the user can sort the view by clicking the - view's horizontal header. For example: + \l{QTreeView::sortingEnabled}{sortingEnabled} property that controls + whether the user can sort the view by clicking the view's horizontal + header. For example: \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 3 - When this feature is on (the default is off), clicking on a - header section sorts the items according to that column. By - clicking repeatedly, the user can alternate between ascending and - descending order. + When this feature is on (the default is off), clicking on a header section + sorts the items according to that column. By clicking repeatedly, the user + can alternate between ascending and descending order. \image qsortfilterproxymodel-sorting.png A sorted QTreeView - Behind the scene, the view calls the sort() virtual function on - the model to reorder the data in the model. To make your data - sortable, you can either implement sort() in your model, or you - use a QSortFilterProxyModel to wrap your model -- - QSortFilterProxyModel provides a generic sort() reimplementation - that operates on the sortRole() (Qt::DisplayRole by default) of - the items and that understands several data types, including \c - int, QString, and QDateTime. For hierarchical models, sorting is - applied recursively to all child items. String comparisons are - case sensitive by default; this can be changed by setting the - \l{QSortFilterProxyModel::}{sortCaseSensitivity} property. + Behind the scene, the view calls the sort() virtual function on the model + to reorder the data in the model. To make your data sortable, you can + either implement sort() in your model, or use a QSortFilterProxyModel to + wrap your model -- QSortFilterProxyModel provides a generic sort() + reimplementation that operates on the sortRole() (Qt::DisplayRole by + default) of the items and that understands several data types, including + \c int, QString, and QDateTime. For hierarchical models, sorting is applied + recursively to all child items. String comparisons are case sensitive by + default; this can be changed by setting the \l{QSortFilterProxyModel::} + {sortCaseSensitivity} property. Custom sorting behavior is achieved by subclassing QSortFilterProxyModel and reimplementing lessThan(), which is @@ -1365,43 +1359,42 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsRemoved( \l{itemviews/customsortfiltermodel}{Custom Sort/Filter Model} example.) - An alternative approach to sorting is to disable sorting on the - view and to impose a certain order to the user. This is done by - explicitly calling sort() with the desired column and order as - arguments on the QSortFilterProxyModel (or on the original model - if it implements sort()). For example: + An alternative approach to sorting is to disable sorting on the view and to + impose a certain order to the user. This is done by explicitly calling + sort() with the desired column and order as arguments on the + QSortFilterProxyModel (or on the original model if it implements sort()). + For example: \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 4 - QSortFilterProxyModel can be sorted by column -1, in which case it - returns to the sort order of the underlying source model. + QSortFilterProxyModel can be sorted by column -1, in which case it returns + to the sort order of the underlying source model. \section1 Filtering - In addition to sorting, QSortFilterProxyModel can be used to hide - items that don't match a certain filter. The filter is specified - using a QRegExp object and is applied to the filterRole() - (Qt::DisplayRole by default) of each item, for a given column. - The QRegExp object can be used to match a regular expression, a - wildcard pattern, or a fixed string. For example: + In addition to sorting, QSortFilterProxyModel can be used to hide items + that do not match a certain filter. The filter is specified using a QRegExp + object and is applied to the filterRole() (Qt::DisplayRole by default) of + each item, for a given column. The QRegExp object can be used to match a + regular expression, a wildcard pattern, or a fixed string. For example: \snippet doc/src/snippets/qsortfilterproxymodel-details/main.cpp 5 - For hierarchical models, the filter is applied recursively to all - children. If a parent item doesn't match the filter, none of its - children will be shown. + For hierarchical models, the filter is applied recursively to all children. + If a parent item doesn't match the filter, none of its children will be + shown. - A common use case is to let the user specify the filter regexp, - wildcard pattern, or fixed string in a QLineEdit and to connect - the \l{QLineEdit::textChanged()}{textChanged()} signal to - setFilterRegExp(), setFilterWildcard(), or setFilterFixedString() - to reapply the filter. + A common use case is to let the user specify the filter regexp, wildcard + pattern, or fixed string in a QLineEdit and to connect the + \l{QLineEdit::textChanged()}{textChanged()} signal to setFilterRegExp(), + setFilterWildcard(), or setFilterFixedString() to reapply the filter. Custom filtering behavior can be achieved by reimplementing the filterAcceptsRow() and filterAcceptsColumn() functions. For - example, the following implementation ignores the - \l{QSortFilterProxyModel::filterKeyColumn}{filterKeyColumn} - property and performs filtering on columns 0, 1, and 2: + example (from the \l{itemviews/customsortfiltermodel} + {Custom Sort/Filter Model} example), the following implementation ignores + the \l{QSortFilterProxyModel::filterKeyColumn}{filterKeyColumn} property + and performs filtering on columns 0, 1, and 2: \snippet examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 3 @@ -1411,24 +1404,24 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsRemoved( If you are working with large amounts of filtering and have to invoke invalidateFilter() repeatedly, using reset() may be more efficient, - depending on the implementation of your model. However, note that reset() - returns the proxy model to its original state, losing selection - information, and will cause the proxy model to be repopulated. + depending on the implementation of your model. However, reset() returns the + proxy model to its original state, losing selection information, and will + cause the proxy model to be repopulated. \section1 Subclassing - \bold{Note:} Some general guidelines for subclassing models are - available in the \l{Model Subclassing Reference}. - Since QAbstractProxyModel and its subclasses are derived from - QAbstractItemModel, much of the same advice about subclassing normal - models also applies to proxy models. In addition, it is worth noting - that many of the default implementations of functions in this class - are written so that they call the equivalent functions in the relevant - source model. This simple proxying mechanism may need to be overridden - for source models with more complex behavior; for example, if the - source model provides a custom hasChildren() implementation, you - should also provide one in the proxy model. + QAbstractItemModel, much of the same advice about subclassing normal models + also applies to proxy models. In addition, it is worth noting that many of + the default implementations of functions in this class are written so that + they call the equivalent functions in the relevant source model. This + simple proxying mechanism may need to be overridden for source models with + more complex behavior; for example, if the source model provides a custom + hasChildren() implementation, you should also provide one in the proxy + model. + + \note Some general guidelines for subclassing models are available in the + \l{Model Subclassing Reference}. \sa QAbstractProxyModel, QAbstractItemModel, {Model/View Programming}, {Basic Sort/Filter Model Example}, {Custom Sort/Filter Model Example} @@ -1991,9 +1984,11 @@ Qt::SortOrder QSortFilterProxyModel::sortOrder() const \brief the QRegExp used to filter the contents of the source model Setting this property overwrites the current - \l{QSortFilterProxyModel::filterCaseSensitivity} - {filterCaseSensitivity}. By default, the QRegExp is an empty - string matching all contents. + \l{QSortFilterProxyModel::filterCaseSensitivity}{filterCaseSensitivity}. + By default, the QRegExp is an empty string matching all contents. + + If no QRegExp or an empty string is set, everything in the source model + will be accepted. \sa filterCaseSensitivity, setFilterWildcard(), setFilterFixedString() */ @@ -2316,7 +2311,7 @@ bool QSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex Q_D(const QSortFilterProxyModel); QVariant l = (left.model() ? left.model()->data(left, d->sort_role) : QVariant()); QVariant r = (right.model() ? right.model()->data(right, d->sort_role) : QVariant()); - switch (l.type()) { + switch (l.userType()) { case QVariant::Invalid: return (r.type() == QVariant::Invalid); case QVariant::Int: @@ -2327,6 +2322,8 @@ bool QSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex return l.toLongLong() < r.toLongLong(); case QVariant::ULongLong: return l.toULongLong() < r.toULongLong(); + case QMetaType::Float: + return l.toFloat() < r.toFloat(); case QVariant::Double: return l.toDouble() < r.toDouble(); case QVariant::Char: diff --git a/src/gui/itemviews/qstandarditemmodel.cpp b/src/gui/itemviews/qstandarditemmodel.cpp index f2fc37e..9ae3214 100644 --- a/src/gui/itemviews/qstandarditemmodel.cpp +++ b/src/gui/itemviews/qstandarditemmodel.cpp @@ -1806,7 +1806,7 @@ bool QStandardItem::operator<(const QStandardItem &other) const const int role = model() ? model()->sortRole() : Qt::DisplayRole; const QVariant l = data(role), r = other.data(role); // this code is copied from QSortFilterProxyModel::lessThan() - switch (l.type()) { + switch (l.userType()) { case QVariant::Invalid: return (r.type() == QVariant::Invalid); case QVariant::Int: @@ -1817,6 +1817,8 @@ bool QStandardItem::operator<(const QStandardItem &other) const return l.toLongLong() < r.toLongLong(); case QVariant::ULongLong: return l.toULongLong() < r.toULongLong(); + case QMetaType::Float: + return l.toFloat() < r.toFloat(); case QVariant::Double: return l.toDouble() < r.toDouble(); case QVariant::Char: diff --git a/src/gui/itemviews/qstandarditemmodel_p.h b/src/gui/itemviews/qstandarditemmodel_p.h index 1ee3432..a8b36ed 100644 --- a/src/gui/itemviews/qstandarditemmodel_p.h +++ b/src/gui/itemviews/qstandarditemmodel_p.h @@ -75,6 +75,7 @@ public: parent(0), rows(0), columns(0), + q_ptr(0), lastIndexOf(2) { } virtual ~QStandardItemPrivate(); diff --git a/src/gui/itemviews/qstringlistmodel.cpp b/src/gui/itemviews/qstringlistmodel.cpp index d57de1a..9462dfe 100644 --- a/src/gui/itemviews/qstringlistmodel.cpp +++ b/src/gui/itemviews/qstringlistmodel.cpp @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE \brief The QStringListModel class provides a model that supplies strings to views. \ingroup model-view - \mainclass + QStringListModel is an editable model that can be used for simple cases where you need to display a number of strings in a view diff --git a/src/gui/itemviews/qstyleditemdelegate.cpp b/src/gui/itemviews/qstyleditemdelegate.cpp index 913af89..b5f676a 100644 --- a/src/gui/itemviews/qstyleditemdelegate.cpp +++ b/src/gui/itemviews/qstyleditemdelegate.cpp @@ -112,7 +112,7 @@ public: data items from a model. \ingroup model-view - \mainclass + \since 4.4 When displaying data from models in Qt item views, e.g., a @@ -267,9 +267,10 @@ QStyledItemDelegate::~QStyledItemDelegate() QString QStyledItemDelegate::displayText(const QVariant &value, const QLocale& locale) const { QString text; - switch (value.type()) { + switch (value.userType()) { + case QMetaType::Float: case QVariant::Double: - text = locale.toString(value.toDouble()); + text = locale.toString(value.toReal()); break; case QVariant::Int: case QVariant::LongLong: diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp index 61c2b60..a9db9f5 100644 --- a/src/gui/itemviews/qtableview.cpp +++ b/src/gui/itemviews/qtableview.cpp @@ -508,7 +508,7 @@ void QTableViewPrivate::drawCell(QPainter *painter, const QStyleOptionViewItemV4 \ingroup model-view \ingroup advanced - \mainclass + A QTableView implements a table view that displays items from a model. This class is used to provide standard tables that were diff --git a/src/gui/itemviews/qtablewidget.cpp b/src/gui/itemviews/qtablewidget.cpp index fea81e5..b04aea2 100644 --- a/src/gui/itemviews/qtablewidget.cpp +++ b/src/gui/itemviews/qtablewidget.cpp @@ -1392,9 +1392,7 @@ QVariant QTableWidgetItem::data(int role) const bool QTableWidgetItem::operator<(const QTableWidgetItem &other) const { const QVariant v1 = data(Qt::DisplayRole), v2 = other.data(Qt::DisplayRole); - if (QAbstractItemModelPrivate::canConvertToDouble(v1) && QAbstractItemModelPrivate::canConvertToDouble(v2)) - return v1.toDouble() < v2.toDouble(); - return v1.toString() < v2.toString(); + return QAbstractItemModelPrivate::variantLessThan(v1, v2); } #ifndef QT_NO_DATASTREAM @@ -1488,7 +1486,7 @@ QTableWidgetItem &QTableWidgetItem::operator=(const QTableWidgetItem &other) \brief The QTableWidget class provides an item-based table view with a default model. \ingroup model-view - \mainclass + Table widgets provide standard table display facilities for applications. The items in a QTableWidget are provided by QTableWidgetItem. diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index cbe1d2a..7dad192 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE \ingroup model-view \ingroup advanced - \mainclass + A QTreeView implements a tree representation of items from a model. This class is used to provide standard hierarchical lists that @@ -2797,15 +2797,14 @@ int QTreeView::indexRowSizeHint(const QModelIndex &index) const if (isRightToLeft()) { start = (start == -1 ? count - 1 : start); - end = (end == -1 ? 0 : end); + end = 0; } else { start = (start == -1 ? 0 : start); - end = (end == -1 ? count - 1 : end); + end = count - 1; } - int tmp = start; - start = qMin(start, end); - end = qMax(tmp, end); + if (end < start) + qSwap(end, start); int height = -1; QStyleOptionViewItemV4 option = d->viewOptionsV4(); diff --git a/src/gui/itemviews/qtreeview_p.h b/src/gui/itemviews/qtreeview_p.h index d17016f..1bbba89 100644 --- a/src/gui/itemviews/qtreeview_p.h +++ b/src/gui/itemviews/qtreeview_p.h @@ -82,7 +82,7 @@ public: uniformRowHeights(false), rootDecoration(true), itemsExpandable(true), sortingEnabled(false), expandsOnDoubleClick(true), - allColumnsShowFocus(false), current(0), + allColumnsShowFocus(false), current(0), spanning(false), animationsEnabled(false), columnResizeTimerID(0), autoExpandDelay(-1), hoverBranch(-1), geometryRecursionBlock(false) {} diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp index eaed05f..b636284 100644 --- a/src/gui/itemviews/qtreewidget.cpp +++ b/src/gui/itemviews/qtreewidget.cpp @@ -75,7 +75,7 @@ public: \brief The QTreeModel class manages the items stored in a tree view. \ingroup model-view - \mainclass + */ /*! @@ -1768,6 +1768,7 @@ QVariant QTreeWidgetItem::data(int column, int role) const // special case for check state in tristate if (children.count() && (itemFlags & Qt::ItemIsTristate)) return childrenCheckState(column); + // fallthrough intended default: if (column >= 0 && column < values.size()) { const QVector<QWidgetItemData> &column_values = values.at(column); @@ -1789,9 +1790,7 @@ bool QTreeWidgetItem::operator<(const QTreeWidgetItem &other) const int column = view ? view->sortColumn() : 0; const QVariant v1 = data(column, Qt::DisplayRole); const QVariant v2 = other.data(column, Qt::DisplayRole); - if (QAbstractItemModelPrivate::canConvertToDouble(v1) && QAbstractItemModelPrivate::canConvertToDouble(v2)) - return v1.toDouble() < v2.toDouble(); - return v1.toString() < v2.toString(); + return QAbstractItemModelPrivate::variantLessThan(v1, v2); } #ifndef QT_NO_DATASTREAM @@ -2074,6 +2073,8 @@ QList<QTreeWidgetItem*> QTreeWidgetItem::takeChildren() void QTreeWidgetItemPrivate::sortChildren(int column, Qt::SortOrder order, bool climb) { QTreeModel *model = (q->view ? qobject_cast<QTreeModel*>(q->view->model()) : 0); + if (!model) + return; model->sortItems(&q->children, column, order); if (climb) { QList<QTreeWidgetItem*>::iterator it = q->children.begin(); @@ -2328,7 +2329,7 @@ void QTreeWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, tree model. \ingroup model-view - \mainclass + The QTreeWidget class is a convenience class that provides a standard tree widget with a classic item-based interface similar to that used by diff --git a/src/gui/itemviews/qtreewidgetitemiterator_p.h b/src/gui/itemviews/qtreewidgetitemiterator_p.h index 3ffe823..ee0808c 100644 --- a/src/gui/itemviews/qtreewidgetitemiterator_p.h +++ b/src/gui/itemviews/qtreewidgetitemiterator_p.h @@ -73,7 +73,8 @@ public: } QTreeWidgetItemIteratorPrivate(const QTreeWidgetItemIteratorPrivate& other) - : m_currentIndex(other.m_currentIndex), m_model(other.m_model), m_parentIndex(other.m_parentIndex) + : m_currentIndex(other.m_currentIndex), m_model(other.m_model), + m_parentIndex(other.m_parentIndex), q_ptr(other.q_ptr) { } |