Qt 4.8
Classes | Public Functions | Static Public Functions | Public Variables | List of all members
QAbstractItemModelPrivate Class Reference

#include <qabstractitemmodel_p.h>

Inheritance diagram for QAbstractItemModelPrivate:
QObjectPrivate QObjectData QAbstractProxyModelPrivate QDirModelPrivate QFileSystemModelPrivate QProxyModelPrivate QScriptBreakpointsModelPrivate QScriptDebuggerLocalsModelPrivate QScriptDebuggerScriptsModelPrivate QScriptDebuggerStackModelPrivate QSqlQueryModelPrivate QStandardItemModelPrivate QTreeModelPrivate

Classes

struct  Change
 
struct  Persistent
 

Public Functions

bool allowMove (const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation)
 Returns whether a move operation is valid. More...
 
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 
QModelIndex createIndex (int row, int column, void *data=0) const
 
QModelIndex createIndex (int row, int column, int id) const
 
bool indexValid (const QModelIndex &index) const
 
void invalidatePersistentIndex (const QModelIndex &index)
 
void invalidatePersistentIndexes ()
 
void itemsAboutToBeMoved (const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation)
 
void itemsMoved (const QModelIndex &srcParent, int srcFirst, int srcLast, const QModelIndex &destinationParent, int destinationChild, Qt::Orientation orientation)
 
void movePersistentIndexes (QVector< QPersistentModelIndexData *> indexes, int change, const QModelIndex &parent, Qt::Orientation orientation)
 Moves persistent indexes indexes by amount change. More...
 
 QAbstractItemModelPrivate ()
 
void removePersistentIndexData (QPersistentModelIndexData *data)
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static const QHash< int, QByteArray > & defaultRoleNames ()
 
static QAbstractItemModelstaticEmptyModel ()
 
static bool variantLessThan (const QVariant &v1, const QVariant &v2)
 This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort. More...
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

QStack< Changechanges
 
struct QAbstractItemModelPrivate::Persistent persistent
 
QHash< int, QByteArrayroleNames
 
Qt::DropActions supportedDragActions
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Detailed Description

Definition at line 76 of file qabstractitemmodel_p.h.

Constructors and Destructors

◆ QAbstractItemModelPrivate()

QAbstractItemModelPrivate::QAbstractItemModelPrivate ( )
inline

Definition at line 81 of file qabstractitemmodel_p.h.

QObjectPrivate(int version=QObjectPrivateVersion)
Definition: qobject.cpp:133
QHash< int, QByteArray > roleNames
static const QHash< int, QByteArray > & defaultRoleNames()

Functions

◆ allowMove()

bool QAbstractItemModelPrivate::allowMove ( const QModelIndex srcParent,
int  start,
int  end,
const QModelIndex destinationParent,
int  destinationStart,
Qt::Orientation  orientation 
)

Returns whether a move operation is valid.

A move operation is not allowed if it moves a continuous range of rows to a destination within itself, or if it attempts to move a row to one of its own descendants.

Warning
This function is not part of the public interface.

Definition at line 2683 of file qabstractitemmodel.cpp.

2684 {
2685  // Don't move the range within itself.
2686  if (destinationParent == srcParent)
2687  return !(destinationStart >= start && destinationStart <= end + 1);
2688 
2689  QModelIndex destinationAncestor = destinationParent;
2690  int pos = (Qt::Vertical == orientation) ? destinationAncestor.row() : destinationAncestor.column();
2691  forever {
2692  if (destinationAncestor == srcParent) {
2693  if (pos >= start && pos <= end)
2694  return false;
2695  break;
2696  }
2697 
2698  if (!destinationAncestor.isValid())
2699  break;
2700 
2701  pos = (Qt::Vertical == orientation) ? destinationAncestor.row() : destinationAncestor.column();
2702  destinationAncestor = destinationAncestor.parent();
2703  }
2704 
2705  return true;
2706 }
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
int row() const
Returns the row this model index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
static const KeyPair *const end
int column() const
Returns the column this model index refers to.
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ columnsAboutToBeInserted()

