Qt Jambi Home

com.trolltech.qt.gui
Class QItemSelection

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.gui.QItemSelection
All Implemented Interfaces:
QtJambiInterface

public class QItemSelection
extends QtJambiObject

The QItemSelection class manages information about selected items in a model.

A QItemSelection describes the items in a model that have been selected by the user. A QItemSelection is basically a list of selection ranges, see QItemSelectionRange. It provides functions for creating and manipulating selections, and selecting a range of items from a model.

The QItemSelection class is one of the Model/View Classes and is part of Qt's model/view framework.

An item selection can be constructed and initialized to contain a range of items from an existing model. The following example constructs a selection that contains a range of items from the given model, beginning at the topLeft, and ending at the bottomRight.

    QItemSelection *selection = new QItemSelection(topLeft, bottomRight);

An empty item selection can be constructed, and later populated as required. So, if the model is going to be unavailable when we construct the item selection, we can rewrite the above code in the following way:

    QItemSelection *selection = new QItemSelection();
    ...
    selection->select(topLeft, bottomRight);

QItemSelection saves memory, and avoids unnecessary work, by working with selection ranges rather than recording the model item index for each item in the selection. Generally, an instance of this class will contain a list of non-overlapping selection ranges.

Use merge to merge one item selection into another without making overlapping ranges. Use split() to split one selection range into smaller ranges based on a another selection range.

See Also:
Model/View Programming, QItemSelectionModel

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Constructor Summary
QItemSelection()
          Constructs an empty selection.
QItemSelection(QModelIndex topLeft, QModelIndex bottomRight)
          Constructs an item selection that extends from the top-left model item, specified by the topLeft index, to the bottom-right item, specified by bottomRight.
 
Method Summary
 void append(QItemSelectionRange t)
          Inserts t at the end of the list.
 QItemSelectionRange at(int i)
          Returns the item at index position i in the list.
 void clear()
          Removes all items from the list.
 boolean contains(QModelIndex index)
          Returns true if the selection contains the given index; otherwise returns false.
 int count()
          Returns the number of items in the list.
 int count(QItemSelectionRange t)
          Returns the number of occurrences of t in the list.
 boolean empty()
          This function is provided for STL compatibility.
 boolean equals(java.lang.Object other)
          
static QItemSelection fromNativePointer(QNativePointer nativePointer)
          This function returns the QItemSelection instance pointed to by nativePointer
static java.util.List<QItemSelectionRange> fromVector(java.util.List<QItemSelectionRange> vector)
          Returns a QList object with the data contained in vector.
 java.util.List<QModelIndex> indexes()
          Returns a list of model indexes that correspond to the selected items.
 int indexOf(QItemSelectionRange t, int from)
          Returns the index position of the first occurrence of t in the list, searching forward from index position from.
 boolean isEmpty()
          Returns true if the list contains no items; otherwise returns false.
 int lastIndexOf(QItemSelectionRange t, int from)
          Returns the index position of the last occurrence of t in the list, searching backward from index position from.
 void merge(QItemSelection other, QItemSelectionModel.SelectionFlag... command)
          Merges the other selection with this QItemSelection using the command given.
 void merge(QItemSelection other, QItemSelectionModel.SelectionFlags command)
          Merges the other selection with this QItemSelection using the command given.
 java.util.List<QItemSelectionRange> mid(int pos, int length)
          Returns a list whose elements are copied from this list, starting at position pos.
 void move(int from, int to)
          Moves the item at index position from to index position to.
static QNativePointer nativePointerArray(QItemSelection[] array)
          This function returns a QNativePointer that is pointing to the specified QItemSelection array.
 void pop_back()
          This function is provided for STL compatibility.
 void pop_front()
          This function is provided for STL compatibility.
 void prepend(QItemSelectionRange t)
          Inserts t at the beginning of the list.
 void push_back(QItemSelectionRange t)
          This function is provided for STL compatibility.
 void push_front(QItemSelectionRange t)
          This function is provided for STL compatibility.
 int removeAll(QItemSelectionRange t)
          Removes all occurrences of t in the list and returns the number of entries removed.
 void removeAt(int i)
          Removes the item at index position i.
 void removeFirst()
          Removes the first item in the list.
 void removeLast()
          Removes the last item in the list.
 void replace(int i, QItemSelectionRange t)
          Replaces the item at index position i with t.
 void select(QModelIndex topLeft, QModelIndex bottomRight)
          Adds the items in the range that extends from the top-left model item, specified by the topLeft index, to the bottom-right item, specified by bottomRight to the list.
 void setSharable(boolean sharable)
          
 int size()
          Returns the number of items in the list.
