40 #include <QItemSelection>
42 #include <QtCore/QRegularExpression>
58 int r = sourceIndex.row(),
c = sourceIndex.column();
59 int n = this->sourceModel()->columnCount();
65 int k = (n * (n - 1) / 2) - (n -
r) * ((n -
r) - 1) / 2 +
c -
r - 1;
73 int n = sourceModel()->columnCount();
74 int k = proxyIndex.row();
75 int r = n - 2 - (int)(sqrt(-8 * k + 4 * n * (n - 1) - 7) / 2.0 - 0.5);
76 int c = k +
r + 1 - n * (n - 1) / 2 + (n -
r) * ((n -
r) - 1) / 2;
77 return sourceModel()->index(
r,
c);
82 int n = this->sourceModel()->rowCount();
83 return (n * (n - 1) / 2);
93 return createIndex(row, column);
104 switch (
index.column())
107 if (role != Qt::DisplayRole)
110 return this->sourceModel()->headerData(src_index.row(), Qt::Horizontal, Qt::DisplayRole);
112 if (role != Qt::DisplayRole)
114 return this->sourceModel()->headerData(src_index.column(), Qt::Vertical, Qt::DisplayRole);
116 if (role != Qt::CheckStateRole)
119 return this->sourceModel()->data(src_index, Qt::CheckStateRole);
121 if (role != Qt::DisplayRole)
124 return this->sourceModel()->data(src_index, Qt::ToolTipRole);
131 if (role == Qt::CheckStateRole)
137 Q_EMIT dataChanged(this->
index(r, 2), this->
index(r, 3));
146 for (
const auto idx : selection.indexes())
148 if (idx.column() != 2)
150 setData(idx,
value ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
156 if (
index.column() == 2)
157 return Qt::ItemIsUserCheckable | QAbstractItemModel::flags(
index);
159 return QAbstractItemModel::flags(
index);
164 if (role != Qt::DisplayRole)
167 if (orientation == Qt::Horizontal)
178 return "Reason to Disable";
181 else if (orientation == Qt::Vertical)
190 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
191 connect(
this, SIGNAL(sourceModelChanged()),
this, SLOT(
initSorting()));
196 sort_orders_ << Qt::AscendingOrder << Qt::AscendingOrder;
201 if (role == Qt::DisplayRole && orientation == Qt::Vertical)
204 return QSortFilterProxyModel::headerData(section, orientation, role);
214 int cols = sourceModel()->columnCount();
220 for (
int i = prev_size, end =
sort_columns_.size(); i < end; ++i)
236 if (!(
show_all_ ||
m->data(
m->index(source_row, 2), Qt::CheckStateRole) == Qt::Checked))
238 #if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0))
239 const QRegExp regexp = this->filterRegExp();
240 if (regexp.isEmpty())
243 const QRegularExpression regexp = this->filterRegularExpression();
244 if (!regexp.isValid())
248 return m->data(
m->index(source_row, 0, source_parent), Qt::DisplayRole).toString().contains(regexp) ||
249 m->data(
m->index(source_row, 1, source_parent), Qt::DisplayRole).toString().contains(regexp);
253 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
256 bool operator<(
const QVariant& left,
const QVariant& right)
258 if (left.userType() == QVariant::Type::Int)
259 return left.toInt() < right.toInt();
261 return left.toString() < right.toString();
268 int row_left = src_left.row();
269 int row_right = src_right.row();
270 QAbstractItemModel*
m = sourceModel();
275 int role = sc == 2 ? Qt::CheckStateRole : Qt::DisplayRole;
276 QVariant value_left =
m->data(
m->index(row_left, sc), role);
277 QVariant value_right =
m->data(
m->index(row_right, sc), role);
279 if (value_left == value_right)
283 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
284 switch (value_left.type())
286 switch (value_left.typeId())
290 smaller = value_left.toInt() < value_right.toInt();
293 smaller = value_left.toString() < value_right.toString();
321 QSortFilterProxyModel::sort(column, Qt::AscendingOrder);