From f8256a30b877d281cc70bfbf78eed2b1eec35699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Jensen?= Date: Wed, 29 Nov 2017 11:45:01 +0100 Subject: [PATCH] #2167 statistics dialog. Screen dump to clipboard or file --- .../RicSnapshotViewToClipboardFeature.cpp | 33 +++++- .../RicSnapshotViewToClipboardFeature.h | 6 + .../RicSnapshotViewToFileFeature.cpp | 104 ++++++++++++------ .../RicSnapshotViewToFileFeature.h | 5 + .../Commands/RicGridStatisticsDialog.cpp | 98 ++++++++++++++--- .../Commands/RicGridStatisticsDialog.h | 14 +++ .../Rim3dOverlayInfoConfig.cpp | 15 ++- 7 files changed, 217 insertions(+), 58 deletions(-) diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.cpp index bcccfbd273..7678fc5f71 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.cpp +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.cpp @@ -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()); } diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.h b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.h index f07092a77e..5a125e2675 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.h +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToClipboardFeature.h @@ -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; diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp index 1591dd0af3..86cd089a76 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.cpp @@ -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()); } diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.h b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.h index ae83718d21..afead616b0 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.h +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotViewToFileFeature.h @@ -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 diff --git a/ApplicationCode/Commands/RicGridStatisticsDialog.cpp b/ApplicationCode/Commands/RicGridStatisticsDialog.cpp index 716ec1a699..3a39587f74 100644 --- a/ApplicationCode/Commands/RicGridStatisticsDialog.cpp +++ b/ApplicationCode/Commands/RicGridStatisticsDialog.cpp @@ -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 +#include +#include +#include +#include +#include +#include #include #include #include #include #include #include - -#include -#include -#include -#include -#include +#include #include @@ -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); +} diff --git a/ApplicationCode/Commands/RicGridStatisticsDialog.h b/ApplicationCode/Commands/RicGridStatisticsDialog.h index a0e01a5879..3cba72e02c 100644 --- a/ApplicationCode/Commands/RicGridStatisticsDialog.h +++ b/ApplicationCode/Commands/RicGridStatisticsDialog.h @@ -20,6 +20,8 @@ #include "Rim3dOverlayInfoConfig.h" +#include "cafPdmPointer.h" + #include 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 m_currentRimView; }; diff --git a/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp b/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp index 801fe93110..d7562a96e7 100644 --- a/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp +++ b/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp @@ -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(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); } }