void QAbstractItemModelPrivate::columnsAboutToBeInserted ( const QModelIndex parent,
int  first,
int  last 
)

Definition at line 809 of file qabstractitemmodel.cpp.

811 {
813  Q_UNUSED(last);
814  QVector<QPersistentModelIndexData *> persistent_moved;
815  if (first < q->columnCount(parent)) {
817  it != persistent.indexes.constEnd(); ++it) {
819  const QModelIndex &index = data->index;
820  if (index.column() >= first && index.isValid() && index.parent() == parent)
821  persistent_moved.append(data);
822  }
823  }
824  persistent.moved.push(persistent_moved);
825 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
QHash< QModelIndex, QPersistentModelIndexData * > indexes
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
#define Q_Q(Class)
Definition: qglobal.h:2483
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static const char * data(const QByteArray &arr)
QStack< QVector< QPersistentModelIndexData * > > moved
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QAbstractItemModel class provides the abstract interface for item model classes.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
struct QAbstractItemModelPrivate::Persistent persistent
The QModelIndex class is used to locate data in a data model.
quint16 index
QObject * parent
Definition: qobject.h:92
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
int column() const
Returns the column this model index refers to.

◆ columnsAboutToBeRemoved()

void QAbstractItemModelPrivate::columnsAboutToBeRemoved ( const QModelIndex parent,
int  first,
int  last 
)

Definition at line 846 of file qabstractitemmodel.cpp.

848 {
849  QVector<QPersistentModelIndexData *> persistent_moved;
850  QVector<QPersistentModelIndexData *> persistent_invalidated;
851  // find the persistent indexes that are affected by the change, either by being in the removed subtree
852  // or by being on the same level and to the right of the removed columns
854  it != persistent.indexes.constEnd(); ++it) {
856  bool level_changed = false;
857  QModelIndex current = data->index;
858  while (current.isValid()) {
859  QModelIndex current_parent = current.parent();
860  if (current_parent == parent) { // on the same level as the change
861  if (!level_changed && current.column() > last) // right of the removed columns
862  persistent_moved.append(data);
863  else if (current.column() <= last && current.column() >= first) // in the removed subtree
864  persistent_invalidated.append(data);
865  break;
866  }
867  current = current_parent;
868  level_changed = true;
869  }
870  }
871 
872  persistent.moved.push(persistent_moved);
873  persistent.invalidated.push(persistent_invalidated);
874 
875 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
QStack< QVector< QPersistentModelIndexData * > > invalidated
QHash< QModelIndex, QPersistentModelIndexData * > indexes
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static const char * data(const QByteArray &arr)
QStack< QVector< QPersistentModelIndexData * > > moved
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
struct QAbstractItemModelPrivate::Persistent persistent
The QModelIndex class is used to locate data in a data model.
int column() const
Returns the column this model index refers to.

◆ columnsInserted()

void QAbstractItemModelPrivate::columnsInserted ( const QModelIndex parent,
int  first,
int  last 
)

Definition at line 827 of file qabstractitemmodel.cpp.

829 {
831  int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested
833  it != persistent_moved.constEnd(); ++it) {
835  QModelIndex old = data->index;
837  data->index = q_func()->index(old.row(), old.column() + count, parent);
838  if (data->index.isValid()) {
839  persistent.insertMultiAtEnd(data->index, data);
840  } else {
841  qWarning() << "QAbstractItemModel::endInsertColumns: Invalid index (" << old.row() << ',' << old.column() + count << ") in model" << q_func();
842  }
843  }
844 }
#define it(className, varName)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QHash< QModelIndex, QPersistentModelIndexData * > indexes
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
void insertMultiAtEnd(const QModelIndex &key, QPersistentModelIndexData *data)
QHash::insertMulti insert the value before the old value.
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
int row() const
Returns the row this model index refers to.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
QStack< QVector< QPersistentModelIndexData * > > moved
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
struct QAbstractItemModelPrivate::Persistent persistent
The QModelIndex class is used to locate data in a data model.
QObject * parent
Definition: qobject.h:92
const T * const_iterator
The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack...
Definition: qvector.h:245
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
int column() const
Returns the column this model index refers to.

◆ columnsRemoved()

void QAbstractItemModelPrivate::columnsRemoved ( const QModelIndex parent,
int  first,
int  last 
)

Definition at line 877 of file qabstractitemmodel.cpp.

879 {
881  int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested
883  it != persistent_moved.constEnd(); ++it) {
885  QModelIndex old = data->index;
887  data->index = q_func()->index(old.row(), old.column() - count, parent);
888  if (data->index.isValid()) {
889  persistent.insertMultiAtEnd(data->index, data);
890  } else {
891  qWarning() << "QAbstractItemModel::endRemoveColumns: Invalid index (" << old.row() << ',' << old.column() - count << ") in model" << q_func();
892  }
893  }
896  it != persistent_invalidated.constEnd(); ++it) {
897  QPersistentModelIndexData *data = *it;
899  data->index = QModelIndex();
900  data->model = 0;
901  }
902 }
#define it(className, varName)
QStack< QVector< QPersistentModelIndexData * > > invalidated
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QHash< QModelIndex, QPersistentModelIndexData * > indexes
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
void insertMultiAtEnd(const QModelIndex &key, QPersistentModelIndexData *data)
QHash::insertMulti insert the value before the old value.
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
const QAbstractItemModel * model
int row() const
Returns the row this model index refers to.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
QStack< QVector< QPersistentModelIndexData * > > moved
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
struct QAbstractItemModelPrivate::Persistent persistent
The QModelIndex class is used to locate data in a data model.
QObject * parent
Definition: qobject.h:92
const T * const_iterator
The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack...
Definition: qvector.h:245
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
int column() const
Returns the column this model index refers to.

◆ createIndex() [1/2]

QModelIndex QAbstractItemModelPrivate::createIndex ( int  row,
int  column,
void *  data = 0 
) const
inline

Definition at line 99 of file qabstractitemmodel_p.h.

99  {
100  return q_func()->createIndex(row, column, data);
101  }
static const char * data(const QByteArray &arr)

◆ createIndex() [2/2]

QModelIndex QAbstractItemModelPrivate::createIndex ( int  row,
int  column,
int  id 
) const
inline

Definition at line 103 of file qabstractitemmodel_p.h.

103  {
104  return q_func()->createIndex(row, column, id);
105  }

◆ defaultRoleNames()

const QHash< int, QByteArray > & QAbstractItemModelPrivate::defaultRoleNames ( )
static

Definition at line 523 of file qabstractitemmodel.cpp.

524 {
525  return *qDefaultRoleNames();
526 }

◆ indexValid()

bool QAbstractItemModelPrivate::indexValid ( const QModelIndex index) const
inline

Definition at line 107 of file qabstractitemmodel_p.h.

107  {
108  return (index.row() >= 0) && (index.column() >= 0) && (index.model() == q_func());
109  }
int row() const
Returns the row this model index refers to.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
int column() const
Returns the column this model index refers to.

◆ invalidatePersistentIndex()

void QAbstractItemModelPrivate::invalidatePersistentIndex ( const QModelIndex index)
inline
Warning
This function is not part of the public interface. clean the QPersistentModelIndex relative to the index if there is one. To be used before an index is invalided

Definition at line 124 of file qabstractitemmodel_p.h.

124  {
126  if(it != persistent.indexes.end()) {
129  data->index = QModelIndex();
130  data->model = 0;
131  }
132  }
#define it(className, varName)
QHash< QModelIndex, QPersistentModelIndexData * > indexes
const QAbstractItemModel * model
static const char * data(const QByteArray &arr)
struct QAbstractItemModelPrivate::Persistent persistent
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
The QModelIndex class is used to locate data in a data model.
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827

