MeVisLab Scripting Reference
MLABListViewControl Class Reference

#include <mlabListViewControl.h>

Inherits MLABSimpleWidgetControl.

Public Types

enum  Alignment
 
enum  EditorFlags
 

Public Slots

Scripting access.


MLABListViewItemitemForId (int id)
 
QList< MLABListViewItem * > topLevelItems () const
 
MLABListViewItemfirstItem () const
 
MLABListViewItemfirstChild () const
 
MLABListViewItemlastItem () const
 
void ensureItemVisible (MLABListViewItem *item, bool positionAtCenter=false)
 
MLABListViewItemselectedItem () const
 
QList< MLABListViewItem * > selectedItems () const
 
void resizeColumnsToContents ()
 
void setSelected (MLABListViewItem *item, bool selected)
 
bool isSelected (MLABListViewItem *item)
 
void setAlternatingRowColors (bool enable)
 
QVariantList selectedItemIds ()
 
QVariantList checkedItemIds ()
 
QList< MLABListViewItem * > checkedItems ()
 
void clearSelection ()
 
MLABListViewItemcurrentItem () const
 
void setCurrentItem (MLABListViewItem *item)
 
void setColumnAlignment (int column, Alignment alignment)
 
void setColumnWidth (int column, int w)
 
void setColumnPixmapFile (int column, const QString &file)
 
void setColumnText (int column, const QString &text)
 
QString columnText (int column)
 
void setSorting (int column, bool ascending)
 
int sortColumn () const
 
bool isSortOrderAscending () const
 
void addColumn (const QString &label)
 
void removeColumn (int idx)
 
int columnCount ()
 
void hideColumn (int column)
 
void showColumn (int column)
 
bool isColumnHidden (int column)
 
void removeColumns ()
 
void clearItems ()
 
void removeItem (MLABListViewItem *item)
 
MLABListViewItemappendItem (const QStringList &texts=QStringList())
 
MLABListViewItemappendItem (MLABListViewItem *parent, const QStringList &texts=QStringList())
 
MLABListViewIteminsertItem ()
 
MLABListViewIteminsertItem (MLABListViewItem *after)
 
MLABListViewIteminsertItem (const QStringList &texts)
 
MLABListViewIteminsertItem (MLABListViewItem *after, const QStringList &texts)
 
MLABListViewIteminsertItem (MLABListViewItem *parent, MLABListViewItem *after)
 
MLABListViewIteminsertItem (MLABListViewItem *parent, MLABListViewItem *after, const QStringList &texts)
 
MLABListViewIteminsertCheckBoxItem ()
 
MLABListViewIteminsertRadioControllerItem ()
 
MLABListViewIteminsertRadioItem (MLABListViewItem *after)
 
MLABListViewIteminsertCheckBoxItem (MLABListViewItem *after)
 
MLABListViewIteminsertRadioControllerItem (MLABListViewItem *after)
 
MLABListViewIteminsertRadioItem (MLABListViewItem *parent, MLABListViewItem *after)
 
MLABListViewIteminsertCheckBoxItem (MLABListViewItem *parent, MLABListViewItem *after)
 
MLABListViewIteminsertRadioControllerItem (MLABListViewItem *parent, MLABListViewItem *after)
 
void setRootIsDecorated (bool flag)
 
void setStringEditorValues (const QStringList &values, int flags=0)
 
void setItemFilter (int column, const QString &pattern, bool caseSensitive=true, bool keepParents=false)
 
void unsetItemFilter ()
 
void setSizeHint (const QSize &size) override
 
void beginInsertItems (int itemCount)
 
void beginInsertItems (MLABListViewItem *parent, int itemCount)
 
void endInsertItems ()
 
- Public Slots inherited from MLABWidgetControl
void adjustSize ()
 
virtual void setEnabled (bool flag)
 
virtual void setVisible (bool flag)
 
virtual bool isVisible ()
 
virtual void setFocus ()
 
