mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1319 Make sure clipboard text from plot data widget can be pasted into columns in Excel
This commit is contained in:
parent
4b7b11e45b
commit
be3ed0d934
@ -29,7 +29,9 @@
|
||||
|
||||
#include <QAction>
|
||||
#include <QBoxLayout>
|
||||
#include <QTextEdit>
|
||||
#include <QClipboard>
|
||||
#include <QMenu>
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicShowPlotDataFeature, "RicShowPlotDataFeature");
|
||||
|
||||
@ -111,7 +113,7 @@ void RicShowPlotDataFeature::showTextWindow(const QString& title, const QString&
|
||||
textWiget->setMinimumSize(400, 600);
|
||||
|
||||
textWiget->setWindowTitle(title);
|
||||
textWiget->showText(text);
|
||||
textWiget->setText(text);
|
||||
|
||||
textWiget->show();
|
||||
|
||||
@ -132,13 +134,15 @@ void RicShowPlotDataFeature::showTextWindow(const QString& title, const QString&
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicTextWidget::RicTextWidget(QWidget* parent) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
|
||||
{
|
||||
m_textEdit = new QTextEdit(this);
|
||||
m_textEdit = new QPlainTextEdit(this);
|
||||
m_textEdit->setReadOnly(true);
|
||||
m_textEdit->setLineWrapMode(QTextEdit::NoWrap);
|
||||
m_textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
|
||||
|
||||
QFont font("Courier", 8);
|
||||
m_textEdit->setFont(font);
|
||||
|
||||
m_textEdit->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
layout->addWidget(m_textEdit);
|
||||
setLayout(layout);
|
||||
@ -147,8 +151,82 @@ RicTextWidget::RicTextWidget(QWidget* parent) : QDialog(parent, Qt::WindowTitleH
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicTextWidget::showText(const QString& text)
|
||||
void RicTextWidget::setText(const QString& text)
|
||||
{
|
||||
m_textEdit->setText(text);
|
||||
m_textEdit->setPlainText(text);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicTextWidget::slotCopyContentToClipboard()
|
||||
{
|
||||
QTextCursor cursor(m_textEdit->textCursor());
|
||||
|
||||
QString textForClipboard;
|
||||
|
||||
QString selText = cursor.selectedText();
|
||||
if (!selText.isEmpty())
|
||||
{
|
||||
QTextDocument doc;
|
||||
doc.setPlainText(selText);
|
||||
|
||||
textForClipboard = doc.toPlainText();
|
||||
}
|
||||
|
||||
if (textForClipboard.isEmpty())
|
||||
{
|
||||
textForClipboard = m_textEdit->toPlainText();
|
||||
}
|
||||
|
||||
if (!textForClipboard.isEmpty())
|
||||
{
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
if (clipboard)
|
||||
{
|
||||
clipboard->setText(textForClipboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicTextWidget::slotSelectAll()
|
||||
{
|
||||
m_textEdit->selectAll();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicTextWidget::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
QMenu menu;
|
||||
|
||||
{
|
||||
QAction* actionToSetup = new QAction(this);
|
||||
|
||||
actionToSetup->setText("Copy");
|
||||
actionToSetup->setIcon(QIcon(":/Copy.png"));
|
||||
actionToSetup->setShortcuts(QKeySequence::Copy);
|
||||
|
||||
connect(actionToSetup, SIGNAL(triggered()), this, SLOT(slotCopyContentToClipboard()));
|
||||
|
||||
menu.addAction(actionToSetup);
|
||||
}
|
||||
|
||||
{
|
||||
QAction* actionToSetup = new QAction(this);
|
||||
|
||||
actionToSetup->setText("Select All");
|
||||
actionToSetup->setShortcuts(QKeySequence::SelectAll);
|
||||
|
||||
connect(actionToSetup, SIGNAL(triggered()), this, SLOT(slotSelectAll()));
|
||||
|
||||
menu.addAction(actionToSetup);
|
||||
}
|
||||
|
||||
menu.exec(event->globalPos());
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QTextEdit;
|
||||
class QPlainTextEdit;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -34,10 +34,17 @@ class RicTextWidget : public QDialog
|
||||
public:
|
||||
explicit RicTextWidget(QWidget* parent = 0);
|
||||
|
||||
void showText(const QString& text);
|
||||
void setText(const QString& text);
|
||||
|
||||
private slots:
|
||||
void slotCopyContentToClipboard();
|
||||
void slotSelectAll();
|
||||
|
||||
private:
|
||||
QTextEdit* m_textEdit;
|
||||
QPlainTextEdit* m_textEdit;
|
||||
protected:
|
||||
virtual void contextMenuEvent(QContextMenuEvent *) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user