◆ invalidatePersistentIndexes()

void QAbstractItemModelPrivate::invalidatePersistentIndexes ( )
inline

Definition at line 111 of file qabstractitemmodel_p.h.

111  {
113  data->index = QModelIndex();
114  data->model = 0;
115  }
117  }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
QHash< QModelIndex, QPersistentModelIndexData * > indexes
const QAbstractItemModel * model
static const char * data(const QByteArray &arr)
struct QAbstractItemModelPrivate::Persistent persistent
The QModelIndex class is used to locate data in a data model.

◆ itemsAboutToBeMoved()

void QAbstractItemModelPrivate::itemsAboutToBeMoved ( const QModelIndex srcParent,
int  srcFirst,
int  srcLast,
const QModelIndex destinationParent,
int  destinationChild,
Qt::Orientation  orientation 
)

Definition at line 638 of file qabstractitemmodel.cpp.

639 {
640  QVector<QPersistentModelIndexData *> persistent_moved_explicitly;
641  QVector<QPersistentModelIndexData *> persistent_moved_in_source;
642  QVector<QPersistentModelIndexData *> persistent_moved_in_destination;
643 
647 
648  const bool sameParent = (srcParent == destinationParent);
649  const bool movingUp = (srcFirst > destinationChild);
650 
651  for ( it = begin; it != end; ++it) {
653  const QModelIndex &index = data->index;
654  const QModelIndex &parent = index.parent();
655  const bool isSourceIndex = (parent == srcParent);
656  const bool isDestinationIndex = (parent == destinationParent);
657 
658  int childPosition;
659  if (orientation == Qt::Vertical)
660  childPosition = index.row();
661  else
662  childPosition = index.column();
663 
664  if (!index.isValid() || !(isSourceIndex || isDestinationIndex ) )
665  continue;
666 
667  if (!sameParent && isDestinationIndex) {
668  if (childPosition >= destinationChild)
669  persistent_moved_in_destination.append(data);
670  continue;
671  }
672 
673  if (sameParent && movingUp && childPosition < destinationChild)
674  continue;
675 
676  if (sameParent && !movingUp && childPosition < srcFirst )
677  continue;
678 
679  if (!sameParent && childPosition < srcFirst)
680  continue;
681 
682  if (sameParent && (childPosition > srcLast) && (childPosition >= destinationChild ))
683  continue;
684 
685  if ((childPosition <= srcLast) && (childPosition >= srcFirst)) {
686  persistent_moved_explicitly.append(data);
687  } else {
688  persistent_moved_in_source.append(data);
689  }
690  }
691  persistent.moved.push(persistent_moved_explicitly);
692  persistent.moved.push(persistent_moved_in_source);
693  persistent.moved.push(persistent_moved_in_destination);
694 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
QHash< QModelIndex, QPersistentModelIndexData * > indexes
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
int row() const
Returns the row this model index refers to.
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static const char * data(const QByteArray &arr)
QStack< QVector< QPersistentModelIndexData * > > moved
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
struct QAbstractItemModelPrivate::Persistent persistent
The QModelIndex class is used to locate data in a data model.
quint16 index
QObject * parent
Definition: qobject.h:92
static const KeyPair *const end
int column() const
Returns the column this model index refers to.

◆ itemsMoved()

void QAbstractItemModelPrivate::itemsMoved ( const QModelIndex srcParent,
int  srcFirst,
int  srcLast,
const QModelIndex destinationParent,
int  destinationChild,
Qt::Orientation  orientation 
)

Definition at line 734 of file qabstractitemmodel.cpp.

735 {
736  QVector<QPersistentModelIndexData *> moved_in_destination = persistent.moved.pop();
739 
740  const bool sameParent = (sourceParent == destinationParent);
741  const bool movingUp = (sourceFirst > destinationChild);
742 
743  const int explicit_change = (!sameParent || movingUp) ? destinationChild - sourceFirst : destinationChild - sourceLast - 1 ;
744  const int source_change = (!sameParent || !movingUp) ? -1*(sourceLast - sourceFirst + 1) : sourceLast - sourceFirst + 1 ;
745  const int destination_change = sourceLast - sourceFirst + 1;
746 
747  movePersistentIndexes(moved_explicitly, explicit_change, destinationParent, orientation);
748  movePersistentIndexes(moved_in_source, source_change, sourceParent, orientation);
749  movePersistentIndexes(moved_in_destination, destination_change, destinationParent, orientation);
750 }
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QStack< QVector< QPersistentModelIndexData * > > moved
struct QAbstractItemModelPrivate::Persistent persistent
void movePersistentIndexes(QVector< QPersistentModelIndexData *> indexes, int change, const QModelIndex &parent, Qt::Orientation orientation)
Moves persistent indexes indexes by amount change.

◆ movePersistentIndexes()

void QAbstractItemModelPrivate::movePersistentIndexes ( QVector< QPersistentModelIndexData *>  indexes,
int  change,
const QModelIndex parent,
Qt::Orientation  orientation 
)

Moves persistent indexes indexes by amount change.

Warning
This function is not part of the public interface.

The change will be either a change in row value or a change in column value depending on the value of orientation. The indexes may also be moved to a different parent if parent differs from the existing parent for the index.

Definition at line 706 of file qabstractitemmodel.cpp.

707 {
711 
712  for (it = begin; it != end; ++it)
713  {
715 
716  int row = data->index.row();
717  int column = data->index.column();
718 
719  if (Qt::Vertical == orientation)
720  row += change;
721  else
722  column += change;
723 
725  data->index = q_func()->index(row, column, parent);
726  if (data->index.isValid()) {
727  persistent.insertMultiAtEnd(data->index, data);
728  } else {
729  qWarning() << "QAbstractItemModel::endMoveRows: Invalid index (" << row << "," << column << ") in model" << q_func();
730  }
731  }
732 }
#define it(className, varName)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QHash< QModelIndex, QPersistentModelIndexData * > indexes
void insertMultiAtEnd(const QModelIndex &key, QPersistentModelIndexData *data)
QHash::insertMulti insert the value before the old value.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
int row() const
Returns the row this model index refers to.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
struct QAbstractItemModelPrivate::Persistent persistent
const T * const_iterator
The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack...
Definition: qvector.h:245
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
static const KeyPair *const end
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
int column() const
Returns the column this model index refers to.

◆ removePersistentIndexData()

void QAbstractItemModelPrivate::removePersistentIndexData ( QPersistentModelIndexData data)

Definition at line 575 of file qabstractitemmodel.cpp.

Referenced by QPersistentModelIndexData::destroy().

576 {
577  if (data->index.isValid()) {
578  int removed = persistent.indexes.remove(data->index);
579  Q_ASSERT_X(removed == 1, "QPersistentModelIndex::~QPersistentModelIndex",
580  "persistent model indexes corrupted"); //maybe the index was somewhat invalid?
581  // This assert may happen if the model use changePersistentIndex in a way that could result on two
582  // QPersistentModelIndex pointing to the same index.
583  Q_UNUSED(removed);
584  }
585  // make sure our optimization still works
586  for (int i = persistent.moved.count() - 1; i >= 0; --i) {
587  int idx = persistent.moved[i].indexOf(data);
588  if (idx >= 0)
589  persistent.moved[i].remove(idx);
590  }
591  // update the references to invalidated persistent indexes
592  for (int i = persistent.invalidated.count() - 1; i >= 0; --i) {
593  int idx = persistent.invalidated[i].indexOf(data);
594  if (idx >= 0)
595  persistent.invalidated[i].remove(idx);
596  }
597 
598 }
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
void remove(int i)
Removes the element at index position i.
Definition: qvector.h:374
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QStack< QVector< QPersistentModelIndexData * > > invalidated
QHash< QModelIndex, QPersistentModelIndexData * > indexes
QStack< QVector< QPersistentModelIndexData * > > moved
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the vector, searching forward from ind...
Definition: qvector.h:698
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
struct QAbstractItemModelPrivate::Persistent persistent
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ rowsAboutToBeInserted()

void QAbstractItemModelPrivate::rowsAboutToBeInserted ( const QModelIndex parent,
int  first,
int  last 
)

Definition at line 600 of file qabstractitemmodel.cpp.

602 {
604  Q_UNUSED(last);
605  QVector<QPersistentModelIndexData *> persistent_moved;
606  if (first < q->rowCount(parent)) {
608  it != persistent.indexes.constEnd(); ++it) {
610  const QModelIndex &index = data->index;
611  if (index.row() >= first && index.isValid() && index.parent() == parent) {
612  persistent_moved.append(data);
613  }
614  }
615  }
616  persistent.moved.push(persistent_moved);
617 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
QHash< QModelIndex, QPersistentModelIndexData * > indexes
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
#define Q_Q(Class)
Definition: qglobal.h:2483
int row() const
Returns the row this model index refers to.
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static const char * data(const QByteArray &arr)
QStack< QVector< QPersistentModelIndexData * > > moved
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QAbstractItemModel class provides the abstract interface for item model classes.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
struct QAbstractItemModelPrivate::Persistent persistent
The QModelIndex class is used to locate data in a data model.
quint16 index
QObject * parent
Definition: qobject.h:92
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ rowsAboutToBeRemoved()

void QAbstractItemModelPrivate::rowsAboutToBeRemoved ( const QModelIndex parent,
int  first,
int  last 
)

Definition at line 752 of file qabstractitemmodel.cpp.

754 {
755  QVector<QPersistentModelIndexData *> persistent_moved;
756  QVector<QPersistentModelIndexData *> persistent_invalidated;
757  // find the persistent indexes that are affected by the change, either by being in the removed subtree
758  // or by being on the same level and below the removed rows
760  it != persistent.indexes.constEnd(); ++it) {
762  bool level_changed = false;
763  QModelIndex current = data->index;
764  while (current.isValid()) {
765  QModelIndex current_parent = current.parent();
766  if (current_parent == parent) { // on the same level as the change
767  if (!level_changed && current.row() > last) // below the removed rows
768  persistent_moved.append(data);
769  else if (current.row() <= last && current.row() >= first) // in the removed subtree
770  persistent_invalidated.append(data);
771  break;
772  }
773  current = current_parent;
774  level_changed = true;
775  }
776  }
777 
778  persistent.moved.push(persistent_moved);
779  persistent.invalidated.push(persistent_invalidated);
780 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
QStack< QVector< QPersistentModelIndexData * > > invalidated
QHash< QModelIndex, QPersistentModelIndexData * > indexes
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
int row() const
Returns the row this model index refers to.
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static const char * data(const QByteArray &arr)
QStack< QVector< QPersistentModelIndexData * > > moved
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
struct QAbstractItemModelPrivate::Persistent persistent
The QModelIndex class is used to locate data in a data model.

◆ rowsInserted()

void QAbstractItemModelPrivate::rowsInserted ( const QModelIndex parent,
int  first,
int  last 
)

Definition at line 619 of file qabstractitemmodel.cpp.

621 {
623  int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested
625  it != persistent_moved.constEnd(); ++it) {
627  QModelIndex old = data->index;
629  data->index = q_func()->index(old.row() + count, old.column(), parent);
630  if (data->index.isValid()) {
631  persistent.insertMultiAtEnd(data->index, data);
632  } else {
633  qWarning() << "QAbstractItemModel::endInsertRows: Invalid index (" << old.row() + count << ',' << old.column() << ") in model" << q_func();
634  }
635  }
636 }
#define it(className, varName)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QHash< QModelIndex, QPersistentModelIndexData * > indexes
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
void insertMultiAtEnd(const QModelIndex &key, QPersistentModelIndexData *data)
QHash::insertMulti insert the value before the old value.
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
int row() const
Returns the row this model index refers to.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
QStack< QVector< QPersistentModelIndexData * > > moved
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
struct QAbstractItemModelPrivate::Persistent persistent
The QModelIndex class is used to locate data in a data model.
QObject * parent
Definition: qobject.h:92
const T * const_iterator
The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack...
Definition: qvector.h:245
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
int column() const
Returns the column this model index refers to.

