2016-03-01 50 views
1

爲什麼使用重量清單模型時,必須在dataindex方法中指定一列?在重量清單模型中索引項目

The WAbstractListModel doc說,「一個抽象列表模型專門爲一維列表(即一列沒有孩子的模型)提供WAbstractItemModel。」

WAbstractListModel::index原型是index (int row, int column, const WModelIndex &parent=WModelIndex())index (int row, const WModelIndex &parent=WModelIndex())也不合理嗎?

WStringListModel::data中發現了相同的情況,其原型爲data (int row, int column, int role=DisplayRole, const WModelIndex &parent=WModelIndex())? WStringListModel(或WAbstractListModel的任何實現)提供方法data (int row, int role=DisplayRole, const WModelIndex &parent=WModelIndex())是否合理?

我知道Wt在許多方面都是不完整的。缺乏列表模型的一維API僅僅是不完整的結果?或者是否有一些概念上的理由需要在這裏指定列號?

回答

1

Response from Wt developer

WAbstractListModel沒有太大增加(除了表達意圖)。

項目模型和視圖已經在Qt中建模,而 在大多數方面與Qt提供的相同。例如見 http://doc.qt.io/qt-5/qstringlistmodel.html

這Qt的鏈接顯示,無論我的建議是那裏執行。

QAbstractListModel::index不要求你指定一個列:

QModelIndex QAbstractListModel::index(int row, int column = 0, const QModelIndex & parent = QModelIndex()) const

而且,QStringListModel::data沒有列參數:

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

所以,我這個粉化了到「不完整」。