Commit 8a5e1148 authored by Cory Quammen's avatar Cory Quammen

BUG 15158: Enable screen shots of Spreadsheet Views

Attempting to save a screen shot from a Spreadsheet View would
result in an error message after users went through the motions
of saving an image.

This change makes it possible to save the currently rendered
content of a Spreadsheet View as an image.

Limitations:
- magnification factor is ignored
- custom image size is ignored
- The spreadsheet view is not saved out when all views in a layout are saved
parent 2e22e465
Pipeline #17863 passed with stage
......@@ -4,6 +4,7 @@ vtk_module(pqCore
DEPENDS
pqWidgets
vtkGUISupportQt
vtkRenderingQt
PRIVATE_DEPENDS
vtkPVAnimation
vtkPVClientServerCoreDefault
......
......@@ -32,14 +32,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqSpreadSheetView.h"
// Server Manager Includes.
#include "vtkErrorCode.h"
#include "vtkEventQtSlotConnect.h"
#include "vtkImageData.h"
#include "vtkQImageToImageSource.h"
#include "vtkSMProperty.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMUtilities.h"
#include "vtkSMViewProxy.h"
// Qt Includes.
#include <QHeaderView>
#include <QPixmap>
#include <QPointer>
#include <QVBoxLayout>
......@@ -285,3 +290,43 @@ pqSpreadSheetViewModel* pqSpreadSheetView::getViewModel()
{
return this->Internal->Model;
}
//-----------------------------------------------------------------------------
vtkImageData* pqSpreadSheetView::captureImage(int vtkNotUsed(magnification))
{
QPixmap widgetPixmap = QPixmap::grabWidget(this->Internal->Table);
vtkSmartPointer<vtkQImageToImageSource> converter = vtkSmartPointer<vtkQImageToImageSource>::New();
QImage image = widgetPixmap.toImage();
converter->SetQImage(&image);
converter->Update();
vtkImageData* imageData = converter->GetOutput();
if (imageData)
{
vtkImageData* newImage = vtkImageData::New();
newImage->ShallowCopy(imageData);
return newImage;
}
return NULL;
}
//-----------------------------------------------------------------------------
vtkImageData* pqSpreadSheetView::captureImage(const QSize& vtkNotUsed(size))
{
return this->captureImage(1);
}
//-----------------------------------------------------------------------------
bool pqSpreadSheetView::writeImage(const QString& filename, const QSize& vtkNotUsed(s), int quality)
{
vtkImageData* img = this->captureImage(1);
if (img)
{
return vtkSMUtilities::SaveImage(img, filename.toLatin1().data(), quality) == vtkErrorCode::NoError;
}
return false;
}
......@@ -57,6 +57,19 @@ public:
/// Get the internal model for the view
pqSpreadSheetViewModel* getViewModel();
/// Override to capture an image of the spreadsheet. The captured image
/// ignores the magnification factor and produces an image with the same
/// size as the spreadsheet view.
virtual vtkImageData* captureImage(int magnification);
/// Override to capture an image of the spreadsheet. The captured image
/// ignores the given size and produces an image with the same
/// size as the spreadsheet view.
virtual vtkImageData* captureImage(const QSize& size);
/// Overridden to capture a spreadsheet image.
virtual bool writeImage(const QString& filename, const QSize&, int quality=-1);
signals:
/// Fired when the currently shown representation changes. \c repr may be
/// NULL.
......
......@@ -147,7 +147,7 @@ public:
virtual vtkImageData* captureImage(const QSize& size);
/// Capture an image and saves it out to a file.
bool writeImage(const QString& filename, const QSize&, int quality=-1);
virtual bool writeImage(const QString& filename, const QSize&, int quality=-1);
/// This method checks if the representation is shown in this view.
bool hasRepresentation(pqRepresentation* repr) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment