[kmplot] /: Copy root value or (x,y) pair to clipboard

Yuri Chornoivan null at kde.org
Mon Jan 14 17:30:25 GMT 2019


Git commit 4ec38cf969af48c824cd1fe58e6c5a64e200c79e by Yuri Chornoivan.
Committed on 14/01/2019 at 17:30.
Pushed by yurchor into branch 'master'.

Copy root value or (x,y) pair to clipboard

BUG: 308168
Differential Revision: https://phabricator.kde.org/D17403

M  +23   -1    doc/index.docbook
M  +25   -1    kmplot/maindlg.cpp
M  +3    -0    kmplot/maindlg.h
M  +10   -0    kmplot/view.cpp
M  +6    -0    kmplot/view.h

https://commits.kde.org/kmplot/4ec38cf969af48c824cd1fe58e6c5a64e200c79e

diff --git a/doc/index.docbook b/doc/index.docbook
index 13b7b4c..0af1f56 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -406,9 +406,31 @@ url="http://edu.kde.org/">http://edu.kde.org/</ulink></para></abstract>
 		</varlistentry>
 	</variablelist>
 
-	<para>Depending on the plot type, there will also be up to three tools available:</para>
+	<para>Depending on the plot type, there will also be up to five tools available:</para>
 
 	<variablelist>
+		<varlistentry>
+			<term><menuchoice><guimenuitem>Copy (x, y)</guimenuitem>
+				</menuchoice></term>
+			<listitem>
+				<para>Copies the current value on the plot to the system clipboard.
+					This tool can be useful for creating tables of function values outside of &kmplot;.
+				</para>
+			</listitem>
+		</varlistentry>
+
+		<varlistentry>
+			<term><menuchoice><guimenuitem>Copy Root Value</guimenuitem>
+				</menuchoice></term>
+			<listitem>
+                            <para>Copies the root <literal>x</literal> value to the system clipboard.
+					Only up to the first five digits after the decimal point can be copied.
+                                        Use some <ulink url="https://en.wikipedia.org/wiki/Computer_algebra_system">computer algebra system</ulink> to determine this root with arbitrary precision.
+					This tool is only available when the current tracking position is close to a root.
+				</para>
+			</listitem>
+		</varlistentry>
+
 		<varlistentry>
 			<term><menuchoice><guimenuitem>Plot Area...</guimenuitem>
 				</menuchoice></term>
diff --git a/kmplot/maindlg.cpp b/kmplot/maindlg.cpp
index f6a6b86..858b092 100644
--- a/kmplot/maindlg.cpp
+++ b/kmplot/maindlg.cpp
@@ -26,6 +26,7 @@
 #include "maindlg.h"
 
 // Qt includes
+#include <QClipboard>
 #include <QDebug>
 #include <QFileDialog>
 #include <QIcon>
@@ -131,7 +132,8 @@ MainDlg::MainDlg(QWidget *parentWidget, QObject *parent, const QVariantList& ) :
 		KParts::ReadWritePart( parent ),
 		m_recentFiles( 0 ),
 		m_modified(false),
-		m_parent(parentWidget)
+		m_parent(parentWidget),
+		m_rootValue( 0 )
 {
 	assert( !m_self ); // this class should only be constructed once
 	m_self = this;
@@ -389,6 +391,28 @@ void MainDlg::setupActions()
 	m_popupmenu->addAction( mnuMinValue );
 	m_popupmenu->addAction( mnuMaxValue );
 	m_popupmenu->addAction( mnuArea );
+
+	QAction * copyXY = actionCollection()->addAction( "copyXY" );
+	copyXY->setText(i18n("Copy (x, y)"));
+	connect( copyXY, &QAction::triggered, []{
+		QClipboard * cb = QApplication::clipboard();
+		QPointF currentXY = View::self()->getCrosshairPosition();
+		cb->setText( i18nc("Copied pair of coordinates (x, y)", "(%1, %2)", QLocale().toString( currentXY.x(), 'f', 5 ), QLocale().toString( currentXY.y(), 'f', 5 )), QClipboard::Clipboard );
+	} );
+	m_popupmenu->addAction( copyXY );
+
+	QAction * copyRootValue = actionCollection()->addAction( "copyRootValue" );
+	copyRootValue->setText(i18n("Copy Root Value"));
+	connect( View::self(), &View::updateRootValue, [this, copyRootValue]( bool haveRoot, double rootValue ){
+		copyRootValue->setVisible(haveRoot);
+		m_rootValue = rootValue;
+	} );
+	connect( copyRootValue, &QAction::triggered, [this]{
+		QClipboard * cb = QApplication::clipboard();
+		cb->setText( QLocale().toString( m_rootValue, 'f', 5 ), QClipboard::Clipboard );
+	} );
+	m_popupmenu->addAction( copyRootValue );
+
 	//END function popup menu
 }
 
diff --git a/kmplot/maindlg.h b/kmplot/maindlg.h
index 1cf5a68..0f57b79 100644
--- a/kmplot/maindlg.h
+++ b/kmplot/maindlg.h
@@ -215,6 +215,9 @@ private:
 	/// A pointer to ourselves
 	static MainDlg * m_self;
 
+	/// Root value for copying into clipboard
+	double m_rootValue;
+
 protected slots:
 	/**
 	* When you click on a File->Open Recent file, it'll open
diff --git a/kmplot/view.cpp b/kmplot/view.cpp
index 44761f0..c1efba5 100644
--- a/kmplot/view.cpp
+++ b/kmplot/view.cpp
@@ -96,6 +96,7 @@ View::View( bool readOnly, QMenu * functionPopup, QWidget* parent )
     setAttribute( Qt::WA_StaticContents );
 	
 	m_haveRoot = false;
+	emit updateRootValue( false, 0 );
 	m_xmin = m_xmax = m_ymin = m_ymax = 0.0;
 	m_printHeaderTable = false;
 	m_printBackground = false;
@@ -3511,10 +3512,14 @@ bool View::updateCrosshairPosition()
 					str += i18n("root") + ":  x" + SubscriptZeroSymbol + " = ";
 					setStatusBar( str+QString().sprintf("%+.5f", x0), RootSection );
 					m_haveRoot=true;
+					emit updateRootValue( true, x0 );
 				}
 			}
 			else
+			{
 				m_haveRoot=false;
+				emit updateRootValue( false, 0 );
+			}
 		}
 
 		// For Cartesian plots, only adjust the cursor position if it is not at the ends of the view
@@ -4248,6 +4253,11 @@ void View::setPrintHeight( double height )
 	m_printHeight = height;
 }
 
+QPointF View::getCrosshairPosition() const
+{
+	return m_crosshairPosition;
+}
+
 //END class View
 
 
diff --git a/kmplot/view.h b/kmplot/view.h
index 2ff6d4c..0762f1f 100644
--- a/kmplot/view.h
+++ b/kmplot/view.h
@@ -209,6 +209,11 @@ class View : public QWidget
 			SectionCount		= 4
 		};
 
+		/**
+		 * Crosshair position in real coordinates
+		 */
+		QPointF getCrosshairPosition() const;
+
 	public slots:
 		/// Called when the user want to cancel the drawing
 		void stopDrawing();
@@ -235,6 +240,7 @@ class View : public QWidget
 	
 	signals:
 		void setStatusBarText(const QString &);
+		void updateRootValue(bool haveRoot, double rootValue);
 	
 	protected:
 		/// called when focus is lost


More information about the kde-doc-english mailing list