40 #include <QItemSelection> 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(srcIndex.row(), Qt::Horizontal, Qt::DisplayRole);
112 if (role != Qt::DisplayRole)
114 return this->sourceModel()->headerData(srcIndex.column(), Qt::Vertical, Qt::DisplayRole);
116 if (role != Qt::CheckStateRole)
119 return this->sourceModel()->data(srcIndex, Qt::CheckStateRole);
121 if (role != Qt::DisplayRole)
124 return this->sourceModel()->data(srcIndex, Qt::ToolTipRole);
139 if (role == Qt::CheckStateRole)
141 sourceModel()->setData(srcIndex, value, role);
143 Q_EMIT dataChanged(this->
index(r, 2), this->
index(r, 3));
151 for (
const auto idx : selection.indexes())
153 if (idx.column() != 2)
155 setData(idx, value ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
161 if (index.column() == 2)
162 return Qt::ItemIsUserCheckable | QAbstractItemModel::flags(index);
164 return QAbstractItemModel::flags(index);
169 if (role != Qt::DisplayRole)
172 if (orientation == Qt::Horizontal)
183 return "Reason to Disable";
186 else if (orientation == Qt::Vertical)
195 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 196 connect(
this, SIGNAL(sourceModelChanged()),
this, SLOT(
initSorting()));
201 sort_orders_ << Qt::AscendingOrder << Qt::AscendingOrder;
206 if (role == Qt::DisplayRole && orientation == Qt::Vertical)
209 return QSortFilterProxyModel::headerData(section, orientation, role);
219 int cols = sourceModel()->columnCount();
225 for (
int i = prev_size, end =
sort_columns_.size(); i < end; ++i)
242 m->
data(m->
index(source_row, 2), Qt::CheckStateRole) == Qt::Checked))
245 const QRegExp regexp = this->filterRegExp();
246 if (regexp.isEmpty())
249 return m->
data(m->
index(source_row, 0, source_parent), Qt::DisplayRole).
toString().contains(regexp) ||
250 m->
data(m->
index(source_row, 1, source_parent), Qt::DisplayRole).
toString().contains(regexp);
254 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) 257 bool operator<(
const QVariant& left,
const QVariant& right)
259 if (left.userType() == QVariant::Type::Int)
260 return left.toInt() < right.toInt();
262 return left.toString() < right.toString();
269 int row_left = src_left.row();
270 int row_right = src_right.row();
271 QAbstractItemModel* m = sourceModel();
273 for (
int i = 0, end =
sort_columns_.size(); i < end && sort_columns_[i] >= 0; ++i)
276 int role = sc == 2 ? Qt::CheckStateRole : Qt::DisplayRole;
277 QVariant value_left = m->data(m->index(row_left, sc), role);
278 QVariant value_right = m->data(m->index(row_right, sc), role);
280 if (value_left == value_right)
283 bool smaller = (value_left < value_right);
309 QSortFilterProxyModel::sort(column, Qt::AscendingOrder);
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
CollisionLinearModel(CollisionMatrixModel *src, QObject *parent=NULL)
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
SortFilterProxyModel(QObject *parent=0)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
QVector< int > sort_orders_
moveit_setup_assistant::DisabledReason reason(int row) const
void setEnabled(const QItemSelection &selection, bool value)
QModelIndex parent(const QModelIndex &child) const
int columnCount(const QModelIndex &parent) const
QVector< int > sort_columns_
QVariant data(const QModelIndex &index, int role) const
std::string toString(double d)
void sort(int column, Qt::SortOrder order)
DisabledReason
Reasons for disabling link pairs. Append "in collision" for understanding. NOT_DISABLED means the lin...
void setShowAll(bool show_all)
int rowCount(const QModelIndex &parent) const
bool lessThan(const QModelIndex &src_left, const QModelIndex &src_right) const
void setEnabled(const QItemSelection &selection, bool value)
bool setData(const QModelIndex &index, const QVariant &value, int role)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Qt::ItemFlags flags(const QModelIndex &index) const