Class WModelIndex
- All Implemented Interfaces:
java.lang.Comparable<WModelIndex>
public class WModelIndex extends java.lang.Object implements java.lang.Comparable<WModelIndex>
Indexes are used to indicate a particular item in a WAbstractItemModel. An index points to the item by
identifying its row and column location within a parent model index. Indexes are immutable.
The null index identifies the parent of top level indexes. Thus, a model that specifies only a list or
table of data (but no hierarchical data) would have as indexes only indexes that specify the null as
parent.
Valid indexes are created by the model, within the protected WAbstractItemModel.createIndex(int, int, Object)
method. In this way, models can define an internal pointer or suitable for identifying items in the model.
- See Also:
WAbstractItemModel
-
Method Summary
Modifier and Type Method Description intcompareTo(WModelIndex i2)ImplementsComparable.compareTo(Object).WModelIndexdecodeFromRawIndex()Decodes a raw index (after a layout change).static java.util.SortedSet<WModelIndex>decodeFromRawIndexes(java.util.SortedSet<WModelIndex> encodedIndexes)Utility method to decode an entire set of raw indexes.voidencodeAsRawIndex()Encodes to raw index (before a layout change).static voidencodeAsRawIndexes(java.util.SortedSet<WModelIndex> indexes)Utility method for converting an entire set of indexes to raw.booleanequals(java.lang.Object other)Indicates whether some other object is "equal to" this one.WModelIndexgetChild(int row, int column)Returns a model index for a child item.intgetColumn()Returns the column.java.lang.ObjectgetData()Returns the data in the model associated at this index.java.lang.ObjectgetData(int role)Returns the data in the model associated at this index.java.util.EnumSet<ItemFlag>getFlags()Returns the item flags for the item at this index.intgetInternalId()java.lang.ObjectgetInternalPointer()Returns the internal pointer.WAbstractItemModelgetModel()Returns the model.WModelIndexgetParent()Returns the parent index.intgetRow()Returns the row.inthashCode()Returns a hash code value for the object.static booleanisAncestor(WModelIndex i1, WModelIndex i2)Returns whether i2 is an ancestor of i1.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
getParent
Returns the parent index.- Returns:
- the parent index, which may be
nullif the index is a top-level index.
-
getRow
public int getRow()Returns the row.- Returns:
- the row.
-
getColumn
public int getColumn()Returns the column.- Returns:
- the column.
-
getInternalPointer
public java.lang.Object getInternalPointer()Returns the internal pointer.The internal pointer is used by a specific model implementation to uniquely identify (in conjunction with
getRow()andgetColumn()) the item to which this index points.Usually the internal pointer therefore identifies the parent for hierarchical models, or is simply
nullfor tabular models.- Returns:
- the internal pointer.
-
getModel
Returns the model.- Returns:
- the model that created this index.
-
getData
public java.lang.Object getData(int role)Returns the data in the model associated at this index. This is a convenience method forWAbstractItemModel.getData(WModelIndex, int).- Parameters:
role- theItemDataRolerole.- Returns:
- the data, or
nullif no data was available for this role.
-
getData
public java.lang.Object getData()Returns the data in the model associated at this index. CallsgetData(ItemDataRole.DisplayRole). -
getChild
Returns a model index for a child item.This is a convenience method for
WAbstractItemModel.getIndex(int, int, WModelIndex). -
equals
public boolean equals(java.lang.Object other)Indicates whether some other object is "equal to" this one.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()Returns a hash code value for the object.- Overrides:
hashCodein classjava.lang.Object
-
compareTo
ImplementsComparable.compareTo(Object).Creates a topological ordering of model indexes.
The topological order follows the order in which the indexes would be displayed in a tree table view, from top to bottom followed by left to right.
- Specified by:
compareToin interfacejava.lang.Comparable<WModelIndex>
-
getFlags
Returns the item flags for the item at this index. This is a convenience method forWAbstractItemModel.getFlags(WModelIndex). -
encodeAsRawIndex
public void encodeAsRawIndex()Encodes to raw index (before a layout change). Use this method to encode an index for which you want to recover an index after the layout change to the same item (which may still be in the model, but at a different location). An index that has been encoded as a raw index cannot be used for anything but #decodeFromRawIndex() at a later point. -
decodeFromRawIndex
Decodes a raw index (after a layout change). A raw index can be decoded, within the context of a model that has been re-layed out. This method returns a new index that points to the same item, ornullif the underlying model did not support encoding to raw indexes, or, if the item to which the index previously pointed, is no longer part of the model. -
encodeAsRawIndexes
Utility method for converting an entire set of indexes to raw.- Parameters:
indexes-- See Also:
encodeAsRawIndex()
-
decodeFromRawIndexes
public static java.util.SortedSet<WModelIndex> decodeFromRawIndexes(java.util.SortedSet<WModelIndex> encodedIndexes)Utility method to decode an entire set of raw indexes.- See Also:
decodeFromRawIndex()
-
isAncestor
Returns whether i2 is an ancestor of i1. -
getInternalId
public int getInternalId()
-