virtual bool hasFocus ()
 
virtual void setToolTip (const QString &string)
 
virtual void setWhatsThis (const QString &string)
 
void displayWhatsThis ()
 
void displayWhatsThis (const QString &text)
 
virtual void setTitle (const QString &)
 
QWidget * widget ()
 
QLayout * layout ()
 
virtual QString windowHandle ()
 
virtual bool createScreenshot (const QString &filename, bool grabFromScreen=true, bool scaleToLowRes=false)
 
bool isReloadable () const
 
void reload (MLABTree *tree)
 
QString createGlobalScreenshot ()
 
QString applicationName ()
 
QSize size ()
 
int width ()
 
int height ()
 
int minWidth ()
 
int minHeight ()
 
int maxWidth ()
 
int maxHeight ()
 
virtual void setMinWidth (int s)
 
virtual void setMinHeight (int s)
 
void setMaxWidth (int s)
 
void setMaxHeight (int s)
 
QSize sizeHint ()
 
QSize minSize ()
 
QSize maxSize ()
 
void setMinSize (QSize size)
 
void setMaxSize (QSize size)
 
void updateLayout ()
 
int windowID ()
 
MLABWidgetControlcontrol (const QString &name)
 
float scaleFactor ()
 
MLABModulemodule ()
 
QString getType ()
 
QString getName ()
 
bool acceptDrops ()
 
void setAcceptDrops (bool flag)
 
void raiseWidget ()
 
void setStyleSheetFromString (const QString &styleSheetText)
 
void setStyleSheetFromFile (const QString &styleSheetFileName)
 
MLABTreetree ()
 
void updateMaxSize ()
 
bool expandX ()
 
bool expandY ()
 
MLABTreePtr getDefaultTagValues () const
 
virtual bool hasUncommittedChanges () const
 
virtual void applyUncommittedChanges ()
 
virtual void revertUncommittedChanges ()
 
MLABFieldfield () const
 

Detailed Description

ListView control.

Control for showing a ListView. It can be controlled and filled with content via a field or the values tag. If the items are filled via a given field or the value tag, the item ids are guaranteed to be numbered starting from 0 (without the header column).

ListView can also be controlled manually by using Scripting. It offers creation of any number of columns and creating/removing items on the fly. It also allows to create a tree view in the first column by using insertChildItem().

The interface to access content of individual items is given in MLABListViewItem.

Inserting and Adding Items

If the list view is filtered or sorted, then beginInsertItems() and endInsertItems() should be called before and after adding or inserting items. If they are not called, the filtering and sorting will not be immediately applied to the new items.

For more details see the Qt documentation of QAbstractItemModel::beginInsertRows().

Here is an example:

# Add new top level items:
listView.beginInsertItems(3)
listView.appendItem(["item0"])
listView.appendItem(["item1"])
listView.appendItem(["item2"])
listView.endInsertItems()
# Add new sub items:
parentItem = ...
listView.beginInsertItems(parentItem, 2)
listView.appendItem(parentItem, ["subitem0"])
listView.appendItem(parentItem, ["subitem1"])
listView.endInsertItems()
# Add a new top level item and sub items.
# Note that only the item count for the top level item needs to be passed to beginInsertItems(),
# adding the sub items is recognized by the internal model when looking at the new top level item:
listView.beginInsertItems(1)
parentItem = listView.appendItem(["item0"])
listView.appendItem(parentItem, ["subitem0"])
listView.appendItem(parentItem, ["subitem0"])
listView.endInsertItems()

Member Enumeration Documentation

◆ Alignment

These flags can be used with setColumnAlignment().

◆ EditorFlags

These flags can be used with setStringEditorValues().

Member Function Documentation

◆ addColumn

void MLABListViewControl::addColumn ( const QString & label)
slot

Adds a column.

◆ appendItem [1/2]

MLABListViewItem * MLABListViewControl::appendItem ( const QStringList & texts = QStringList())
slot