◆ rowsRemoved()

void QAbstractItemModelPrivate::rowsRemoved ( const QModelIndex parent,
int  first,
int  last 
)

Definition at line 782 of file qabstractitemmodel.cpp.

784 {
786  int count = (last - first) + 1; // it is important to only use the delta, because the change could be nested
788  it != persistent_moved.constEnd(); ++it) {
790  QModelIndex old = data->index;
792  data->index = q_func()->index(old.row() - count, old.column(), parent);
793  if (data->index.isValid()) {
794  persistent.insertMultiAtEnd(data->index, data);
795  } else {
796  qWarning() << "QAbstractItemModel::endRemoveRows: Invalid index (" << old.row() - count << ',' << old.column() << ") in model" << q_func();
797  }
798  }
801  it != persistent_invalidated.constEnd(); ++it) {
802  QPersistentModelIndexData *data = *it;
804  data->index = QModelIndex();
805  data->model = 0;
806  }
807 }
#define it(className, varName)
QStack< QVector< QPersistentModelIndexData * > > invalidated
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
QHash< QModelIndex, QPersistentModelIndexData * > indexes
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
void insertMultiAtEnd(const QModelIndex &key, QPersistentModelIndexData *data)
QHash::insertMulti insert the value before the old value.
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
const QAbstractItemModel * model
int row() const
Returns the row this model index refers to.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
QStack< QVector< QPersistentModelIndexData * > > moved
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
struct QAbstractItemModelPrivate::Persistent persistent
The QModelIndex class is used to locate data in a data model.
QObject * parent
Definition: qobject.h:92
const T * const_iterator
The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack...
Definition: qvector.h:245
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
int column() const
Returns the column this model index refers to.

