File indexing completed on 2024-05-05 16:27:22

0001 /* This file is part of KGraphViewer.
0002    Copyright (C) 2005-2007 Gael de Chalendar <kleag@free.fr>
0003 
0004    KGraphViewer is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, version 2.
0007 
0008    This program is distributed in the hope that it will be useful,
0009    but WITHOUT ANY WARRANTY; without even the implied warranty of
0010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011    General Public License for more details.
0012 
0013    You should have received a copy of the GNU General Public License
0014    along with this program; if not, write to the Free Software
0015    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0016    02110-1301, USA
0017 */
0018 
0019 #ifndef _KGRAPHEDITOR_H_
0020 #define _KGRAPHEDITOR_H_
0021 
0022 #include <KParts/MainWindow>
0023 #include <KRecentFilesAction>
0024 #include <QAction>
0025 #include <QDir>
0026 #include <QTabWidget>
0027 
0028 class QTreeWidget;
0029 class QTreeWidgetItem;
0030 
0031 class KToggleAction;
0032 
0033 class KGraphEditorNodesTreeWidget;
0034 class KGraphEditorElementTreeWidget;
0035 
0036 namespace KParts
0037 {
0038 class ReadOnlyPart;
0039 }
0040 
0041 /**
0042  * This is the application "Shell".  It has a menubar, toolbar, and
0043  * statusbar but relies on the "Part" to do all the real work.
0044  *
0045  * @short Application Shell
0046  * @author Gael de Chalendar <kleag@free.fr>
0047  */
0048 class KGraphEditor : public KParts::MainWindow
0049 {
0050     Q_OBJECT
0051 public:
0052     /**
0053      * Default Constructor
0054      */
0055     KGraphEditor();
0056 
0057     /**
0058      * Default Destructor
0059      */
0060     ~KGraphEditor() override;
0061 
0062     /**
0063      * Use this method to load whatever file/URL you have
0064      */
0065     void openUrl(const QUrl &url);
0066 
0067     void reloadPreviousFiles();
0068 
0069 protected:
0070     void closeEvent(QCloseEvent *event) override;
0071 
0072 Q_SIGNALS:
0073     void hide(KParts::Part *part);
0074     void prepareAddNewElement(QMap<QString, QString> attribs);
0075     void prepareAddNewEdge(QMap<QString, QString> attribs);
0076     void setReadWrite();
0077     void saveTo(const QString &fileName);
0078 
0079     void selectNode(const QString &);
0080     void removeNode(const QString &);
0081     void removeElement(const QString &);
0082     void addAttribute(const QString &);
0083     void removeAttribute(const QString &, const QString &);
0084     void setAttribute(const QString &elementId, const QString &attributeName, const QString &attributeValue);
0085     void update();
0086     void saddNewEdge(QString src, QString tgt, QMap<QString, QString> attribs);
0087     void renameNode(const QString &oldName, const QString &newName);
0088 
0089 public Q_SLOTS:
0090     /**
0091      * Use this method to load whatever file/URL you have
0092      */
0093     void openUrl(const QString &url)
0094     {
0095         openUrl(QUrl::fromUserInput(url, QDir::currentPath(), QUrl::AssumeLocalFile));
0096     }
0097 
0098     void slotSetActiveGraph(KParts::ReadOnlyPart *part);
0099 
0100     void slotGraphLoaded();
0101 
0102     void slotRemoveNode(const QString &);
0103     void slotAddAttribute(const QString &);
0104     void slotRemoveAttribute(const QString &, const QString &);
0105 
0106     void slotNewElementItemChanged(QTreeWidgetItem *, int);
0107     void slotAddNewElementAttribute(const QString &);
0108     void slotRemoveNewElementAttribute(const QString &);
0109 
0110     void slotNewNodeAdded(const QString &id);
0111     void slotNewEdgeAdded(const QString &ids, const QString &idt);
0112     /*public slots:
0113     void reloadOnChangeMode_pressed(int value);
0114     void openInExistingWindowMode_pressed(int value);
0115     void reopenPreviouslyOpenedFilesMode_pressed(int value);*/
0116     void slotRemoveElement(const QString &id);
0117     void slotSelectionIs(const QList<QString> &, const QPoint &p);
0118     void slotNewEdgeFinished(const QString &, const QString &, const QMap<QString, QString> &);
0119 
0120 private Q_SLOTS:
0121     void fileNew();
0122     void fileOpen();
0123     void fileSave();
0124     void fileSaveAs();
0125     void close(int index);
0126     void close();
0127     void slotURLSelected(const QUrl &);
0128     void optionsShowToolbar();
0129     void optionsShowStatusbar();
0130     void optionsConfigureToolbars();
0131     void optionsConfigure();
0132     void newTabSelectedSlot(int index);
0133 
0134     void applyNewToolbarConfig();
0135     void slotItemChanged(QTreeWidgetItem *item, int column);
0136     void slotItemClicked(QTreeWidgetItem *item, int column);
0137     void slotEditNewVertex();
0138     void slotEditNewEdge();
0139 
0140     void slotParsingModeExternalToggled(bool value);
0141     void slotParsingModeInternalToggled(bool value);
0142 
0143     void slotHoverEnter(const QString &);
0144     void slotHoverLeave(const QString &);
0145 
0146     KParts::ReadOnlyPart *slotNewGraph();
0147 
0148 private:
0149     void setupAccel();
0150     void setupActions();
0151 
0152 private:
0153     KGraphEditorNodesTreeWidget *m_treeWidget;
0154     KGraphEditorElementTreeWidget *m_newElementAttributesWidget;
0155     QTabWidget *m_widget;
0156     KRecentFilesAction *m_rfa;
0157     KParts::PartManager *m_manager;
0158 
0159     KToggleAction *m_toolbarAction;
0160     KToggleAction *m_statusbarAction;
0161     QAction *m_closeAction;
0162 
0163     QStringList m_openedFiles;
0164 
0165     QMap<QWidget *, KParts::ReadOnlyPart *> m_tabsPartsMap;
0166     QMap<QWidget *, QString> m_tabsFilesMap;
0167     KParts::ReadOnlyPart *m_currentPart;
0168 
0169     QMap<QString, QString> m_newElementAttributes;
0170 
0171     QString m_currentTreeWidgetItemText;
0172 };
0173 
0174 #endif // _KGRAPHEDITOR_H_