Appends a new top level item to the end of the list.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ appendItem [2/2]

MLABListViewItem * MLABListViewControl::appendItem ( MLABListViewItem * parent,
const QStringList & texts = QStringList() )
slot

Appends a new child item to the given parent. It is put to the end of the children list.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ beginInsertItems [1/2]

void MLABListViewControl::beginInsertItems ( int itemCount)
inlineslot

Call this before items have are appended or inserted (see Inserting and Adding Items).

References beginInsertItems().

Referenced by beginInsertItems().

◆ beginInsertItems [2/2]

void MLABListViewControl::beginInsertItems ( MLABListViewItem * parent,
int itemCount )
slot

Call this before items have are appended or inserted to the given parent item (see Inserting and Adding Items).

◆ checkedItemIds

QVariantList MLABListViewControl::checkedItemIds ( )
slot

You should prefer using checkedItems() instead of this method.

Returns the list of checked items ids. The individual items can then be retrieved via itemForId().

◆ checkedItems

QList< MLABListViewItem * > MLABListViewControl::checkedItems ( )
slot

Returns a list with all checked items.

◆ clearItems

void MLABListViewControl::clearItems ( )
slot

Clears all items.

◆ clearSelection

void MLABListViewControl::clearSelection ( )
slot

Clears the current selection.

◆ columnCount

int MLABListViewControl::columnCount ( )
slot

Returns the number of columns currently defined.

◆ columnText

QString MLABListViewControl::columnText ( int column)
slot

Returns the text for given column.

◆ currentItem

MLABListViewItem * MLABListViewControl::currentItem ( ) const
slot

Returns the current item (in single selection mode, current item and selected item are the same).

◆ endInsertItems

void MLABListViewControl::endInsertItems ( )
slot

Call this after items have been appended or inserted (see Inserting and Adding Items).

◆ ensureItemVisible

void MLABListViewControl::ensureItemVisible ( MLABListViewItem * item,
bool positionAtCenter = false )
slot

Makes sure that the item is visible.

If positionAtCenter is true, the item will be centered in the ListView, otherwise it will possibly just be visible.

◆ firstChild

MLABListViewItem * MLABListViewControl::firstChild ( ) const
slot

Returns the first child in the list view (the logical first item, not the one by the sorting order).

◆ firstItem

MLABListViewItem * MLABListViewControl::firstItem ( ) const
slot

Returns the first child in the list view (the logical first item, not the one by the sorting order).

◆ hideColumn

void MLABListViewControl::hideColumn ( int column)
slot

Makes a column invisible, e.g. for sorting purposes.

◆ insertCheckBoxItem [1/3]

MLABListViewItem * MLABListViewControl::insertCheckBoxItem ( )
slot

Inserts a check box item as first list item.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertCheckBoxItem [2/3]

MLABListViewItem * MLABListViewControl::insertCheckBoxItem ( MLABListViewItem * after)
slot

Inserts a check box item after given item (or as first item if after is NULL).

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertCheckBoxItem [3/3]

MLABListViewItem * MLABListViewControl::insertCheckBoxItem ( MLABListViewItem * parent,
MLABListViewItem * after )
slot

Inserts a check box item behind the after item of parent (if after is NULL, item is first in list).

Make sure that after is a child of parent, otherwise an error occurs!

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertItem [1/6]

MLABListViewItem * MLABListViewControl::insertItem ( )
slot

Inserts a new item at the beginning of the list.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertItem [2/6]

MLABListViewItem * MLABListViewControl::insertItem ( const QStringList & texts)
slot

Creates a new item with given texts at the beginning of the list.

If you want to add non-string items, you can call insertItem().setValues(...) instead.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertItem [3/6]

MLABListViewItem * MLABListViewControl::insertItem ( MLABListViewItem * after)
slot

Inserts a new item after the given item (if after is NULL, the new item is the first in the list).

If after has a parent item, the new item is also a child item of that parent.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertItem [4/6]

