File indexing completed on 2024-04-28 11:20:48

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
0004 */
0005 
0006 #ifndef _RESULT_H
0007 #define _RESULT_H
0008 
0009 #include <QVariant>
0010 #include <QDomElement>
0011 #include <QJsonArray>
0012 #include "cantor_export.h"
0013 
0014 class KZip;
0015 
0016 namespace Cantor
0017 {
0018 
0019 class ResultPrivate;
0020 
0021 /**
0022  * Base class for different results, like text, image, animation. etc.
0023  */
0024 class CANTOR_EXPORT Result
0025 {
0026   public:
0027     /**
0028      * Default constructor
0029      */
0030     Result( );
0031     /**
0032      * Destructor
0033      */
0034     virtual ~Result();
0035 
0036     /**
0037      * returns html code, that represents this result,
0038      * e.g. an img tag for images
0039      * @return html code representing this result
0040      */
0041     virtual QString toHtml() = 0;
0042 
0043     /**
0044      * returns latex code, that represents this result
0045      * e.g. a includegraphics command for images
0046      * it falls back to toHtml if not implemented
0047      * @return latex code representing this result
0048      */
0049     virtual QString toLatex();
0050 
0051     /**
0052      * returns data associated with this result
0053      * (text/images/etc)
0054      * @return data associated with this result
0055      */
0056     virtual QVariant data() = 0;
0057 
0058     /**
0059      * returns an url, data for this result resides at
0060      * @return an url, data for this result resides at
0061      */
0062     virtual QUrl url();
0063 
0064     /**
0065      * returns an unique number, representing the type of this
0066      * result. Every subclass should define their own Type.
0067      * @return the type of this result
0068      */
0069     virtual int type() = 0;
0070     /**
0071      * returns the mimetype, this result is
0072      * @return the mimetype, this result is
0073      */
0074     virtual QString mimeType() = 0;
0075 
0076     /**
0077      * returns a DomElement, containing the information of the result
0078      * @param doc DomDocument used for storing the information
0079      * @return DomElement, containing the information of the result
0080      */
0081     virtual QDomElement toXml(QDomDocument& doc) = 0;
0082     /**
0083      * saves all the data, that can't be saved in xml
0084      * in an extra file in the archive.
0085      */
0086     virtual void saveAdditionalData(KZip* archive);
0087 
0088     /**
0089      * return a Jupyter json object, containing the information of the result
0090      */
0091     virtual QJsonValue toJupyterJson() = 0;
0092     /**
0093      * saves this to a file
0094      * @param filename name of the file
0095      */
0096     virtual void save(const QString& filename) = 0;
0097 
0098     /**
0099      * This functions handle Jupyter metadata of
0100      */
0101     QJsonObject jupyterMetadata() const;
0102     void setJupyterMetadata(QJsonObject metadata);
0103 
0104     /**
0105      * Allow to set execution result index, on this moment useful only for Jupyter
0106      * But maybe Cantor can use it too
0107      */
0108     int executionIndex() const;
0109     void setExecutionIndex(int index);
0110 
0111   private:
0112     ResultPrivate* d;
0113 };
0114 
0115 }
0116 
0117 #endif /* _RESULT_H */