15 int CListModelBaseNonTemplate::columnCount(
const QModelIndex &modelIndex)
const
18 int c = m_columns.size();
27 if (section < 0 || section >= m_columns.size()) {
return QVariant(); }
46 CPropertyIndex CListModelBaseNonTemplate::columnToPropertyIndex(
int column)
const
48 return m_columns.columnToPropertyIndex(column);
51 int CListModelBaseNonTemplate::propertyIndexToColumn(
const CPropertyIndex &propertyIndex)
const
53 return m_columns.propertyIndexToColumn(propertyIndex);
58 return this->columnToPropertyIndex(index.
column());
63 const int column = this->propertyIndexToColumn(propertyIndex);
64 this->sort(column, order);
67 bool CListModelBaseNonTemplate::setSortColumnByPropertyIndex(
const CPropertyIndex &propertyIndex)
69 const int column = m_columns.propertyIndexToColumn(propertyIndex);
70 if (m_sortColumn == column) {
return false; }
71 m_sortColumn = column;
83 const bool changedColumn = this->setSortColumnByPropertyIndex(propertyIndex);
84 const bool changedOrder = (m_sortOrder == order);
86 return changedColumn || changedOrder;
92 return m_columns.at(m_sortColumn).getPropertyIndex();
95 bool CListModelBaseNonTemplate::hasValidSortColumn()
const
97 if (!(m_sortColumn >= 0 && m_sortColumn < m_columns.size())) {
return false; }
98 return m_columns.isSortable(m_sortColumn);
104 if (!index.
isValid()) {
return f; }
105 const bool editable = m_columns.isEditable(index);
110 if (formatter) { f = formatter->
flags(f, editable); }
122 Qt::DropActions CListModelBaseNonTemplate::supportedDropActions()
const {
return m_dropActions; }
126 static const QStringList mimes({
"application/swift.container.json" });
130 void CListModelBaseNonTemplate::markDestroyed() { m_modelDestroyed =
true; }
132 bool CListModelBaseNonTemplate::isModelDestroyed() {
return m_modelDestroyed; }
134 void CListModelBaseNonTemplate::clearHighlighting()
139 bool CListModelBaseNonTemplate::hasHighlightedRows()
const
145 void CListModelBaseNonTemplate::emitDataChanged(
int startRowIndex,
int endRowIndex)
147 SWIFT_VERIFY_X(startRowIndex <= endRowIndex, Q_FUNC_INFO,
"check rows");
148 SWIFT_VERIFY_X(startRowIndex >= 0 && endRowIndex >= 0, Q_FUNC_INFO,
"check rows");
150 const int columns = columnCount();
151 const int rows = rowCount();
152 if (columns < 1) {
return; }
153 if (startRowIndex < 0) { startRowIndex = 0; }
154 if (endRowIndex >= rows) { endRowIndex = rows - 1; }
155 const QModelIndex topLeft(createIndex(startRowIndex, 0));
156 const QModelIndex bottomRight(createIndex(endRowIndex, columns - 1));
157 emit this->dataChanged(topLeft, bottomRight);
160 CListModelBaseNonTemplate::CListModelBaseNonTemplate(
const QString &translationContext,
QObject *parent)
161 :
QStandardItemModel(parent), m_columns(translationContext), m_sortColumn(-1), m_sortOrder(
Qt::AscendingOrder)
virtual void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)=0
Feedback when QStandardItemModel::dataChanged was called.
bool isEmpty() const
Empty?
static const CPropertyIndex & empty()
an empty property index
Models to be used with views, mainly QTableView.
Free functions in swift::misc.
QModelIndex createIndex(int row, int column, const void *ptr) const const
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setObjectName(QAnyStringView name)
virtual Qt::ItemFlags flags(const QModelIndex &index) const const override
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.