◆ staticEmptyModel()

QAbstractItemModel * QAbstractItemModelPrivate::staticEmptyModel ( )
static

◆ variantLessThan()

bool QAbstractItemModelPrivate::variantLessThan ( const QVariant v1,
const QVariant v2 
)
static

This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort.

Warning
This function is not part of the public interface. return true if value contains a numerical type

Definition at line 562 of file qabstractitemmodel.cpp.

Referenced by QListWidgetItem::operator<(), QTableWidgetItem::operator<(), and QTreeWidgetItem::operator<().

563 {
564  switch(qMax(typeOfVariant(v1), typeOfVariant(v2)))
565  {
566  case 0: //integer type
567  return v1.toLongLong() < v2.toLongLong();
568  case 1: //floating point
569  return v1.toReal() < v2.toReal();
570  default:
571  return v1.toString().localeAwareCompare(v2.toString()) < 0;
572  }
573 }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
static uint typeOfVariant(const QVariant &value)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
int localeAwareCompare(const QString &s) const
Definition: qstring.cpp:5197
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740

Properties

◆ changes

QStack<Change> QAbstractItemModelPrivate::changes

Definition at line 158 of file qabstractitemmodel_p.h.

◆ persistent

struct QAbstractItemModelPrivate::Persistent QAbstractItemModelPrivate::persistent

◆ roleNames

QHash<int,QByteArray> QAbstractItemModelPrivate::roleNames

Definition at line 170 of file qabstractitemmodel_p.h.

◆ supportedDragActions

Qt::DropActions QAbstractItemModelPrivate::supportedDragActions

Definition at line 168 of file qabstractitemmodel_p.h.


The documentation for this class was generated from the following files: