Warning, file /education/kmplot/kmplot/functioneditor.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 KmPlot - a math. function plotter for the KDE-Desktop 0003 0004 SPDX-FileCopyrightText: 1998-2002 Klaus-Dieter Möller <kd.moeller@t-online.de> 0005 SPDX-FileCopyrightText: 2004 Fredrik Edemar <f_edemar@linux.se> 0006 SPDX-FileCopyrightText: 2006 David Saxton <david@bluehaze.org> 0007 0008 This file is part of the KDE Project. 0009 KmPlot is part of the KDE-EDU Project. 0010 0011 SPDX-License-Identifier: GPL-2.0-or-later 0012 0013 */ 0014 0015 #ifndef FUNCTIONEDITOR_H 0016 #define FUNCTIONEDITOR_H 0017 0018 #include "parser.h" 0019 0020 #include <QDockWidget> 0021 #include <QList> 0022 #include <QListWidget> 0023 #include <QListWidgetItem> 0024 #include <QMimeData> 0025 0026 class FunctionEditorWidget; 0027 class FunctionListItem; 0028 class FunctionListWidget; 0029 class QMenu; 0030 class QTimer; 0031 class Function; 0032 0033 class FunctionEditor : public QDockWidget 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 FunctionEditor(QMenu *createNewPlotsMenu, QWidget *parent); 0039 virtual ~FunctionEditor(); 0040 0041 /** 0042 * Highlights the function item for the given function. 0043 */ 0044 void setCurrentFunction(int functionID); 0045 0046 public slots: 0047 /** 0048 * Deletes the current selected function. 0049 */ 0050 void deleteCurrent(); 0051 /** 0052 * Creates a new cartesian function. 0053 */ 0054 void createCartesian(); 0055 /** 0056 * Creates a new parametric function. 0057 */ 0058 void createParametric(); 0059 /** 0060 * Creates a new polar function. 0061 */ 0062 void createPolar(); 0063 /** 0064 * Creates a new implicit function. 0065 */ 0066 void createImplicit(); 0067 /** 0068 * Creates a new differential function. 0069 */ 0070 void createDifferential(); 0071 /** 0072 * Called when the list of functions in the parser changes. 0073 */ 0074 void functionsChanged(); 0075 0076 protected slots: 0077 /** 0078 * Called when a function in the list is selected. 0079 */ 0080 void functionSelected(QListWidgetItem *function); 0081 /** 0082 * Called when the user changes a function widget. 0083 */ 0084 void save(); 0085 /** 0086 * Called when the user ticks or unticks an item in the function list. 0087 */ 0088 void saveItem(QListWidgetItem *item); 0089 /** 0090 * Updates the list of functions (called when a function is added or 0091 * removed from Parser). 0092 */ 0093 void syncFunctionList(); 0094 /** 0095 * Called when the user edits any of the widgets relating to a 0096 * cartesian function. 0097 */ 0098 void saveCartesian(); 0099 /** 0100 * Called when the user edits any of the widgets relating to a 0101 * polar function. 0102 */ 0103 void savePolar(); 0104 /** 0105 * Called when the user edits any of the widgets relating to a 0106 * parametric function. 0107 */ 0108 void saveParametric(); 0109 /** 0110 * Called when the user edits any of the widgets relating to an 0111 * implicit function. 0112 */ 0113 void saveImplicit(); 0114 /** 0115 * Called when the user edits any of the widgets relating to a 0116 * differential function. 0117 */ 0118 void saveDifferential(); 0119 0120 protected: 0121 /** 0122 * Initialize the widgets from the cartesian function set in 0123 * m_functionID. 0124 */ 0125 void initFromCartesian(); 0126 /** 0127 * Initialize the widgets from a polar function set in m_functionID. 0128 */ 0129 void initFromPolar(); 0130 /** 0131 * Initialize the widgets from a parametric function set in 0132 * m_functionID. 0133 */ 0134 void initFromParametric(); 0135 /** 0136 * Initialize the widgets from an implicit function set in m_functionID. 0137 */ 0138 void initFromImplicit(); 0139 /** 0140 * Initialize the widgets from a differential function set in m_functionID. 0141 */ 0142 void initFromDifferential(); 0143 /** 0144 * Resets all the function editing widgets (i.e. those in the widget 0145 * stack, but not the list of functions). 0146 */ 0147 void resetFunctionEditing(); 0148 /** 0149 * Extract function \p name and \p expression from the given 0150 * \p equation - for implicit functions. 0151 */ 0152 void splitImplicitEquation(const QString &equation, QString *name, QString *expression); 0153 /** 0154 * Used at end of the save* functions. 0155 * \a tempFunction is the function to copy the settings from. 0156 */ 0157 void saveFunction(Function *tempFunction); 0158 /** 0159 * Called from the create* functions - finishes of saving of the function. 0160 */ 0161 void createFunction(const QString &eq0, const QString &eq1, Function::Type type); 0162 0163 /** 0164 * The main editing widget. 0165 */ 0166 FunctionEditorWidget *m_editor; 0167 /** 0168 * The id of the function currently being edited. 0169 */ 0170 int m_functionID; 0171 0172 /** 0173 * Used to ensure only one update when multiple widgets are changed. 0174 * A timer for each function type. 0175 */ 0176 QTimer *m_saveTimer[5]; 0177 /** 0178 * Ensure only one update when functions are added or removed, and all 0179 * the piece of code that is adding or removing a function to make the 0180 * necessary changes first. 0181 */ 0182 QTimer *m_syncFunctionListTimer; 0183 /** 0184 * The list of functions. 0185 */ 0186 FunctionListWidget *m_functionList; 0187 }; 0188 0189 class FunctionListWidget : public QListWidget 0190 { 0191 public: 0192 explicit FunctionListWidget(QWidget *parent); 0193 0194 protected: 0195 void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; 0196 void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; 0197 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0198 QMimeData *mimeData(const QList<QListWidgetItem *> items) const Q_DECL_OVERRIDE; 0199 #else 0200 QMimeData *mimeData(const QList<QListWidgetItem *> &items) const Q_DECL_OVERRIDE; 0201 #endif 0202 QStringList mimeTypes() const Q_DECL_OVERRIDE; 0203 }; 0204 0205 class FunctionListItem : public QListWidgetItem 0206 { 0207 public: 0208 FunctionListItem(QListWidget *parent, int function); 0209 0210 /** 0211 * Updates the displayed text and checked state depending on the 0212 * function types and states. 0213 */ 0214 void update(); 0215 0216 int function() const 0217 { 0218 return m_function; 0219 } 0220 0221 protected: 0222 int m_function; 0223 }; 0224 0225 #endif // FUNCTIONEDITOR_H