Skip to content

Commit

Permalink
Add error message when exporting a flamegraph that hasn't been opened
Browse files Browse the repository at this point in the history
In order to save a flamegraph to an image or SVG, it must have been
opened at least once so the graphics item is loaded. If you try to
export it before doing so, you'll still get prompted to save the file,
but it won't be (nor can be) written.

Now there's an explicit check with it's own error message in that case.
  • Loading branch information
redstrate authored and milianw committed Jan 30, 2024
1 parent e398f8c commit 55ee32c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/flamegraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,8 @@ void FlameGraph::setData(FrameGraphicsItem* rootItem)
if (isVisible()) {
selectItem(m_rootItem);
}

emit canConvertToImageChanged();
}

void FlameGraph::selectItem(int item)
Expand Down Expand Up @@ -1238,3 +1240,8 @@ void FlameGraph::updateNavigationActions()
m_forwardAction->setEnabled(isNotLastItem);
m_resetAction->setEnabled(hasItems);
}

bool FlameGraph::canConvertToImage() const
{
return m_rootItem != nullptr;
}
2 changes: 2 additions & 0 deletions src/flamegraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class FlameGraph : public QWidget

QImage toImage() const;
void saveSvg(const QString& fileName) const;
bool canConvertToImage() const;

protected:
bool eventFilter(QObject* object, QEvent* event) override;
Expand All @@ -55,6 +56,7 @@ private slots:
void selectStack(const QVector<Data::Symbol>& stack, bool bottomUp);
void jumpToDisassembly(const Data::Symbol& symbol);
void uiResetRequested();
void canConvertToImageChanged();

private:
void setTooltipItem(const FrameGraphicsItem* item);
Expand Down
5 changes: 5 additions & 0 deletions src/resultsflamegraphpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ ResultsFlameGraphPage::ResultsFlameGraphPage(FilterAndZoomStack* filterStack, Pe
connect(parser, &PerfParser::bottomUpDataAvailable, this, [this, exportMenu](const Data::BottomUpResults& data) {
ui->flameGraph->setBottomUpData(data);
m_exportAction = exportMenu->addAction(QIcon::fromTheme(QStringLiteral("image-x-generic")), tr("Flamegraph"));
m_exportAction->setEnabled(ui->flameGraph->canConvertToImage());

connect(ui->flameGraph, &FlameGraph::canConvertToImageChanged, m_exportAction,
[this] { m_exportAction->setEnabled(ui->flameGraph->canConvertToImage()); });

connect(m_exportAction, &QAction::triggered, this, [this]() {
const auto filter = tr("Images (%1);;SVG (*.svg)").arg(imageFormatFilter());
QString selectedFilter;
Expand Down

0 comments on commit 55ee32c

Please sign in to comment.