#2167 statistics dialog. Screen dump to clipboard or file

This commit is contained in:
Bjørn Erik Jensen
2017-11-29 11:45:01 +01:00
parent c0615134a9
commit f8256a30b8
7 changed files with 217 additions and 58 deletions

View File

@@ -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());
}

View File

@@ -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;

View File

@@ -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());
}

View File

@@ -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