static void split(QItemSelectionRange range, QItemSelectionRange other, QItemSelection result)
          Splits the selection range using the selection other range.
 void swap(int i, int j)
          Exchange the item at index position i with the item at index position j.
 QItemSelectionRange takeAt(int i)
          Removes the item at index position i and returns it.
 QItemSelectionRange takeFirst()
          Removes the first item in the list and returns it.
 QItemSelectionRange takeLast()
          Removes the last item in the list and returns it.
 java.util.List<QItemSelectionRange> toVector()
          Returns a QVector object with the data contained in this QList.
 QItemSelectionRange value(int i)
          Returns the value at index position i in the list.
 QItemSelectionRange value(int i, QItemSelectionRange defaultValue)
          If the index i is out of bounds, the function returns defaultValue.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QItemSelection

public QItemSelection()

Constructs an empty selection.


QItemSelection

public QItemSelection(QModelIndex topLeft,
                      QModelIndex bottomRight)

Constructs an item selection that extends from the top-left model item, specified by the topLeft index, to the bottom-right item, specified by bottomRight.

Method Detail

append

public final void append(QItemSelectionRange t)

Inserts t at the end of the list.

Example:

    QList<QString> list;
    list.append("one");
    list.append("two");
    list.append("three");
    // list: ["one", "two", "three"]

This is the same as list.insert(size, t).

This operation is typically very fast (constant time), because QList preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.

See Also:
operator<<, prepend, insert

at

public final QItemSelectionRange at(int i)

Returns the item at index position i in the list.

i must be a valid index position in the list (i.e., 0 <= i < size).

This function is very fast (constant time).

See Also:
value, operator[]

clear

public final void clear()

Removes all items from the list.

See Also:
removeAll

contains

public final boolean contains(QModelIndex index)

Returns true if the selection contains the given index; otherwise returns false.


count

public final int count(QItemSelectionRange t)

Returns the number of occurrences of t in the list.

This function requires the value type to have an implementation of operator==().

See Also:
contains, indexOf

count

public final int count()

Returns the number of items in the list. This is effectively the same as size.


empty

public final boolean empty()

This function is provided for STL compatibility. It is equivalent to isEmpty and returns true if the list is empty.


indexOf

public final int indexOf(QItemSelectionRange t,
                         int from)

Returns the index position of the first occurrence of t in the list, searching forward from index position from. Returns -1 if no item matched.

Example:

    QList<QString> list;
    list << "A" << "B" << "C" << "B" << "A";
    list.indexOf("B");          // returns 1
    list.indexOf("B", 1);       // returns 1
    list.indexOf("B", 2);       // returns 3
    list.indexOf("X");          // returns -1

This function requires the value type to have an implementation of operator==().

See Also:
lastIndexOf, contains

indexes

public final java.util.List<QModelIndex> indexes()

Returns a list of model indexes that correspond to the selected items.


isEmpty

public final boolean isEmpty()

Returns true if the list contains no items; otherwise returns false.

See Also:
size

lastIndexOf

public final int lastIndexOf(QItemSelectionRange t,
                             int from)

Returns the index position of the last occurrence of t in the list, searching backward from index position from. If from is -1 (the default), the search starts at the last item. Returns -1 if no item matched.

Example:

    QList<QString> list;
    list << "A" << "B" << "C" << "B" << "A";
    list.lastIndexOf("B");      // returns 3
    list.lastIndexOf("B", 3);   // returns 3
    list.lastIndexOf("B", 2);   // returns 1
    list.lastIndexOf("X");      // returns -1

This function requires the value type to have an implementation of operator==().

See Also:
indexOf

merge

public final void merge(QItemSelection other,
                        QItemSelectionModel.SelectionFlag... command)

Merges the other selection with this QItemSelection using the command given. This method guarantees that no ranges are overlapping.

Note that only QItemSelectionModel::Select, QItemSelectionModel::Deselect, and QItemSelectionModel::Toggle are supported.

See Also:
split

merge

public final void merge(QItemSelection other,
                        QItemSelectionModel.SelectionFlags command)

Merges the other selection with this QItemSelection using the command given. This method guarantees that no ranges are overlapping.

Note that only QItemSelectionModel::Select, QItemSelectionModel::Deselect, and QItemSelectionModel::Toggle are supported.

See Also:
split

mid

public final java.util.List<QItemSelectionRange> mid(int pos,
                                                     int length)

Returns a list whose elements are copied from this list, starting at position pos. If length is -1 (the default), all elements after pos are copied; otherwise length elements (or all remaining elements if there are less than length elements) are copied.


move

public final void move(int from,
                       int to)

Moves the item at index position from to index position to.

Example:

    QList<QString> list;
    list << "A" << "B" << "C" << "D" << "E" << "F";
    list.move(1, 4);
    // list: ["A", "C", "D", "E", "B", "F"]

This is the same as insert(to, takeAt(from)).

See Also:
swap, insert, takeAt

pop_back

public final void pop_back()

This function is provided for STL compatibility. It is equivalent to removeLast.


pop_front

public final void pop_front()

This function is provided for STL compatibility. It is equivalent to removeFirst.


prepend

public final void prepend(QItemSelectionRange t)

Inserts t at the beginning of the list.

