mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2167 statistics dialog. Screen dump to clipboard or file
This commit is contained in:
parent
c0615134a9
commit
f8256a30b8
@ -17,6 +17,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicSnapshotViewToClipboardFeature.h"
|
||||
#include "RicGridStatisticsDialog.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
@ -39,6 +40,34 @@
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicSnapshotViewToClipboardFeature, "RicSnapshotViewToClipboardFeature");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSnapshotViewToClipboardFeature::copyToClipboard(const QImage& image)
|
||||
{
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
if (clipboard)
|
||||
{
|
||||
clipboard->setImage(image);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QIcon RicSnapshotViewToClipboardFeature::icon()
|
||||
{
|
||||
return QIcon(":/SnapShot.png");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicSnapshotViewToClipboardFeature::text()
|
||||
{
|
||||
return "Snapshot To Clipboard";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -75,6 +104,6 @@ void RicSnapshotViewToClipboardFeature::onActionTriggered(bool isChecked)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSnapshotViewToClipboardFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setText("Snapshot To Clipboard");
|
||||
actionToSetup->setIcon(QIcon(":/SnapShot.png"));
|
||||
actionToSetup->setText(text());
|
||||
actionToSetup->setIcon(icon());
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "cafCmdFeature.h"
|
||||
|
||||
class RimViewWindow;
|
||||
class QImage;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@ -29,6 +30,11 @@ class RicSnapshotViewToClipboardFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
static void copyToClipboard(const QImage& image);
|
||||
static QIcon icon();
|
||||
static QString text();
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
virtual bool isCommandEnabled() override;
|
||||
|
@ -49,20 +49,76 @@ void RicSnapshotViewToFileFeature::saveSnapshotAs(const QString& fileName, RimVi
|
||||
if (viewWindow)
|
||||
{
|
||||
QImage image = viewWindow->snapshotWindowContent();
|
||||
if (!image.isNull())
|
||||
saveSnapshotAs(fileName, image);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSnapshotViewToFileFeature::saveSnapshotAs(const QString& fileName, const QImage& image)
|
||||
{
|
||||
if (!image.isNull())
|
||||
{
|
||||
if (image.save(fileName))
|
||||
{
|
||||
if (image.save(fileName))
|
||||
{
|
||||
RiaLogging::info(QString("Exported snapshot image to %1").arg(fileName));
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::error(QString("Error when trying to export snapshot image to %1").arg(fileName));
|
||||
}
|
||||
RiaLogging::info(QString("Exported snapshot image to %1").arg(fileName));
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::error(QString("Error when trying to export snapshot image to %1").arg(fileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSnapshotViewToFileFeature::saveToFile(const QImage& image, const QString& defaultFileBaseName)
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
RimProject* proj = app->project();
|
||||
|
||||
QString startPath;
|
||||
if (!proj->fileName().isEmpty())
|
||||
{
|
||||
QFileInfo fi(proj->fileName());
|
||||
startPath = fi.absolutePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
startPath = app->lastUsedDialogDirectory("IMAGE_SNAPSHOT");
|
||||
}
|
||||
|
||||
QString defaultAbsFileName = caf::Utils::constructFullFileName(startPath, defaultFileBaseName, ".png");
|
||||
QString fileName = QFileDialog::getSaveFileName(NULL, tr("Export to File"), defaultAbsFileName);
|
||||
if (fileName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remember the directory to next time
|
||||
app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath());
|
||||
|
||||
RicSnapshotViewToFileFeature::saveSnapshotAs(fileName, image);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QIcon RicSnapshotViewToFileFeature::icon()
|
||||
{
|
||||
return QIcon(":/SnapShotSave.png");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicSnapshotViewToFileFeature::text()
|
||||
{
|
||||
return "Snapshot To File";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -77,7 +133,6 @@ bool RicSnapshotViewToFileFeature::isCommandEnabled()
|
||||
void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
RimProject* proj = app->project();
|
||||
|
||||
// Get active view window before displaying the file selection dialog
|
||||
// If this is done after the file save dialog is displayed (and closed)
|
||||
@ -90,29 +145,8 @@ void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked)
|
||||
return;
|
||||
}
|
||||
|
||||
QString startPath;
|
||||
if (!proj->fileName().isEmpty())
|
||||
{
|
||||
QFileInfo fi(proj->fileName());
|
||||
startPath = fi.absolutePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
startPath = app->lastUsedDialogDirectory("IMAGE_SNAPSHOT");
|
||||
}
|
||||
|
||||
startPath = caf::Utils::constructFullFileName(startPath, RicSnapshotFilenameGenerator::generateSnapshotFileName(viewWindow), ".png");
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(NULL, tr("Export to File"), startPath);
|
||||
if (fileName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remember the directory to next time
|
||||
app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath());
|
||||
|
||||
RicSnapshotViewToFileFeature::saveSnapshotAs(fileName, viewWindow);
|
||||
QImage image = viewWindow->snapshotWindowContent();
|
||||
saveToFile(image, RicSnapshotFilenameGenerator::generateSnapshotFileName(viewWindow));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -120,6 +154,6 @@ void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicSnapshotViewToFileFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setText("Snapshot To File");
|
||||
actionToSetup->setIcon(QIcon(":/SnapShotSave.png"));
|
||||
actionToSetup->setText(text());
|
||||
actionToSetup->setIcon(icon());
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "cafCmdFeature.h"
|
||||
|
||||
class RimViewWindow;
|
||||
class QImage;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@ -31,6 +32,10 @@ class RicSnapshotViewToFileFeature : public caf::CmdFeature
|
||||
|
||||
public:
|
||||
static void saveSnapshotAs(const QString& fileName, RimViewWindow* viewWindow);
|
||||
static void saveSnapshotAs(const QString& fileName, const QImage& image);
|
||||
static void saveToFile(const QImage& image, const QString& defaultFileBaseName = "image");
|
||||
static QIcon icon();
|
||||
static QString text();
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
|
@ -17,6 +17,9 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicGridStatisticsDialog.h"
|
||||
#include "ExportCommands/RicSnapshotViewToClipboardFeature.h"
|
||||
#include "ExportCommands/RicSnapshotViewToFileFeature.h"
|
||||
#include "ExportCommands/RicSnapshotFilenameGenerator.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
@ -27,19 +30,20 @@
|
||||
#include "RiuSummaryQwtPlot.h"
|
||||
#include "RiuTools.h"
|
||||
|
||||
#include "qwt_scale_draw.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QPushButton>
|
||||
#include <QToolBar>
|
||||
#include <QAction>
|
||||
#include <qwt_plot.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_plot_histogram.h>
|
||||
#include <qwt_plot_marker.h>
|
||||
#include <qwt_series_data.h>
|
||||
#include <qwt_symbol.h>
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <qwt_scale_draw.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -49,14 +53,18 @@
|
||||
RicGridStatisticsDialog::RicGridStatisticsDialog(QWidget* parent)
|
||||
: QDialog(parent, RiuTools::defaultDialogFlags())
|
||||
{
|
||||
m_currentRimView = nullptr;
|
||||
|
||||
// Create widgets
|
||||
m_toolBar = new QToolBar();
|
||||
m_mainViewWidget = new QFrame();
|
||||
m_label = new QLabel();
|
||||
m_textEdit = new QTextEdit();
|
||||
m_historgramPlot = new QwtPlot();
|
||||
m_aggregatedPlot = new QwtPlot();
|
||||
m_buttons = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||
|
||||
// Connect to signal
|
||||
// Connect to close button signal
|
||||
connect(m_buttons, SIGNAL(rejected()), this, SLOT(slotDialogFinished()));
|
||||
|
||||
// Set widget properties
|
||||
@ -65,19 +73,29 @@ RicGridStatisticsDialog::RicGridStatisticsDialog(QWidget* parent)
|
||||
RiuSummaryQwtPlot::setCommonPlotBehaviour(m_aggregatedPlot);
|
||||
|
||||
// Define layout
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
layout->addWidget(m_label);
|
||||
layout->addWidget(m_textEdit);
|
||||
QVBoxLayout* dialogLayout = new QVBoxLayout();
|
||||
dialogLayout->addWidget(m_mainViewWidget);
|
||||
|
||||
QVBoxLayout* mainViewLayout = new QVBoxLayout();
|
||||
mainViewLayout->setMargin(0);
|
||||
m_mainViewWidget->setLayout(mainViewLayout);
|
||||
mainViewLayout->addWidget(m_label);
|
||||
mainViewLayout->addWidget(m_textEdit);
|
||||
|
||||
QVBoxLayout* plotLayout = new QVBoxLayout();
|
||||
plotLayout->setSpacing(0);
|
||||
//plotLayout->addStretch();
|
||||
plotLayout->addWidget(m_historgramPlot);
|
||||
plotLayout->addWidget(m_aggregatedPlot);
|
||||
layout->addLayout(plotLayout);
|
||||
mainViewLayout->addLayout(plotLayout);
|
||||
|
||||
layout->addWidget(m_buttons);
|
||||
setLayout(layout);
|
||||
dialogLayout->addLayout(mainViewLayout);
|
||||
dialogLayout->addWidget(m_buttons);
|
||||
|
||||
setLayout(dialogLayout);
|
||||
|
||||
// Toolbar
|
||||
dialogLayout->setMenuBar(m_toolBar);
|
||||
createAndConnectToolbarActions();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -95,6 +113,16 @@ void RicGridStatisticsDialog::setLabel(const QString& labelText)
|
||||
m_label->setText(labelText);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicGridStatisticsDialog::setCurrentRimView(RimView* rimView)
|
||||
{
|
||||
m_currentRimView = rimView;
|
||||
setInfoText(m_currentRimView);
|
||||
setHistogramData(m_currentRimView);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -178,6 +206,18 @@ void RicGridStatisticsDialog::setHistogramData(RimView* view)
|
||||
m_aggregatedPlot->replot();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicGridStatisticsDialog::createAndConnectToolbarActions()
|
||||
{
|
||||
QAction* scrShotToClipboardAction = m_toolBar->addAction(RicSnapshotViewToClipboardFeature::icon(), RicSnapshotViewToClipboardFeature::text());
|
||||
connect(scrShotToClipboardAction, SIGNAL(triggered()), this, SLOT(screenShotToClipboard()));
|
||||
|
||||
QAction* scrShotToFileAction = m_toolBar->addAction(RicSnapshotViewToFileFeature::icon(), RicSnapshotViewToFileFeature::text());
|
||||
connect(scrShotToFileAction, SIGNAL(triggered()), this, SLOT(screenShotToFile()));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -252,3 +292,31 @@ void RicGridStatisticsDialog::slotDialogFinished()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicGridStatisticsDialog::screenShotToClipboard()
|
||||
{
|
||||
QPixmap shot = QPixmap::grabWidget(m_mainViewWidget, m_mainViewWidget->rect());
|
||||
RicSnapshotViewToClipboardFeature::copyToClipboard(shot.toImage());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicGridStatisticsDialog::screenShotToFile()
|
||||
{
|
||||
QPixmap shot = QPixmap::grabWidget(m_mainViewWidget, m_mainViewWidget->rect());
|
||||
QString defaultFileBaseName;
|
||||
if (m_currentRimView)
|
||||
{
|
||||
defaultFileBaseName = RicSnapshotFilenameGenerator::generateSnapshotFileName(m_currentRimView);
|
||||
defaultFileBaseName += "_Statistics";
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultFileBaseName = "Snapshot_Statistics";
|
||||
}
|
||||
RicSnapshotViewToFileFeature::saveToFile(shot.toImage(), defaultFileBaseName);
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "Rim3dOverlayInfoConfig.h"
|
||||
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QLabel;
|
||||
@ -27,6 +29,8 @@ class QTextEdit;
|
||||
class QDialogButtonBox;
|
||||
class QwtPlot;
|
||||
class QwtPlotMarker;
|
||||
class QMainWindow;
|
||||
class QToolBar;
|
||||
class RimEclipseView;
|
||||
|
||||
//==================================================================================================
|
||||
@ -42,10 +46,14 @@ public:
|
||||
~RicGridStatisticsDialog();
|
||||
|
||||
void setLabel(const QString& labelText);
|
||||
void setCurrentRimView(RimView* rimView);
|
||||
|
||||
private:
|
||||
void setInfoText(RimView* eclipseView);
|
||||
void setHistogramData(RimView* eclipseView);
|
||||
|
||||
private:
|
||||
void createAndConnectToolbarActions();
|
||||
void deletePlotItems(QwtPlot* plot);
|
||||
static void setMarkers(const Rim3dOverlayInfoConfig::HistogramData& histData, QwtPlot* plot);
|
||||
static QwtPlotMarker* createVerticalPlotMarker(const QColor& color, double xValue);
|
||||
@ -53,11 +61,17 @@ private:
|
||||
|
||||
private slots:
|
||||
void slotDialogFinished();
|
||||
void screenShotToClipboard();
|
||||
void screenShotToFile();
|
||||
|
||||
private:
|
||||
QToolBar* m_toolBar;
|
||||
QWidget* m_mainViewWidget;
|
||||
QLabel* m_label;
|
||||
QTextEdit* m_textEdit;
|
||||
QwtPlot* m_historgramPlot;
|
||||
QwtPlot* m_aggregatedPlot;
|
||||
QDialogButtonBox* m_buttons;
|
||||
|
||||
caf::PdmPointer<RimView> m_currentRimView;
|
||||
};
|
||||
|
@ -613,8 +613,9 @@ void Rim3dOverlayInfoConfig::showStatisticsInfoDialog()
|
||||
m_gridStatisticsDialog->show();
|
||||
|
||||
m_gridStatisticsDialog->setLabel("Grid statistics");
|
||||
m_gridStatisticsDialog->setInfoText(m_viewDef);
|
||||
m_gridStatisticsDialog->setHistogramData(m_viewDef);
|
||||
m_gridStatisticsDialog->setCurrentRimView(m_viewDef);
|
||||
//m_gridStatisticsDialog->setInfoText(m_viewDef);
|
||||
//m_gridStatisticsDialog->setHistogramData(m_viewDef);
|
||||
|
||||
m_gridStatisticsDialog->raise();
|
||||
}
|
||||
@ -657,8 +658,9 @@ void Rim3dOverlayInfoConfig::update3DInfo()
|
||||
updateEclipse3DInfo(reservoirView);
|
||||
|
||||
// Update statistics dialog
|
||||
m_gridStatisticsDialog->setInfoText(reservoirView);
|
||||
m_gridStatisticsDialog->setHistogramData(reservoirView);
|
||||
m_gridStatisticsDialog->setCurrentRimView(reservoirView);
|
||||
//m_gridStatisticsDialog->setInfoText(reservoirView);
|
||||
//m_gridStatisticsDialog->setHistogramData(reservoirView);
|
||||
}
|
||||
|
||||
RimGeoMechView * geoMechView = dynamic_cast<RimGeoMechView*>(m_viewDef.p());
|
||||
@ -669,8 +671,9 @@ void Rim3dOverlayInfoConfig::update3DInfo()
|
||||
updateGeoMech3DInfo(geoMechView);
|
||||
|
||||
// Update statistics dialog
|
||||
m_gridStatisticsDialog->setInfoText(geoMechView);
|
||||
m_gridStatisticsDialog->setHistogramData(geoMechView);
|
||||
m_gridStatisticsDialog->setCurrentRimView(geoMechView);
|
||||
//m_gridStatisticsDialog->setInfoText(geoMechView);
|
||||
//m_gridStatisticsDialog->setHistogramData(geoMechView);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user