15 int CListModelBaseNonTemplate::columnCount(
const QModelIndex &modelIndex)
const
18 int c = m_columns.size();
22 QVariant CListModelBaseNonTemplate::headerData(
int section, Qt::Orientation orientation,
int role)
const
24 if (orientation != Qt::Horizontal) {
return QVariant(); }
25 const bool handled = (role == Qt::DisplayRole || role == Qt::ToolTipRole || role == Qt::InitialSortOrderRole);
26 if (!handled) {
return QVariant(); }
27 if (section < 0 || section >= m_columns.size()) {
return QVariant(); }
29 if (role == Qt::DisplayRole) {
return QVariant(m_columns.at(section).getColumnName()); }
30 if (role == Qt::ToolTipRole) {
return QVariant(m_columns.at(section).getColumnToolTip()); }
34 QModelIndex CListModelBaseNonTemplate::index(
int row,
int column,
const QModelIndex &parent)
const
37 return QStandardItemModel::createIndex(row, column);
40 QModelIndex CListModelBaseNonTemplate::parent(
const QModelIndex &child)
const
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);
56 CPropertyIndex CListModelBaseNonTemplate::modelIndexToPropertyIndex(
const QModelIndex &index)
const
58 return this->columnToPropertyIndex(index.column());
61 void CListModelBaseNonTemplate::sortByPropertyIndex(
const CPropertyIndex &propertyIndex, Qt::SortOrder order)
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;
75 bool CListModelBaseNonTemplate::setSorting(
const CPropertyIndex &propertyIndex, Qt::SortOrder order)
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);
101 Qt::ItemFlags CListModelBaseNonTemplate::flags(
const QModelIndex &index)
const
103 Qt::ItemFlags f = QStandardItemModel::flags(index);
104 if (!index.isValid()) {
return f; }
105 const bool editable = m_columns.isEditable(index);
106 f = editable ? (f | Qt::ItemIsEditable) : (f & ~Qt::ItemIsEditable);
110 if (formatter) { f = formatter->
flags(f, editable); }
113 f = f | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
117 Qt::DropActions CListModelBaseNonTemplate::supportedDragActions()
const
119 return isOrderable() ? Qt::CopyAction | Qt::MoveAction : Qt::CopyAction;
122 Qt::DropActions CListModelBaseNonTemplate::supportedDropActions()
const {
return m_dropActions; }
124 QStringList CListModelBaseNonTemplate::mimeTypes()
const
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)
164 this->setObjectName(translationContext);
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.
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.