Qt 4.8
Public Functions | Properties | List of all members
QStringListModel Class Reference

The QStringListModel class provides a model that supplies strings to views. More...

#include <qstringlistmodel.h>

Inheritance diagram for QStringListModel:
QAbstractListModel QAbstractItemModel QObject

Public Functions

QVariant data (const QModelIndex &index, int role) const
 Returns data for the specified role, from the item with the given index. More...
 
Qt::ItemFlags flags (const QModelIndex &index) const
 Returns the flags for the item with the given index. More...
 
bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
 Inserts count rows into the model, beginning at the given row. More...
 
 QStringListModel (QObject *parent=0)
 Constructs a string list model with the given parent. More...
 
 QStringListModel (const QStringList &strings, QObject *parent=0)
 Constructs a string list model containing the specified strings with the given parent. More...
 
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 Removes count rows from the model, beginning at the given row. More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 Returns the number of rows in the model. More...
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Sets the data for the specified role in the item with the given index in the model, to the provided value. More...
 
void setStringList (const QStringList &strings)
 Sets the model's internal string list to strings. More...
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 Reimplemented Function More...
 
QStringList stringList () const
 Returns the string list used by the model to store data. More...
 
Qt::DropActions supportedDropActions () const
 Reimplemented Function More...
 
- Public Functions inherited from QAbstractListModel
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Reimplemented Function More...
 
QModelIndex index (int row, int column=0, const QModelIndex &parent=QModelIndex()) const
 Returns the index of the data in row and column with parent. More...
 
 QAbstractListModel (QObject *parent=0)
 Constructs an abstract list model with the given parent. More...
 
 ~QAbstractListModel ()
 Destroys the abstract list model. More...
 
- Public Functions inherited from QAbstractItemModel
virtual QModelIndex buddy (const QModelIndex &index) const
 Returns a model index for the buddy of the item represented by index. More...
 
virtual bool canFetchMore (const QModelIndex &parent) const
 Returns true if there is more data available for parent; otherwise returns false. More...
 
virtual void fetchMore (const QModelIndex &parent)
 Fetches any available data for the items with the parent specified by the parent index. More...
 
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Returns true if the model returns a valid QModelIndex for row and column with parent, otherwise returns false. More...
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 Returns the data for the given role and section in the header with the specified orientation. More...
 
bool insertColumn (int column, const QModelIndex &parent=QModelIndex())
 Inserts a single column before the given column in the child items of the parent specified. More...
 
virtual bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count new columns into the model before the given column. More...
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex())
 Inserts a single row before the given row in the child items of the parent specified. More...
 
virtual QMap< int, QVariantitemData (const QModelIndex &index) const
 Returns a map with values for all predefined roles in the model for the item at the given index. More...
 
virtual QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 Returns a list of indexes for the items in the column of the start index where data stored under the given role matches the specified value. More...
 
virtual QMimeDatamimeData (const QModelIndexList &indexes) const
 Returns an object that contains serialized items of data corresponding to the list of indexes specified. More...
 
virtual QStringList mimeTypes () const
 Returns a list of MIME types that can be used to describe a list of model indexes. More...
 
 QAbstractItemModel (QObject *parent=0)
 Constructs an abstract item model with the given parent. More...
 
bool removeColumn (int column, const QModelIndex &parent=QModelIndex())
 Removes the given column from the child items of the parent specified. More...
 
virtual bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count columns starting with the given column under parent parent from the model. More...
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex())
 Removes the given row from the child items of the parent specified. More...
 
const QHash< int, QByteArray > & roleNames () const
 Returns the model's role names. More...
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 Sets the data for the given role and section in the header with the specified orientation to the value supplied. More...
 
virtual bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole. More...
 
void setSupportedDragActions (Qt::DropActions)
 Sets the supported drag actions for the items in the model. More...
 
QModelIndex sibling (int row, int column, const QModelIndex &idx) const
 Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. More...
 
virtual QSize span (const QModelIndex &index) const
 Returns the row and column span of the item represented by index. More...
 
Qt::DropActions supportedDragActions () const
 Returns the actions supported by the data in this model. More...
 
