Skip to content

Commit

Permalink
Merge pull request #115 from SchrodingersGat/plot-title
Browse files Browse the repository at this point in the history
Allow setting plot title
  • Loading branch information
SchrodingersGat authored Dec 16, 2024
2 parents 44d14ca + 2485098 commit d76431c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ void MainWindow::addPlot()

PlotWidget *plot = new PlotWidget();

QDockWidget *dock = new QDockWidget(tr("Plot") + QString(" ") + QString::number(plotIndex), this);
QString title = tr("Plot") + QString(" ") + QString::number(plotIndex);

QDockWidget *dock = new QDockWidget(title, this);
dock->setWindowTitle(title);
dock->setObjectName("plot-" + QString::number(plotIndex));
dock->setAllowedAreas(Qt::AllDockWidgetAreas);
plot->setParent(dock);
Expand Down
38 changes: 38 additions & 0 deletions src/plot_widget.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <QApplication>
#include <QMimeData>
#include <QDockWidget>
#include <QInputDialog>
#include <qcolordialog.h>
#include <qmenu.h>
#include <qaction.h>
Expand Down Expand Up @@ -397,6 +399,7 @@ void PlotWidget::onContextMenu(const QPoint &pos)
syncAction->setChecked(isTimescaleSynced());

QAction *bgColor = plotMenu->addAction(tr("Set Color"));
QAction *plotTitle = plotMenu->addAction(tr("Set Title"));

menu.addMenu(plotMenu);

Expand Down Expand Up @@ -476,6 +479,10 @@ void PlotWidget::onContextMenu(const QPoint &pos)
{
selectBackgroundColor();
}
else if (action == plotTitle)
{
setPlotTitle();
}
}


Expand Down Expand Up @@ -544,6 +551,37 @@ void PlotWidget::selectBackgroundColor()
}


void PlotWidget::setPlotTitle(QString title)
{
bool ok = true;

QDockWidget *dock = qobject_cast<QDockWidget*>(parent());

QString currentTitle = !!dock ? dock->windowTitle() : windowTitle();

if (title.isEmpty())
{
title = QInputDialog::getText(
this,
tr("Set Title"),
tr("Set plot tile"),
QLineEdit::Normal,
windowTitle()
);
}

if (ok && !title.isEmpty())
{
setWindowTitle(title);

if (dock)
{
dock->setWindowTitle(title);
}
}
}


/**
* @brief PlotWidget::exportDataToFile - export data to a file
*/
Expand Down
1 change: 1 addition & 0 deletions src/plot_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public slots:
void autoScale(QSharedPointer<PlotCurve> curve);

void setBackgroundColor(QColor color);
void setPlotTitle(QString title = QString());

void onContextMenu(const QPoint &pos);

Expand Down

0 comments on commit d76431c

Please sign in to comment.