MLABListViewItem * MLABListViewControl::insertItem ( MLABListViewItem * after,
const QStringList & texts )
slot

Creates a new item with given texts after the given item (if after is NULL, the new item is the first in the list).

If after has a parent item, the new item is also a child item of that parent. If you want to add non-string items, you can call insertItem(after).setValues(...) instead.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertItem [5/6]

MLABListViewItem * MLABListViewControl::insertItem ( MLABListViewItem * parent,
MLABListViewItem * after )
slot

Inserts a new child item after given item (or as first child if after is NULL).

Make sure that after is a child of parent, otherwise an error occurs.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertItem [6/6]

MLABListViewItem * MLABListViewControl::insertItem ( MLABListViewItem * parent,
MLABListViewItem * after,
const QStringList & texts )
slot

Inserts a new child item after given item (or as first child if after is NULL), with given texts.

Make sure that after is a child of parent, otherwise an error occurs!

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertRadioControllerItem [1/3]

MLABListViewItem * MLABListViewControl::insertRadioControllerItem ( )
slot

Inserts a radio controller as first list item.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertRadioControllerItem [2/3]

MLABListViewItem * MLABListViewControl::insertRadioControllerItem ( MLABListViewItem * after)
slot

Inserts a radio controller item after given item (or as first item if after is NULL).

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertRadioControllerItem [3/3]

MLABListViewItem * MLABListViewControl::insertRadioControllerItem ( MLABListViewItem * parent,
MLABListViewItem * after )
slot

Inserts a radio controller item behind the after item of parent (if after is NULL, item is first in list).

Make sure that after is a child of parent, otherwise an error occurs!

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertRadioItem [1/2]

MLABListViewItem * MLABListViewControl::insertRadioItem ( MLABListViewItem * after)
slot

Inserts a check box item after given item.

Must be put into a radio controller to work.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ insertRadioItem [2/2]

MLABListViewItem * MLABListViewControl::insertRadioItem ( MLABListViewItem * parent,
MLABListViewItem * after )
slot

Inserts a radio item behind the after item of parent (if after is NULL, item is first in list).

Make sure that after is a child of parent, otherwise an error occurs.

If filtering or sorting is enabled, then beginInsertItems() and endInsertItems() should be called (see Inserting and Adding Items).

◆ isColumnHidden

bool MLABListViewControl::isColumnHidden ( int column)
slot

Returns whether a column is hidden.

◆ isSelected

bool MLABListViewControl::isSelected ( MLABListViewItem * item)
slot

Returns whether the item is selected.

◆ isSortOrderAscending

bool MLABListViewControl::isSortOrderAscending ( ) const
slot

Returns whether the current sort order is ascending, undefined if sortColumn is -1.

◆ itemForId

MLABListViewItem * MLABListViewControl::itemForId ( int id)
slot

Returns the item for given integer id (id can be get from an item with the id() method).

◆ lastItem

MLABListViewItem * MLABListViewControl::lastItem ( ) const
slot

Returns the last child in the list view (expensive, because it needs to search the whole list!).

◆ removeColumn

void MLABListViewControl::removeColumn ( int idx)
slot

Removes a column.

◆ removeColumns

void MLABListViewControl::removeColumns ( )
slot

Clears all columns.

◆ removeItem

void MLABListViewControl::removeItem ( MLABListViewItem * item)
slot

Removes the given item (being a normal item or child item) and all its children if any.

◆ resizeColumnsToContents

void MLABListViewControl::resizeColumnsToContents ( )
slot

Resizes all columns to their contents.

◆ selectedItem

MLABListViewItem * MLABListViewControl::selectedItem ( ) const
slot

Returns the selected item (in single selection mode this is identical with currentItem(), otherwise always NULL).

◆ selectedItemIds

QVariantList MLABListViewControl::selectedItemIds ( )
slot

You should prefer using selectedItems() instead of this method.