Example:

    QList<QString> list;
    list.prepend("one");
    list.prepend("two");
    list.prepend("three");
    // list: ["three", "two", "one"]

This is the same as list.insert(0, t).

This operation is usually very fast (constant time), because QList preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.

See Also:
append, insert

push_back

public final void push_back(QItemSelectionRange t)

This function is provided for STL compatibility. It is equivalent to append(t).


push_front

public final void push_front(QItemSelectionRange t)

This function is provided for STL compatibility. It is equivalent to prepend(t).


removeAll

public final int removeAll(QItemSelectionRange t)

Removes all occurrences of t in the list and returns the number of entries removed.

Example:

    QList<QString> list;
    list << "sun" << "cloud" << "sun" << "rain";
    list.removeAll("sun");
    // list: ["cloud", "rain"]

This function requires the value type to have an implementation of operator==().

See Also:
removeAt, takeAt, replace

removeAt

public final void removeAt(int i)

Removes the item at index position i.

i must be a valid index position in the list (i.e., 0 <= i < size).

See Also:
takeAt, removeFirst, removeLast

removeFirst

public final void removeFirst()

Removes the first item in the list.

This is the same as removeAt(0).

See Also:
removeAt, takeFirst

removeLast

public final void removeLast()

Removes the last item in the list.

This is the same as removeAt(size - 1).

See Also:
removeAt, takeLast

replace

public final void replace(int i,
                          QItemSelectionRange t)

Replaces the item at index position i with t.

i must be a valid index position in the list (i.e., 0 <= i < size).

See Also:
operator[], removeAt

select

public final void select(QModelIndex topLeft,
                         QModelIndex bottomRight)

Adds the items in the range that extends from the top-left model item, specified by the topLeft index, to the bottom-right item, specified by bottomRight to the list.


setSharable

public final void setSharable(boolean sharable)


size

public final int size()

Returns the number of items in the list.

See Also:
isEmpty, count

swap

public final void swap(int i,
                       int j)

Exchange the item at index position i with the item at index position j.

Example:

    QList<QString> list;
    list << "A" << "B" << "C" << "D" << "E" << "F";
    list.swap(1, 4);
    // list: ["A", "E", "C", "D", "B", "F"]

See Also:
move

takeAt

public final QItemSelectionRange takeAt(int i)

Removes the item at index position i and returns it.

i must be a valid index position in the list (i.e., 0 <= i < size).

If you don't use the return value, removeAt is more efficient.

See Also:
removeAt, takeFirst, takeLast

takeFirst

public final QItemSelectionRange takeFirst()

Removes the first item in the list and returns it.

This is the same as takeAt(0).

This operation is very fast (constant time), because QList preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.

If you don't use the return value, removeFirst is more efficient.

See Also:
takeLast, takeAt, removeFirst

takeLast

public final QItemSelectionRange takeLast()

Removes the last item in the list and returns it.

This is the same as takeAt(size - 1).

This operation is very fast (constant time), because QList preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.

If you don't use the return value, removeLast is more efficient.

See Also:
takeFirst, takeAt, removeLast

toVector

public final java.util.List<QItemSelectionRange> toVector()

Returns a QVector object with the data contained in this QList.

Example:

    QStringList list;
    list << "Sven" << "Kim" << "Ola";

    QVector<QString> vect = list.toVector();
    // vect: ["Sven", "Kim", "Ola"]

See Also:
toSet, fromVector, QVector::fromList

value

public final QItemSelectionRange value(int i,
                                       QItemSelectionRange defaultValue)

If the index i is out of bounds, the function returns defaultValue.


value

public final QItemSelectionRange value(int i)

Returns the value at index position i in the list.

If the index i is out of bounds, the function returns a default-constructed value. If you are certain that the index is going to be within bounds, you can use at instead, which is slightly faster.

See Also:
at, operator[]

fromVector

public static java.util.List<QItemSelectionRange> fromVector(java.util.List<QItemSelectionRange> vector)

Returns a QList object with the data contained in vector.

Example:

    QVector<double> vect;
    vect << "red" << "green" << "blue" << "black";

    QList<double> list = QVector<T>::fromVector(vect);
    // list: ["red", "green", "blue", "black"]

See Also:
fromSet, toVector, QVector::toList

fromNativePointer

public static QItemSelection fromNativePointer(QNativePointer nativePointer)
This function returns the QItemSelection instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

nativePointerArray

public static QNativePointer nativePointerArray(QItemSelection[] array)
This function returns a QNativePointer that is pointing to the specified QItemSelection array.

Parameters:
array - the array that the returned pointer will point to.
Returns:
a QNativePointer that is pointing to the specified array.

equals

public boolean equals(java.lang.Object other)

Overrides:
equals in class java.lang.Object

split

public static void split(QItemSelectionRange range,
                         QItemSelectionRange other,
                         QItemSelection result)
Splits the selection range using the selection other range. Removes all items in other from range and puts the result in result.


Qt Jambi Home