mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3087 Show plot data. Display tabbed dialog for summary data
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// 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.
|
||||
//
|
||||
@@ -19,13 +20,16 @@
|
||||
#include "RiuTextDialog.h"
|
||||
#include "RiuTools.h"
|
||||
|
||||
#include "RiaQDateTimeTools.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QBoxLayout>
|
||||
#include <QClipboard>
|
||||
#include <QMenu>
|
||||
#include <QTabWidget>
|
||||
|
||||
|
||||
#include <cvfAssert.h>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -156,3 +160,124 @@ void RiuTextDialog::contextMenuEvent(QContextMenuEvent* event)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuShowTabbedPlotDataDialog::RiuShowTabbedPlotDataDialog(QWidget* parent /*= nullptr*/)
|
||||
: QDialog(parent, RiuTools::defaultDialogFlags())
|
||||
{
|
||||
m_tabWidget = new QTabWidget(this);
|
||||
|
||||
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabChanged(int)));
|
||||
|
||||
for(auto timePeriod : RiaQDateTimeTools::dateTimePeriods())
|
||||
{
|
||||
QString tabTitle =
|
||||
timePeriod == DateTimePeriod::NONE ? "No Resampling" :
|
||||
QString("Plot Data, %1").arg(RiaQDateTimeTools::dateTimePeriodName(timePeriod));
|
||||
|
||||
RiuQPlainTextEdit* textEdit = new RiuQPlainTextEdit();
|
||||
textEdit->setReadOnly(true);
|
||||
textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
|
||||
|
||||
QFont font("Courier", 8);
|
||||
textEdit->setFont(font);
|
||||
textEdit->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
|
||||
m_tabWidget->addTab(textEdit, tabTitle);
|
||||
}
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
layout->addWidget(m_tabWidget);
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuShowTabbedPlotDataDialog::setTextProvider(std::function<QString(DateTimePeriod)> textProvider)
|
||||
{
|
||||
m_textProvider = textProvider;
|
||||
|
||||
updateText();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuQPlainTextEdit * RiuShowTabbedPlotDataDialog::currentTextEdit() const
|
||||
{
|
||||
return dynamic_cast<RiuQPlainTextEdit*>(m_tabWidget->currentWidget());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
DateTimePeriod RiuShowTabbedPlotDataDialog::indexToPeriod(int index)
|
||||
{
|
||||
auto currTabTitle = m_tabWidget->tabText(index);
|
||||
if (currTabTitle.contains(RiaQDateTimeTools::TIMESPAN_DAY_NAME)) return DateTimePeriod::DAY;
|
||||
if (currTabTitle.contains(RiaQDateTimeTools::TIMESPAN_WEEK_NAME)) return DateTimePeriod::WEEK;
|
||||
if (currTabTitle.contains(RiaQDateTimeTools::TIMESPAN_MONTH_NAME)) return DateTimePeriod::MONTH;
|
||||
if (currTabTitle.contains(RiaQDateTimeTools::TIMESPAN_QUARTER_NAME)) return DateTimePeriod::QUARTER;
|
||||
if (currTabTitle.contains(RiaQDateTimeTools::TIMESPAN_HALFYEAR_NAME)) return DateTimePeriod::HALFYEAR;
|
||||
if (currTabTitle.contains(RiaQDateTimeTools::TIMESPAN_YEAR_NAME)) return DateTimePeriod::YEAR;
|
||||
if (currTabTitle.contains(RiaQDateTimeTools::TIMESPAN_DECADE_NAME)) return DateTimePeriod::DECADE;
|
||||
return DateTimePeriod::NONE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuShowTabbedPlotDataDialog::updateText()
|
||||
{
|
||||
auto textEdit = currentTextEdit();
|
||||
auto currIndex = m_tabWidget->currentIndex();
|
||||
if (textEdit && textEdit->toPlainText().isEmpty() && m_textProvider)
|
||||
{
|
||||
textEdit->setPlainText(m_textProvider(indexToPeriod(currIndex)));
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuShowTabbedPlotDataDialog::slotTabChanged(int index)
|
||||
{
|
||||
updateText();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuShowTabbedPlotDataDialog::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
QMenu menu;
|
||||
RiuQPlainTextEdit* textEdit = dynamic_cast<RiuQPlainTextEdit*>(m_tabWidget->currentWidget());
|
||||
|
||||
{
|
||||
|
||||
QAction* actionToSetup = new QAction(this);
|
||||
|
||||
actionToSetup->setText("Copy");
|
||||
actionToSetup->setIcon(QIcon(":/Copy.png"));
|
||||
actionToSetup->setShortcuts(QKeySequence::Copy);
|
||||
|
||||
connect(actionToSetup, SIGNAL(triggered()), textEdit, SLOT(slotCopyContentToClipboard()));
|
||||
|
||||
menu.addAction(actionToSetup);
|
||||
}
|
||||
|
||||
{
|
||||
QAction* actionToSetup = new QAction(this);
|
||||
|
||||
actionToSetup->setText("Select All");
|
||||
actionToSetup->setShortcuts(QKeySequence::SelectAll);
|
||||
|
||||
connect(actionToSetup, SIGNAL(triggered()), textEdit, SLOT(slotSelectAll()));
|
||||
|
||||
menu.addAction(actionToSetup);
|
||||
}
|
||||
|
||||
menu.exec(event->globalPos());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user