From 10edf44ee371267e8f81102f388b0116d70619bb Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 15 Mar 2017 20:15:04 +0100 Subject: [PATCH] #1293 Show plot data in text widget --- .../CMakeLists_files.cmake | 10 +- .../RicShowPlotDataFeature.cpp | 154 ++++++++++++++++++ .../RicShowPlotDataFeature.h | 61 +++++++ .../RimContextCommandBuilder.cpp | 1 + .../UserInterface/RiuMainPlotWindow.cpp | 20 +++ .../UserInterface/RiuMainPlotWindow.h | 4 + 6 files changed, 246 insertions(+), 4 deletions(-) create mode 100644 ApplicationCode/Commands/ApplicationCommands/RicShowPlotDataFeature.cpp create mode 100644 ApplicationCode/Commands/ApplicationCommands/RicShowPlotDataFeature.h diff --git a/ApplicationCode/Commands/ApplicationCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/ApplicationCommands/CMakeLists_files.cmake index c93e9cf97b..858000503d 100644 --- a/ApplicationCode/Commands/ApplicationCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/ApplicationCommands/CMakeLists_files.cmake @@ -17,6 +17,7 @@ ${CEE_CURRENT_LIST_DIR}RicExitApplicationFeature.h ${CEE_CURRENT_LIST_DIR}RicCloseProjectFeature.h ${CEE_CURRENT_LIST_DIR}RicHelpFeatures.h ${CEE_CURRENT_LIST_DIR}RicEditPreferencesFeature.h +${CEE_CURRENT_LIST_DIR}RicShowPlotDataFeature.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -32,6 +33,7 @@ ${CEE_CURRENT_LIST_DIR}RicExitApplicationFeature.cpp ${CEE_CURRENT_LIST_DIR}RicCloseProjectFeature.cpp ${CEE_CURRENT_LIST_DIR}RicHelpFeatures.cpp ${CEE_CURRENT_LIST_DIR}RicEditPreferencesFeature.cpp +${CEE_CURRENT_LIST_DIR}RicShowPlotDataFeature.cpp ) list(APPEND CODE_HEADER_FILES @@ -42,10 +44,10 @@ list(APPEND CODE_SOURCE_FILES ${SOURCE_GROUP_SOURCE_FILES} ) -#set (QT_MOC_HEADERS -#${QT_MOC_HEADERS} -#${CEE_CURRENT_LIST_DIR}RicBoxManipulatorEventHandler.h -#) +set (QT_MOC_HEADERS +${QT_MOC_HEADERS} +${CEE_CURRENT_LIST_DIR}RicShowPlotDataFeature.h +) source_group( "CommandFeature\\Application" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CEE_CURRENT_LIST_DIR}CMakeLists_files.cmake ) diff --git a/ApplicationCode/Commands/ApplicationCommands/RicShowPlotDataFeature.cpp b/ApplicationCode/Commands/ApplicationCommands/RicShowPlotDataFeature.cpp new file mode 100644 index 0000000000..6af86ae9c2 --- /dev/null +++ b/ApplicationCode/Commands/ApplicationCommands/RicShowPlotDataFeature.cpp @@ -0,0 +1,154 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017 Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicShowPlotDataFeature.h" + +#include "RiaApplication.h" + +#include "RimSummaryPlot.h" +#include "RimWellLogPlot.h" + +#include "RiuMainPlotWindow.h" + +#include "cafSelectionManager.h" + +#include +#include +#include + +CAF_CMD_SOURCE_INIT(RicShowPlotDataFeature, "RicShowPlotDataFeature"); + + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicShowPlotDataFeature::isCommandEnabled() +{ + std::vector selectedSummaryPlots; + caf::SelectionManager::instance()->objectsByType(&selectedSummaryPlots); + + std::vector wellLogPlots; + caf::SelectionManager::instance()->objectsByType(&wellLogPlots); + + if (selectedSummaryPlots.size() > 0 || wellLogPlots.size() > 0) + { + return true; + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicShowPlotDataFeature::onActionTriggered(bool isChecked) +{ + std::vector selectedSummaryPlots; + caf::SelectionManager::instance()->objectsByType(&selectedSummaryPlots); + + std::vector wellLogPlots; + caf::SelectionManager::instance()->objectsByType(&wellLogPlots); + + if (selectedSummaryPlots.size() == 0 && wellLogPlots.size() == 0) + { + CVF_ASSERT(false); + + return; + } + + RiuMainPlotWindow* plotwindow = RiaApplication::instance()->mainPlotWindow(); + CVF_ASSERT(plotwindow); + + for (RimSummaryPlot* summaryPlot : selectedSummaryPlots) + { + QString title = summaryPlot->description(); + QString text = summaryPlot->asciiDataForPlotExport(); + + RicShowPlotDataFeature::showTextWindow(title, text); + } + + for (RimWellLogPlot* wellLogPlot : wellLogPlots) + { + QString title = wellLogPlot->description(); + QString text = wellLogPlot->asciiDataForPlotExport(); + + RicShowPlotDataFeature::showTextWindow(title, text); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicShowPlotDataFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Show Plot Data"); + actionToSetup->setIcon(QIcon(":/PlotWindow24x24.png")); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicShowPlotDataFeature::showTextWindow(const QString& title, const QString& text) +{ + RiuMainPlotWindow* plotwindow = RiaApplication::instance()->mainPlotWindow(); + CVF_ASSERT(plotwindow); + + RicTextWidget* textWiget = new RicTextWidget(plotwindow); + textWiget->setMinimumSize(400, 600); + + textWiget->setWindowTitle(title); + textWiget->showText(text); + + textWiget->show(); + + plotwindow->addToTemporaryWidgets(textWiget); +} + + + + + + + + + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicTextWidget::RicTextWidget(QWidget* parent) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint) +{ + m_textEdit = new QTextEdit(this); + m_textEdit->setReadOnly(true); + m_textEdit->setLineWrapMode(QTextEdit::NoWrap); + + QVBoxLayout* layout = new QVBoxLayout(); + layout->addWidget(m_textEdit); + setLayout(layout); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicTextWidget::showText(const QString& text) +{ + m_textEdit->setText(text); +} + diff --git a/ApplicationCode/Commands/ApplicationCommands/RicShowPlotDataFeature.h b/ApplicationCode/Commands/ApplicationCommands/RicShowPlotDataFeature.h new file mode 100644 index 0000000000..0eca6e3ed2 --- /dev/null +++ b/ApplicationCode/Commands/ApplicationCommands/RicShowPlotDataFeature.h @@ -0,0 +1,61 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017 Statoil ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +#include + +class QTextEdit; + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +class RicTextWidget : public QDialog +{ + Q_OBJECT + +public: + explicit RicTextWidget(QWidget* parent = 0); + + void showText(const QString& text); + +private: + QTextEdit* m_textEdit; +}; + + +//================================================================================================== +/// +//================================================================================================== +class RicShowPlotDataFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + // Overrides + virtual bool isCommandEnabled(); + virtual void onActionTriggered( bool isChecked ); + virtual void setupActionLook( QAction* actionToSetup ); + +private: + static void showTextWindow(const QString& title, const QString& text); +}; + + diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index caf3bd484d..cdc6d8a4b9 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -381,6 +381,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection() // without using dyncamic_cast. commandIds << "RicCopyReferencesToClipboardFeature"; + commandIds << "RicShowPlotDataFeature"; // Work in progress -- End diff --git a/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp b/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp index 6ceb6c0ee9..9ebb8ba996 100644 --- a/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp @@ -114,6 +114,16 @@ void RiuMainPlotWindow::cleanupGuiBeforeProjectClose() { m_pdmUiPropertyView->showProperties(NULL); } + + for (QWidget* w : m_temporaryWidgets) + { + w->close(); + w->deleteLater(); + } + + m_temporaryWidgets.clear(); + + setWindowTitle("Plots - ResInsight"); } //-------------------------------------------------------------------------------------------------- @@ -367,6 +377,16 @@ QList RiuMainPlotWindow::subWindowList(QMdiArea::WindowOrder ord return m_mdiArea->subWindowList(order); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMainPlotWindow::addToTemporaryWidgets(QWidget* widget) +{ + CVF_ASSERT(widget); + + m_temporaryWidgets.push_back(widget); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuMainPlotWindow.h b/ApplicationCode/UserInterface/RiuMainPlotWindow.h index 2b7bf10bc6..9df6833c37 100644 --- a/ApplicationCode/UserInterface/RiuMainPlotWindow.h +++ b/ApplicationCode/UserInterface/RiuMainPlotWindow.h @@ -79,6 +79,8 @@ public: QMdiSubWindow* findMdiSubWindow(QWidget* viewer); QList subWindowList(QMdiArea::WindowOrder order); + void addToTemporaryWidgets(QWidget* widget); + protected: virtual void closeEvent(QCloseEvent* event); @@ -124,4 +126,6 @@ private: caf::PdmUiPropertyView* m_pdmUiPropertyView; bool m_blockSlotSubWindowActivated; + + std::vector m_temporaryWidgets; };