#3087 Show plot data. Add context menu: export to file

This commit is contained in:
Bjørn Erik Jensen 2018-07-02 14:29:46 +02:00
parent a949f2acec
commit 02059debf9
5 changed files with 104 additions and 17 deletions

View File

@ -131,6 +131,7 @@ void RicShowPlotDataFeature::showTabbedTextWindow(const QString& title, std::fun
textWiget->setMinimumSize(800, 600);
textWiget->setWindowTitle(title);
textWiget->setDescription(title);
textWiget->setTextProvider(textProvider);
textWiget->show();

View File

@ -59,15 +59,9 @@ void RicAsciiExportSummaryPlotFeature::onActionTriggered(bool isChecked)
{
this->disableModelChangeContribution();
RiaApplication* app = RiaApplication::instance();
QString projectFolder = app->currentProjectPath();
RimProject* project = RiaApplication::instance()->project();
CVF_ASSERT(project);
std::vector<RimSummaryPlot*> selectedSummaryPlots;
caf::SelectionManager::instance()->objectsByType(&selectedSummaryPlots);
QString defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallback("PLOT_ASCIIEXPORT_DIR", projectFolder);
QString defaultDir = defaultExportDir();
// Ask user about resampling
auto result = RicResampleDialog::openDialog();
@ -76,8 +70,7 @@ void RicAsciiExportSummaryPlotFeature::onActionTriggered(bool isChecked)
if (selectedSummaryPlots.size() == 1)
{
RimSummaryPlot* summaryPlot = selectedSummaryPlots.at(0);
QString defaultFileName = defaultDir + "/" + caf::Utils::makeValidFileBasename((summaryPlot->description())) + ".ascii";
QString fileName = QFileDialog::getSaveFileName(nullptr, "Select File for Summary Plot Export", defaultFileName, "Text File(*.ascii);;All files(*.*)");
QString fileName = getFileNameFromUserDialog(summaryPlot->description(), defaultDir);
if (fileName.isEmpty()) return;
caf::ProgressInfo pi(selectedSummaryPlots.size(), QString("Exporting plot data to ASCII"));
@ -127,9 +120,27 @@ void RicAsciiExportSummaryPlotFeature::setupActionLook(QAction* actionToSetup)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicAsciiExportSummaryPlotFeature::exportAsciiForSummaryPlot(const QString& fileName,
const RimSummaryPlot* summaryPlot,
DateTimePeriod resamplingPeriod)
QString RicAsciiExportSummaryPlotFeature::defaultExportDir()
{
RiaApplication* app = RiaApplication::instance();
QString projectFolder = app->currentProjectPath();
return RiaApplication::instance()->lastUsedDialogDirectoryWithFallback("PLOT_ASCIIEXPORT_DIR", projectFolder);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicAsciiExportSummaryPlotFeature::getFileNameFromUserDialog(const QString& fileNameCandidate, const QString& defaultDir)
{
QString defaultFileName = defaultDir + "/" + caf::Utils::makeValidFileBasename(fileNameCandidate) + ".ascii";
QString fileName = QFileDialog::getSaveFileName(nullptr, "Select File for Summary Plot Export", defaultFileName, "Text File(*.ascii);;All files(*.*)");
return fileName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicAsciiExportSummaryPlotFeature::exportTextToFile(const QString& fileName, const QString& text)
{
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
@ -140,13 +151,25 @@ bool RicAsciiExportSummaryPlotFeature::exportAsciiForSummaryPlot(const QString&
RiaLogging::info(QString("Writing values for summary plot(s) to file: %1").arg(fileName));
QTextStream out(&file);
out << summaryPlot->description();
out << summaryPlot->asciiDataForPlotExport(resamplingPeriod);
out << "\n\n";
out << text;
RiaLogging::info(QString("Competed writing values for summary plot(s) to file %1").arg(fileName));
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicAsciiExportSummaryPlotFeature::exportAsciiForSummaryPlot(const QString& fileName,
const RimSummaryPlot* summaryPlot,
DateTimePeriod resamplingPeriod)
{
QString text = summaryPlot->description();
text.append(summaryPlot->asciiDataForPlotExport(resamplingPeriod));
text.append("\n\n");
return exportTextToFile(fileName, text);
}

View File

@ -31,6 +31,11 @@ class RicAsciiExportSummaryPlotFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
public:
static QString defaultExportDir();
static QString getFileNameFromUserDialog(const QString& fileNameCandidate, const QString& defaultDir);
static bool exportTextToFile(const QString& fileName, const QString& text);
protected:
virtual bool isCommandEnabled() override;
virtual void onActionTriggered( bool isChecked ) override;

View File

@ -20,8 +20,11 @@
#include "RiuTextDialog.h"
#include "RiuTools.h"
#include "RiaApplication.h"
#include "RiaQDateTimeTools.h"
#include "SummaryPlotCommands/RicAsciiExportSummaryPlotFeature.h"
#include <QAction>
#include <QApplication>
#include <QBoxLayout>
@ -92,6 +95,30 @@ void RiuQPlainTextEdit::slotSelectAll()
this->selectAll();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQPlainTextEdit::slotExportToFile()
{
// Get dialog
RiuShowTabbedPlotDataDialog* dialog = nullptr;
auto curr = parent();
while (dialog == nullptr)
{
if (!curr) break;
dialog = dynamic_cast<RiuShowTabbedPlotDataDialog*>(curr);
if (dialog) break;
curr = curr->parent();
}
if(dialog)
{
QString defaultDir = RicAsciiExportSummaryPlotFeature::defaultExportDir();
auto fileName = RicAsciiExportSummaryPlotFeature::getFileNameFromUserDialog(dialog->description(), defaultDir);
RicAsciiExportSummaryPlotFeature::exportTextToFile(fileName, this->toPlainText());
}
}
//--------------------------------------------------------------------------------------------------
///
///
@ -192,6 +219,23 @@ RiuShowTabbedPlotDataDialog::RiuShowTabbedPlotDataDialog(QWidget* parent /*= nul
setLayout(layout);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuShowTabbedPlotDataDialog::setDescription(const QString& description)
{
m_description = description;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuShowTabbedPlotDataDialog::description() const
{
if (m_description.isEmpty()) return "Plot Data";
return m_description;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -279,5 +323,16 @@ void RiuShowTabbedPlotDataDialog::contextMenuEvent(QContextMenuEvent* event)
menu.addAction(actionToSetup);
}
{
QAction* actionToSetup = new QAction(this);
actionToSetup->setText("Export to File...");
//actionToSetup->setShortcuts(QKeySequence::);
connect(actionToSetup, SIGNAL(triggered()), textEdit, SLOT(slotExportToFile()));
menu.addAction(actionToSetup);
}
menu.exec(event->globalPos());
}

View File

@ -44,7 +44,7 @@ protected:
private slots:
void slotCopyContentToClipboard();
void slotSelectAll();
void slotExportToFile();
};
@ -77,6 +77,8 @@ class RiuShowTabbedPlotDataDialog : public QDialog
public:
explicit RiuShowTabbedPlotDataDialog(QWidget* parent = nullptr);
void setDescription(const QString& description);
QString description() const;
void setTextProvider(std::function<QString (DateTimePeriod)> textProvider);
private:
@ -85,6 +87,7 @@ private:
void updateText();
QTabWidget* m_tabWidget;
QString m_description;
std::function<QString(DateTimePeriod)> m_textProvider;
private slots: