33 #include <QVBoxLayout> 36 #include <QMouseEvent> 47 size_t name_hash = std::hash<std::string>{}(name.toStdString());
49 int h = (name_hash >> 0) % 255;
50 int s = (name_hash >> 8) % 200 + 55;
51 int v = (name_hash >> 16) % 200 + 55;
52 return QColor::fromHsv(h, s, v);
62 QObject::connect(
view_animator_, SIGNAL(valueChanged(
const QVariant &)),
75 qWarning(
"PartitionWidget: Cannot change the profile database.");
82 QObject::connect(
db_, SIGNAL(dataAdded(
int)),
this, SLOT(
updateData()));
83 QObject::connect(
db_, SIGNAL(profileAdded(
int)),
this, SLOT(
updateData()));
84 QObject::connect(
db_, SIGNAL(nodesAdded(
int)),
this, SLOT(
updateData()));
104 QPainter painter(
this);
107 QRect win_rect(0,0,width(), height());
108 painter.setBrush(Qt::white);
109 painter.drawRect(win_rect.adjusted(1,1,-1,-1));
114 QRectF win_rect(QPointF(0, 0), QPointF(width()-1, height()-1));
115 win_rect = win_rect.adjusted(1,1,-1,-1);
124 if (layout.empty()) {
125 return QRectF(0.0, 0.0, 1.0, 1.0);
128 double right = layout.back().rect.right();
130 for (
auto const &item : layout) {
132 QRectF rect = item.rect;
134 rect.setLeft(std::max(0.0, rect.left()-0.2));
135 rect.setRight(right);
137 double margin = 0.05 * rect.height();
138 rect.setTop(std::max(0.0, rect.top() - margin));
139 rect.setBottom(std::min(1.0, rect.bottom() + margin));
144 qWarning(
"Active node key was not found in layout");
145 return QRectF(QPointF(0.0, 0.0), QPointF(right, 1.0));
165 QRectF data_rect =
dataRect(layout);
188 qWarning(
"Profile returned invalid root node.");
192 if (root_node.
data().empty()) {
196 double time_scale = root_node.
data().back().cumulative_inclusive_duration_ns;
202 root_item.
rect = QRectF(column, 0.0, 1, 1.0);
203 layout.push_back(root_item);
207 std::vector<LayoutItem> parents;
208 std::vector<LayoutItem> children;
209 parents.push_back(root_item);
216 double span_start = 0.0;
217 for (
auto const &parent_item : parents) {
222 double height = parent_node.
data().back().cumulative_exclusive_duration_ns/time_scale;
224 item.
node_key = parent_item.node_key;
226 item.
rect = QRectF(column, span_start, 1, height);
227 children.push_back(item);
228 span_start = item.
rect.bottom();
232 if (parent_item.exclusive) {
236 for (
int child_key : parent_node.
childKeys()) {
238 double height = child_node.
data().back().cumulative_inclusive_duration_ns / time_scale;
243 item.
rect = QRectF(column, span_start, 1, height);
244 children.push_back(item);
245 span_start = item.
rect.bottom();
251 layout.insert(layout.end(), children.begin(), children.end());
252 parents.swap(children);
260 const QTransform &win_from_data,
265 painter.setPen(Qt::black);
267 double right = layout.back().rect.right();
269 for (
auto const &item : layout) {
270 if (item.exclusive) {
277 QRectF data_rect = item.rect;
278 data_rect.setRight(right);
279 QRectF win_rect = win_from_data.mapRect(data_rect);
282 painter.setBrush(color);
283 painter.drawRect(int_rect.adjusted(0,0,-1,-1));
288 const QRectF &data_rect)
290 double sx = win_rect.width() / data_rect.width();
291 double sy = win_rect.height() / data_rect.height();
292 double tx = win_rect.topLeft().x() - sx*data_rect.topLeft().x();
293 double ty = win_rect.topLeft().y() - sy*data_rect.topLeft().y();
295 QTransform win_from_data(sx, 0.0, 0.0,
298 return win_from_data;
305 if (item.rect.contains(point)) {
314 if (event->type() == QEvent::ToolTip) {
319 return QWidget::event(event);
325 int index =
itemAtPoint(data_from_win.map(QPointF(event->pos())));
328 QToolTip::hideText();
337 tool_tip = profile.
name();
341 tool_tip +=
" [exclusive]";
347 QToolTip::showText(event->globalPos(), tool_tip,
this, int_rect);
357 #if QT_VERSION >= 0x050000 358 int index =
itemAtPoint(data_from_win.map(event->localPos()));
360 int index =
itemAtPoint(data_from_win.map(event->posF()));
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)