Returns the list of selected items ids (especially useful for multiple selection). The individual items can then be retrieved via itemForId().

Example:

ids = list.selectedItemIds()
for id in ids:
item = list.itemForId(id)

◆ selectedItems

QList< MLABListViewItem * > MLABListViewControl::selectedItems ( ) const
slot

Returns a list of the selected items.

◆ setAlternatingRowColors

void MLABListViewControl::setAlternatingRowColors ( bool enable)
inlineslot

Enables/disables display of alternating row colors.

The alternative row color needs to be set in the style (the color's name in CSS is 'alternateBase').

◆ setColumnAlignment

void MLABListViewControl::setColumnAlignment ( int column,
Alignment alignment )
slot

Sets the alignment of the given column, possible values are AlignLeft, AlignRight or AlignHCenter (defined on the control itself).

◆ setColumnPixmapFile

void MLABListViewControl::setColumnPixmapFile ( int column,
const QString & file )
slot

Sets the column pixmap for this file.

◆ setColumnText

void MLABListViewControl::setColumnText ( int column,
const QString & text )
slot

Sets the text for given column.

◆ setColumnWidth

void MLABListViewControl::setColumnWidth ( int column,
int w )
slot

Sets a fixed column width for given column.

-1 means always resize to content, -2 means resize to content now, but allow interactive resizing (default)

◆ setCurrentItem

void MLABListViewControl::setCurrentItem ( MLABListViewItem * item)
slot

Sets the current item.

◆ setItemFilter

void MLABListViewControl::setItemFilter ( int column,
const QString & pattern,
bool caseSensitive = true,
bool keepParents = false )
slot

Sets a filter for a special column (0..n) or all columns (-1): Only show items with a string value that matches the regular expression given by pattern.

The regular expression syntax is the default pattern syntax of Qt5: http://doc.qt.io/qt-5/qregexp.html. Operations like selecting items or making items visible/invisible will have no effect on items that are filtered away. The original item hierarchy that is accessed with parent(), firstChild(), nextSibling() and childCount() is not affected by filtering. Each call to setItemFilter will replace the previous filter. If keepParents is set, all parents of items that would make it through the filter also get through the filter, i.e. they are visible. But this may be an expensive recursive operation, especially for deeply nested trees, so handle with care.

◆ setRootIsDecorated

void MLABListViewControl::setRootIsDecorated ( bool flag)
slot

Sets whether root is decorated (for tree views).

◆ setSelected

void MLABListViewControl::setSelected ( MLABListViewItem * item,
bool selected )
slot

Selects an item.

◆ setSizeHint

void MLABListViewControl::setSizeHint ( const QSize & size)
overrideslot

Sets the size hint.

◆ setSorting

void MLABListViewControl::setSorting ( int column,
bool ascending )
slot

Sets the sorting column to use, -1 means no sorting.

◆ setStringEditorValues

void MLABListViewControl::setStringEditorValues ( const QStringList & values,
int flags = 0 )
slot

Sets combo box values to use when editing string values - if the value list is empty, the normal line edit is used for editing.

This is only relevant for string values, not e.g. for numerical values which have their own editor. The flags parameter can be a combination (bit-ored) of the values EditorEditable and EditorCaseSensitive, which are defined on this control: EditorEditable defines whether the user can enter his/her own values (default is not editable), EditorCaseSensitive makes the automatic string completion case sensitive (default is case insensitive).

◆ showColumn

void MLABListViewControl::showColumn ( int column)
slot

Shows column again.

◆ sortColumn

int MLABListViewControl::sortColumn ( ) const
slot

Returns the current sort column, -1 if not sorted by column.

◆ topLevelItems

QList< MLABListViewItem * > MLABListViewControl::topLevelItems ( ) const
slot

Returns a list of the top level items of the view, in logical order.

◆ unsetItemFilter

void MLABListViewControl::unsetItemFilter ( )
slot

Unsets a filter previously set with setItemFilter.