File indexing completed on 2024-05-19 15:27:52

0001 /*
0002     This file is part of KGraphViewer.
0003     Copyright (C) 2010  Gael de Chalendar <kleag@free.fr>
0004 
0005     This program is free software; you can redistribute it and/or
0006     modify it under the terms of the GNU General Public License as
0007     published by the Free Software Foundation; either version 2 of
0008     the License, or (at your option) any later version.
0009 
0010     This program is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013     GNU General Public License for more details.
0014 
0015     You should have received a copy of the GNU General Public License
0016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 
0018 */
0019 
0020 #ifndef LOADAGRAPHTHREAD_H
0021 #define LOADAGRAPHTHREAD_H
0022 
0023 #include <QSemaphore>
0024 #include <QThread>
0025 
0026 #include <graphviz/gvc.h>
0027 
0028 class LoadAGraphThread : public QThread
0029 {
0030     Q_OBJECT
0031 public:
0032     LoadAGraphThread()
0033         : sem(1)
0034     {
0035     }
0036     void loadFile(const QString &dotFileName);
0037     inline graph_t *g()
0038     {
0039         return m_g;
0040     }
0041     inline const QString &dotFileName()
0042     {
0043         return m_dotFileName;
0044     }
0045     void processed_finished()
0046     {
0047         sem.release();
0048     }
0049 
0050     // helper method only for DotGraphView::loadLibrarySync()
0051     // see notes next to the call there
0052     void setDotFileName(const QString &dotFileName)
0053     {
0054         m_dotFileName = dotFileName;
0055     }
0056 
0057 protected:
0058     void run() override;
0059 
0060 private:
0061     QSemaphore sem;
0062     QString m_dotFileName;
0063     graph_t *m_g = nullptr;
0064 };
0065 
0066 #endif // LOADAGRAPHTHREAD_H