Remove code for qt < 4.7.2 :)

Initialize variables
wilder
Laurent Montel 7 years ago
parent eb6cfe3591
commit 24b7791301
  1. 5
      src/kcheckableproxymodel.cpp
  2. 5
      src/kconcatenaterowsproxymodel.cpp
  3. 41
      src/klinkitemselectionmodel.cpp
  4. 34
      src/kmodelindexproxymapper.cpp

@ -27,13 +27,12 @@ class KCheckableProxyModelPrivate
KCheckableProxyModel *q_ptr; KCheckableProxyModel *q_ptr;
KCheckableProxyModelPrivate(KCheckableProxyModel *checkableModel) KCheckableProxyModelPrivate(KCheckableProxyModel *checkableModel)
: q_ptr(checkableModel), : q_ptr(checkableModel)
m_itemSelectionModel(nullptr)
{ {
} }
QItemSelectionModel *m_itemSelectionModel; QItemSelectionModel *m_itemSelectionModel = nullptr;
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);

@ -24,8 +24,7 @@ class KConcatenateRowsProxyModelPrivate
{ {
public: public:
KConcatenateRowsProxyModelPrivate(KConcatenateRowsProxyModel* model) KConcatenateRowsProxyModelPrivate(KConcatenateRowsProxyModel* model)
: q(model), : q(model)
m_rowCount(0)
{} {}
int computeRowsPrior(const QAbstractItemModel *sourceModel) const; int computeRowsPrior(const QAbstractItemModel *sourceModel) const;
@ -47,7 +46,7 @@ public:
KConcatenateRowsProxyModel *q; KConcatenateRowsProxyModel *q;
QList<QAbstractItemModel *> m_models; QList<QAbstractItemModel *> m_models;
int m_rowCount; // have to maintain it here since we can't compute during model destruction int m_rowCount = 0; // have to maintain it here since we can't compute during model destruction
// for layoutAboutToBeChanged/layoutChanged // for layoutAboutToBeChanged/layoutChanged
QVector<QPersistentModelIndex> layoutChangePersistentIndexes; QVector<QPersistentModelIndex> layoutChangePersistentIndexes;

@ -31,10 +31,7 @@ class KLinkItemSelectionModelPrivate
{ {
public: public:
KLinkItemSelectionModelPrivate(KLinkItemSelectionModel *proxySelectionModel) KLinkItemSelectionModelPrivate(KLinkItemSelectionModel *proxySelectionModel)
: q_ptr(proxySelectionModel), : q_ptr(proxySelectionModel)
m_linkedItemSelectionModel(nullptr),
m_ignoreCurrentChanged(false),
m_indexMapper(nullptr)
{ {
QObject::connect(q_ptr, &QItemSelectionModel::currentChanged, q_ptr, QObject::connect(q_ptr, &QItemSelectionModel::currentChanged, q_ptr,
[this](const QModelIndex& idx) { slotCurrentChanged(idx); } ); [this](const QModelIndex& idx) { slotCurrentChanged(idx); } );
@ -79,9 +76,9 @@ public:
void sourceCurrentChanged(const QModelIndex &current); void sourceCurrentChanged(const QModelIndex &current);
void slotCurrentChanged(const QModelIndex &current); void slotCurrentChanged(const QModelIndex &current);
QItemSelectionModel *m_linkedItemSelectionModel; QItemSelectionModel *m_linkedItemSelectionModel = nullptr;
bool m_ignoreCurrentChanged; bool m_ignoreCurrentChanged = false;
KModelIndexProxyMapper * m_indexMapper; KModelIndexProxyMapper * m_indexMapper = nullptr;
}; };
KLinkItemSelectionModel::KLinkItemSelectionModel(QAbstractItemModel *model, QItemSelectionModel *proxySelector, QObject *parent) KLinkItemSelectionModel::KLinkItemSelectionModel(QAbstractItemModel *model, QItemSelectionModel *proxySelector, QObject *parent)
@ -162,37 +159,12 @@ void KLinkItemSelectionModel::select(const QModelIndex &index, QItemSelectionMod
} }
} }
// QAbstractProxyModel::mapSelectionFromSource creates invalid ranges to we filter
// those out manually in a loop. Hopefully fixed in Qt 4.7.2, so we ifdef it out.
// http://qt.gitorious.org/qt/qt/merge_requests/2474
// http://qt.gitorious.org/qt/qt/merge_requests/831
#if QT_VERSION < 0x040702
#define RANGE_FIX_HACK
#endif
#ifdef RANGE_FIX_HACK
static QItemSelection klink_removeInvalidRanges(const QItemSelection &selection)
{
QItemSelection result;
Q_FOREACH (const QItemSelectionRange &range, selection) {
if (!range.isValid()) {
continue;
}
result << range;
}
return result;
}
#endif
void KLinkItemSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) void KLinkItemSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
{ {
Q_D(KLinkItemSelectionModel); Q_D(KLinkItemSelectionModel);
d->m_ignoreCurrentChanged = true; d->m_ignoreCurrentChanged = true;
#ifdef RANGE_FIX_HACK
QItemSelection _selection = klink_removeInvalidRanges(selection);
#else
QItemSelection _selection = selection; QItemSelection _selection = selection;
#endif
QItemSelectionModel::select(_selection, command); QItemSelectionModel::select(_selection, command);
Q_ASSERT(d->assertSelectionValid(_selection)); Q_ASSERT(d->assertSelectionValid(_selection));
QItemSelection mappedSelection = d->m_indexMapper->mapSelectionLeftToRight(_selection); QItemSelection mappedSelection = d->m_indexMapper->mapSelectionLeftToRight(_selection);
@ -213,13 +185,8 @@ void KLinkItemSelectionModelPrivate::slotCurrentChanged(const QModelIndex &curre
void KLinkItemSelectionModelPrivate::sourceSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) void KLinkItemSelectionModelPrivate::sourceSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{ {
Q_Q(KLinkItemSelectionModel); Q_Q(KLinkItemSelectionModel);
#ifdef RANGE_FIX_HACK
QItemSelection _selected = klink_removeInvalidRanges(selected);
QItemSelection _deselected = klink_removeInvalidRanges(deselected);
#else
QItemSelection _selected = selected; QItemSelection _selected = selected;
QItemSelection _deselected = deselected; QItemSelection _deselected = deselected;
#endif
Q_ASSERT(assertSelectionValid(_selected)); Q_ASSERT(assertSelectionValid(_selected));
Q_ASSERT(assertSelectionValid(_deselected)); Q_ASSERT(assertSelectionValid(_deselected));
const QItemSelection mappedDeselection = m_indexMapper->mapSelectionRightToLeft(_deselected); const QItemSelection mappedDeselection = m_indexMapper->mapSelectionRightToLeft(_deselected);

@ -197,28 +197,6 @@ QModelIndex KModelIndexProxyMapper::mapRightToLeft(const QModelIndex &index) con
return selection.indexes().first(); return selection.indexes().first();
} }
// QAbstractProxyModel::mapSelectionFromSource creates invalid ranges to we filter
// those out manually in a loop. Hopefully fixed in Qt 4.7.2, so we ifdef it out.
// http://qt.gitorious.org/qt/qt/merge_requests/2474
// http://qt.gitorious.org/qt/qt/merge_requests/831
#if QT_VERSION < 0x040702
#define RANGE_FIX_HACK
#endif
#ifdef RANGE_FIX_HACK
static QItemSelection removeInvalidRanges(const QItemSelection &selection)
{
QItemSelection result;
Q_FOREACH (const QItemSelectionRange &range, selection) {
if (!range.isValid()) {
continue;
}
result << range;
}
return result;
}
#endif
QItemSelection KModelIndexProxyMapper::mapSelectionLeftToRight(const QItemSelection &selection) const QItemSelection KModelIndexProxyMapper::mapSelectionLeftToRight(const QItemSelection &selection) const
{ {
Q_D(const KModelIndexProxyMapper); Q_D(const KModelIndexProxyMapper);
@ -246,9 +224,6 @@ QItemSelection KModelIndexProxyMapper::mapSelectionLeftToRight(const QItemSelect
seekSelection = proxy->mapSelectionToSource(seekSelection); seekSelection = proxy->mapSelectionToSource(seekSelection);
Q_ASSERT(seekSelection.isEmpty() || seekSelection.first().model() == proxy->sourceModel()); Q_ASSERT(seekSelection.isEmpty() || seekSelection.first().model() == proxy->sourceModel());
#ifdef RANGE_FIX_HACK
seekSelection = removeInvalidRanges(seekSelection);
#endif
Q_ASSERT(d->assertSelectionValid(seekSelection)); Q_ASSERT(d->assertSelectionValid(seekSelection));
} }
@ -263,9 +238,6 @@ QItemSelection KModelIndexProxyMapper::mapSelectionLeftToRight(const QItemSelect
seekSelection = proxy->mapSelectionFromSource(seekSelection); seekSelection = proxy->mapSelectionFromSource(seekSelection);
Q_ASSERT(seekSelection.isEmpty() || seekSelection.first().model() == proxy); Q_ASSERT(seekSelection.isEmpty() || seekSelection.first().model() == proxy);
#ifdef RANGE_FIX_HACK
seekSelection = removeInvalidRanges(seekSelection);
#endif
Q_ASSERT(d->assertSelectionValid(seekSelection)); Q_ASSERT(d->assertSelectionValid(seekSelection));
} }
@ -298,9 +270,6 @@ QItemSelection KModelIndexProxyMapper::mapSelectionRightToLeft(const QItemSelect
} }
seekSelection = proxy->mapSelectionToSource(seekSelection); seekSelection = proxy->mapSelectionToSource(seekSelection);
#ifdef RANGE_FIX_HACK
seekSelection = removeInvalidRanges(seekSelection);
#endif
Q_ASSERT(d->assertSelectionValid(seekSelection)); Q_ASSERT(d->assertSelectionValid(seekSelection));
} }
@ -314,9 +283,6 @@ QItemSelection KModelIndexProxyMapper::mapSelectionRightToLeft(const QItemSelect
} }
seekSelection = proxy->mapSelectionFromSource(seekSelection); seekSelection = proxy->mapSelectionFromSource(seekSelection);
#ifdef RANGE_FIX_HACK
seekSelection = removeInvalidRanges(seekSelection);
#endif
Q_ASSERT(d->assertSelectionValid(seekSelection)); Q_ASSERT(d->assertSelectionValid(seekSelection));
} }

Loading…
Cancel
Save