virtual ~QAbstractItemModel ()
 Destroys the abstract item model. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Properties

QStringList lst
 

Additional Inherited Members

- Public Slots inherited from QAbstractItemModel
virtual void revert ()
 Lets the model know that it should discard cached information. More...
 
virtual bool submit ()
 Lets the model know that it should submit cached information to permanent storage. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QAbstractItemModel
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are inserted into the model. More...
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 This signal is emitted just before columns are moved within the model. More...
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are removed from the model. More...
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been inserted into the model. More...
 
void columnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
 This signal is emitted after columns have been moved within the model. More...
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been removed from the model. More...
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 This signal is emitted whenever the data in an existing item changes. More...
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 This signal is emitted whenever a header is changed. More...
 
void layoutAboutToBeChanged ()
 This signal is emitted just before the layout of a model is changed. More...
 
void layoutChanged ()
 This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. More...
 
void modelAboutToBeReset ()
 This signal is emitted when reset() is called, before the model's internal state (e. More...
 
void modelReset ()
 This signal is emitted when reset() is called, after the model's internal state (e. More...
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are inserted into the model. More...
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 This signal is emitted just before rows are moved within the model. More...
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are removed from the model. More...
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been inserted into the model. More...
 
void rowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 This signal is emitted after rows have been moved within the model. More...
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been removed from the model. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QAbstractItemModel
void resetInternalData ()
 This slot is called just after the internal data of a model is cleared while it is being reset. More...
 
- Protected Functions inherited from QAbstractListModel
 QAbstractListModel (QAbstractItemModelPrivate &dd, QObject *parent)
 Constructs an abstract list model with dd and the given parent. More...
 
- Protected Functions inherited from QAbstractItemModel
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 Begins a column insertion operation. More...
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 Begins a row insertion operation. More...
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 Begins a column move operation. More...
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 Begins a row move operation. More...
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 Begins a column removal operation. More...
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 Begins a row removal operation. More...
 
void beginResetModel ()
 Begins a model reset operation. More...
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index. More...
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list to the given to model index list. More...
 
QModelIndex createIndex (int row, int column, void *data=0) const
 Creates a model index for the given row and column with the internal pointer ptr. More...
 
QModelIndex createIndex (int row, int column, int id) const
 Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. More...
 
QModelIndex createIndex (int row, int column, quint32 id) const
 Creates a model index for the given row and column with the internal identifier, id. More...
 
bool decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream)
 
void encodeData (const QModelIndexList &indexes, QDataStream &stream) const
 
void endInsertColumns ()
 Ends a column insertion operation. More...
 
void endInsertRows ()
 Ends a row insertion operation. More...
 
void endMoveColumns ()
 Ends a column move operation. More...
 
void endMoveRows ()
 Ends a row move operation. More...
 
void endRemoveColumns ()
 Ends a column removal operation. More...
 
void endRemoveRows ()
 Ends a row removal operation. More...
 
void endResetModel ()
 Completes a model reset operation. More...
 
QModelIndexList persistentIndexList () const
 Returns the list of indexes stored as persistent indexes in the model. More...
 
 QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=0)
 
void reset ()
 Resets the model to its original state in any attached views. More...
 
void setRoleNames (const QHash< int, QByteArray > &roleNames)
 Sets the model's role names to roleNames. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QStringListModel class provides a model that supplies strings to views.

QStringListModel is an editable model that can be used for simple cases where you need to display a number of strings in a view widget, such as a QListView or a QComboBox.

The model provides all the standard functions of an editable model, representing the data in the string list as a model with one column and a number of rows equal to the number of items in the list.

Model indexes corresponding to items are obtained with the index() function, and item flags are obtained with flags(). Item data is read with the data() function and written with setData(). The number of rows (and number of items in the string list) can be found with the rowCount() function.

The model can be constructed with an existing string list, or strings can be set later with the setStringList() convenience function. Strings can also be inserted in the usual way with the insertRows() function, and removed with removeRows(). The contents of the string list can be retrieved with the stringList() convenience function.

An example usage of QStringListModel:

list << "a" << "b" << "c";
model->setStringList(list);
See also
QAbstractListModel, QAbstractItemModel, {Model Classes}

