add button to reset zoom/pan of chart viewer
This commit is contained in:
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLineSeries>
|
#include <QLineSeries>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@ -30,9 +31,17 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
|
|||||||
menu->addMenu(file);
|
menu->addMenu(file);
|
||||||
menu->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
menu->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||||
|
|
||||||
|
// workaround for incorrect highlight bug on macOS
|
||||||
|
auto *dummy = new QPushButton(QIcon(), "");
|
||||||
|
dummy->hide();
|
||||||
|
auto *normal = new QPushButton(QIcon(":/icons/gtk-zoom-fit.png"), "");
|
||||||
|
normal->setToolTip("Reset zoom to normal");
|
||||||
|
|
||||||
columns = new QComboBox;
|
columns = new QComboBox;
|
||||||
top->addWidget(menu);
|
top->addWidget(menu);
|
||||||
top->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
top->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
||||||
|
top->addWidget(dummy);
|
||||||
|
top->addWidget(normal);
|
||||||
top->addWidget(new QLabel("Select data:"));
|
top->addWidget(new QLabel("Select data:"));
|
||||||
top->addWidget(columns);
|
top->addWidget(columns);
|
||||||
saveAsAct = file->addAction("&Save Graph As...", this, &ChartWindow::saveAs);
|
saveAsAct = file->addAction("&Save Graph As...", this, &ChartWindow::saveAs);
|
||||||
@ -44,9 +53,10 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
|
|||||||
file->addSeparator();
|
file->addSeparator();
|
||||||
stopAct = file->addAction("Stop &Run", this, &ChartWindow::stop_run);
|
stopAct = file->addAction("Stop &Run", this, &ChartWindow::stop_run);
|
||||||
stopAct->setIcon(QIcon(":/icons/process-stop.png"));
|
stopAct->setIcon(QIcon(":/icons/process-stop.png"));
|
||||||
stopAct->setShortcut(QKeySequence(Qt::Key_Slash, Qt::CTRL));
|
stopAct->setShortcut(QKeySequence::fromString("Ctrl+/"));
|
||||||
closeAct = file->addAction("&Close", this, &QWidget::close);
|
closeAct = file->addAction("&Close", this, &QWidget::close);
|
||||||
closeAct->setIcon(QIcon(":/icons/window-close.png"));
|
closeAct->setIcon(QIcon(":/icons/window-close.png"));
|
||||||
|
closeAct->setShortcut(QKeySequence::fromString("Ctrl+W"));
|
||||||
quitAct = file->addAction("&Quit", this, &ChartWindow::quit);
|
quitAct = file->addAction("&Quit", this, &ChartWindow::quit);
|
||||||
quitAct->setIcon(QIcon(":/icons/application-exit.png"));
|
quitAct->setIcon(QIcon(":/icons/application-exit.png"));
|
||||||
quitAct->setShortcut(QKeySequence::fromString("Ctrl+Q"));
|
quitAct->setShortcut(QKeySequence::fromString("Ctrl+Q"));
|
||||||
@ -54,6 +64,8 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
|
|||||||
layout->addLayout(top);
|
layout->addLayout(top);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
|
connect(normal, &QPushButton::released, this, &ChartWindow::reset_zoom);
|
||||||
|
|
||||||
connect(columns, SIGNAL(currentIndexChanged(int)), this, SLOT(change_chart(int)));
|
connect(columns, SIGNAL(currentIndexChanged(int)), this, SLOT(change_chart(int)));
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
resize(settings.value("chartx", 500).toInt(), settings.value("charty", 320).toInt());
|
resize(settings.value("chartx", 500).toInt(), settings.value("charty", 320).toInt());
|
||||||
@ -108,6 +120,12 @@ void ChartWindow::quit()
|
|||||||
main->quit();
|
main->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChartWindow::reset_zoom()
|
||||||
|
{
|
||||||
|
int choice = columns->currentData().toInt();
|
||||||
|
charts[choice]->reset_zoom();
|
||||||
|
}
|
||||||
|
|
||||||
void ChartWindow::stop_run()
|
void ChartWindow::stop_run()
|
||||||
{
|
{
|
||||||
LammpsGui *main;
|
LammpsGui *main;
|
||||||
@ -266,6 +284,26 @@ void ChartViewer::add_data(int step, double data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void ChartViewer::reset_zoom()
|
||||||
|
{
|
||||||
|
auto points = series->pointsVector();
|
||||||
|
|
||||||
|
qreal xmin = 1.0e100;
|
||||||
|
qreal xmax = -1.0e100;
|
||||||
|
qreal ymin = 1.0e100;
|
||||||
|
qreal ymax = -1.0e100;
|
||||||
|
for (auto &p : points) {
|
||||||
|
xmin = qMin(xmin, p.x());
|
||||||
|
xmax = qMax(xmax, p.x());
|
||||||
|
ymin = qMin(ymin, p.y());
|
||||||
|
ymax = qMax(ymax, p.y());
|
||||||
|
}
|
||||||
|
xaxis->setRange(xmin, xmax);
|
||||||
|
yaxis->setRange(ymin, ymax);
|
||||||
|
}
|
||||||
|
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// c-basic-offset: 4
|
// c-basic-offset: 4
|
||||||
// End:
|
// End:
|
||||||
|
|||||||
@ -43,6 +43,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void quit();
|
void quit();
|
||||||
|
void reset_zoom();
|
||||||
void stop_run();
|
void stop_run();
|
||||||
|
|
||||||
void saveAs();
|
void saveAs();
|
||||||
@ -74,6 +75,8 @@ public:
|
|||||||
explicit ChartViewer(const QString &title, int index, QWidget *parent = nullptr);
|
explicit ChartViewer(const QString &title, int index, QWidget *parent = nullptr);
|
||||||
|
|
||||||
void add_data(int step, double data);
|
void add_data(int step, double data);
|
||||||
|
void reset_zoom();
|
||||||
|
|
||||||
int get_index() const { return index; };
|
int get_index() const { return index; };
|
||||||
int get_count() const { return series->count(); }
|
int get_count() const { return series->count(); }
|
||||||
const char *get_title() const { return series->name().toLocal8Bit(); }
|
const char *get_title() const { return series->name().toLocal8Bit(); }
|
||||||
|
|||||||
Reference in New Issue
Block a user