38 #include <boost/unordered_map.hpp> 39 #include <boost/assign.hpp> 44 #include <QApplication> 45 #include <QItemSelection> 50 static const boost::unordered_map<moveit_setup_assistant::DisabledReason, const char*>
longReasonsToString =
51 boost::assign::map_list_of
60 static const boost::unordered_map<moveit_setup_assistant::DisabledReason, QVariant>
longReasonsToBrush =
61 boost::assign::map_list_of
70 const std::vector<std::string>& names, QObject* parent)
71 : QAbstractTableModel(parent), pairs(pairs), std_names(names)
74 for (std::vector<std::string>::const_iterator it = names.begin(), end = names.end(); it != end; ++it, ++idx)
77 q_names << QString::fromStdString(*it);
107 if (index.isValid() && index.row() == index.column() && role == Qt::BackgroundRole)
108 return QApplication::palette().window();
110 moveit_setup_assistant::LinkPairMap::const_iterator
item = this->
item(index);
111 if (item ==
pairs.end())
116 case Qt::CheckStateRole:
117 return item->second.disable_check ? Qt::Checked : Qt::Unchecked;
118 case Qt::ToolTipRole:
120 case Qt::BackgroundRole:
121 return longReasonsToBrush.at(item->second.reason);
128 moveit_setup_assistant::LinkPairMap::const_iterator
item = this->
item(index);
129 if (item ==
pairs.end())
131 return item->second.reason;
136 if (role == Qt::CheckStateRole)
138 moveit_setup_assistant::LinkPairMap::iterator
item = this->
item(index);
139 if (item ==
pairs.end())
142 bool new_value = (value.toInt() == Qt::Checked);
143 if (item->second.disable_check == new_value)
146 item->second.disable_check = new_value;
156 QModelIndex mirror = this->index(index.column(), index.row());
157 Q_EMIT dataChanged(index, index);
158 Q_EMIT dataChanged(mirror, mirror);
167 QItemSelection changes;
169 for (
const auto range : selection)
173 const QModelIndex& top_left = range.topLeft();
174 const QModelIndex& bottom_right = range.bottomRight();
175 changes.select(top_left, bottom_right);
176 changes.select(createIndex(top_left.column(), top_left.row()),
177 createIndex(bottom_right.column(), bottom_right.row()));
182 for (
const auto range : changes)
183 Q_EMIT dataChanged(range.topLeft(), range.bottomRight());
188 for (
const auto idx : indexes)
189 setData(idx, value ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
195 QRegExp regexp(filter);
197 for (
int idx = 0, end =
q_names.size(); idx != end; ++idx)
199 if (
q_names[idx].contains(regexp))
207 if (role == Qt::DisplayRole)
214 if (!index.isValid())
217 Qt::ItemFlags
f = QAbstractTableModel::flags(index);
218 if (index.row() != index.column())
219 f |= Qt::ItemIsUserCheckable;
moveit_setup_assistant::LinkPairMap & pairs
static const boost::unordered_map< moveit_setup_assistant::DisabledReason, QVariant > longReasonsToBrush
Boost mapping of reasons to a background color.
CollisionMatrixModel(moveit_setup_assistant::LinkPairMap &pairs, const std::vector< std::string > &names, QObject *parent=NULL)
bool setData(const QModelIndex &, const QVariant &value, int role)
Qt::ItemFlags flags(const QModelIndex &index) const
int rowCount(const QModelIndex &parent=QModelIndex()) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const
QList< int > visual_to_index
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
DisabledReason
Reasons for disabling link pairs. Append "in collision" for understanding. NOT_DISABLED means the lin...
const std::vector< std::string > std_names
static const boost::unordered_map< moveit_setup_assistant::DisabledReason, const char * > longReasonsToString
Boost mapping of reasons for disabling a link pair to strings.
int columnCount(const QModelIndex &parent=QModelIndex()) const
void setFilterRegExp(const QString &filter)
moveit_setup_assistant::LinkPairMap::iterator item(const QModelIndex &index)
void setEnabled(const QItemSelection &selection, bool value)
std::map< std::pair< std::string, std::string >, LinkPairData > LinkPairMap
LinkPairMap is an adjacency list structure containing links in string-based form. Used for disabled l...
moveit_setup_assistant::DisabledReason reason(const QModelIndex &index) const