Definition at line 56 of file qstringlistmodel.h.

Constructors and Destructors

◆ QStringListModel() [1/2]

QStringListModel::QStringListModel ( QObject parent = 0)
explicit

Constructs a string list model with the given parent.

Definition at line 96 of file qstringlistmodel.cpp.

97  : QAbstractListModel(parent)
98 {
99 }
QAbstractListModel(QObject *parent=0)
Constructs an abstract list model with the given parent.

◆ QStringListModel() [2/2]

QStringListModel::QStringListModel ( const QStringList strings,
QObject parent = 0 
)

Constructs a string list model containing the specified strings with the given parent.

Definition at line 106 of file qstringlistmodel.cpp.

107  : QAbstractListModel(parent), lst(strings)
108 {
109 }
QAbstractListModel(QObject *parent=0)
Constructs an abstract list model with the given parent.

Functions

◆ data()

QVariant QStringListModel::data ( const QModelIndex index,
int  role 
) const
virtual

Returns data for the specified role, from the item with the given index.

If the view requests an invalid index, an invalid variant is returned.

See also
setData()

Implements QAbstractItemModel.

Definition at line 139 of file qstringlistmodel.cpp.

140 {
141  if (index.row() < 0 || index.row() >= lst.size())
142  return QVariant();
143 
144  if (role == Qt::DisplayRole || role == Qt::EditRole)
145  return lst.at(index.row());
146 
147  return QVariant();
148 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int row() const
Returns the row this model index refers to.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ flags()

Qt::ItemFlags QStringListModel::flags ( const QModelIndex index) const
virtual

Returns the flags for the item with the given index.

Valid items are enabled, selectable, editable, drag enabled and drop enabled.

See also
QAbstractItemModel::flags()

Reimplemented from QAbstractItemModel.

Definition at line 158 of file qstringlistmodel.cpp.

159 {
160  if (!index.isValid())
162 
164 }
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ insertRows()

bool QStringListModel::insertRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

Inserts count rows into the model, beginning at the given row.

The parent index of the rows is optional and is only used for consistency with QAbstractItemModel. By default, a null index is specified, indicating that the rows are inserted in the top level of the model.

See also
QAbstractItemModel::insertRows()

Reimplemented from QAbstractItemModel.

Definition at line 197 of file qstringlistmodel.cpp.

198 {
199  if (count < 1 || row < 0 || row > rowCount(parent))
200  return false;
201 
202  beginInsertRows(QModelIndex(), row, row + count - 1);
203 
204  for (int r = 0; r < count; ++r)
205  lst.insert(row, QString());
206 
207  endInsertRows();
208 
209  return true;
210 }
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
void endInsertRows()
Ends a row insertion operation.
The QString class provides a Unicode character string.
Definition: qstring.h:83
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows in the model.
The QModelIndex class is used to locate data in a data model.
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.

◆ removeRows()

bool QStringListModel::removeRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
virtual

Removes count rows from the model, beginning at the given row.

The parent index of the rows is optional and is only used for consistency with QAbstractItemModel. By default, a null index is specified, indicating that the rows are removed in the top level of the model.

See also
QAbstractItemModel::removeRows()

Reimplemented from QAbstractItemModel.

Definition at line 223 of file qstringlistmodel.cpp.

224 {
225  if (count <= 0 || row < 0 || (row + count) > rowCount(parent))
226  return false;
227 
228  beginRemoveRows(QModelIndex(), row, row + count - 1);
229 
230  for (int r = 0; r < count; ++r)
231  lst.removeAt(row);
232 
233  endRemoveRows();
234 
235  return true;
236 }
void endRemoveRows()
Ends a row removal operation.
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows in the model.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
The QModelIndex class is used to locate data in a data model.
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ rowCount()

int QStringListModel::rowCount ( const QModelIndex parent = QModelIndex()) const
virtual

Returns the number of rows in the model.

This value corresponds to the number of items in the model's internal string list.

The optional parent argument is in most models used to specify the parent of the rows to be counted. Because this is a list if a valid parent is specified, the result will always be 0.

See also
insertRows(), removeRows(), QAbstractItemModel::rowCount()

Implements QAbstractItemModel.

Definition at line 122 of file qstringlistmodel.cpp.

Referenced by QFontListView::count(), insertRows(), and removeRows().

123 {
124  if (parent.isValid())
125  return 0;
126 
127  return lst.count();
128 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool isValid() const
Returns true if this model index is valid; otherwise returns false.

◆ setData()

bool QStringListModel::setData ( const QModelIndex index,
const QVariant value,
int  role = Qt::EditRole 
)
virtual

Sets the data for the specified role in the item with the given index in the model, to the provided value.

The dataChanged() signal is emitted if the item is changed.

See also
Qt::ItemDataRole, data()

Reimplemented from QAbstractItemModel.

Definition at line 175 of file qstringlistmodel.cpp.

176 {
177  if (index.row() >= 0 && index.row() < lst.size()
178  && (role == Qt::EditRole || role == Qt::DisplayRole)) {
179  lst.replace(index.row(), value.toString());
180  emit dataChanged(index, index);
181  return true;
182  }
183  return false;
184 }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
int row() const
Returns the row this model index refers to.
#define emit
Definition: qobjectdefs.h:76
void replace(int i, const T &t)
Replaces the item at index position i with value.
Definition: qlist.h:609
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.

◆ setStringList()

void QStringListModel::setStringList ( const QStringList strings)

Sets the model's internal string list to strings.

The model will notify any attached views that its underlying data has changed.

See also
dataChanged()

Definition at line 294 of file qstringlistmodel.cpp.

Referenced by QScriptDebuggerLocalsWidgetPrivate::_q_onCompletionTaskFinished(), and QFontComboBoxPrivate::_q_updateModel().

295 {
297  lst = strings;
299 }
void endResetModel()
Completes a model reset operation.
#define emit
Definition: qobjectdefs.h:76
void beginResetModel()
Begins a model reset operation.

◆ sort()

void QStringListModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
)
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 251 of file qstringlistmodel.cpp.

252 {
254 
256  for (int i = 0; i < lst.count(); ++i)
257  list.append(QPair<QString, int>(lst.at(i), i));
258 
259  if (order == Qt::AscendingOrder)
260  qSort(list.begin(), list.end(), ascendingLessThan);
261  else
262  qSort(list.begin(), list.end(), decendingLessThan);
263 
264  lst.clear();
265  QVector<int> forwarding(list.count());
266  for (int i = 0; i < list.count(); ++i) {
267  lst.append(list.at(i).first);
268  forwarding[list.at(i).second] = i;
269  }
270 
272  QModelIndexList newList;
273  for (int i = 0; i < oldList.count(); ++i)
274  newList.append(index(forwarding.at(oldList.at(i).row()), 0));
275  changePersistentIndexList(oldList, newList);
276 
278 }
QModelIndexList persistentIndexList() const
Returns the list of indexes stored as persistent indexes in the model.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QModelIndex index(int row, int column=0, const QModelIndex &parent=QModelIndex()) const
Returns the index of the data in row and column with parent.
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list t...
static bool ascendingLessThan(const QPair< QString, int > &s1, const QPair< QString, int > &s2)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
int row() const
Returns the row this model index refers to.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
void clear()
Removes all items from the list.
Definition: qlist.h:764
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
static bool decendingLessThan(const QPair< QString, int > &s1, const QPair< QString, int > &s2)
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ stringList()

QStringList QStringListModel::stringList ( ) const

Returns the string list used by the model to store data.

Definition at line 283 of file qstringlistmodel.cpp.

Referenced by QFontListView::currentText(), and QFontListView::text().

284 {
285  return lst;
286 }

◆ supportedDropActions()

Qt::DropActions QStringListModel::supportedDropActions ( ) const
virtual

Reimplemented Function

Reimplemented from QAbstractItemModel.

Definition at line 304 of file qstringlistmodel.cpp.

305 {
307 }
virtual Qt::DropActions supportedDropActions() const
Returns the drop actions supported by this model.

Properties

◆ lst

QStringList QStringListModel::lst
private

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