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 LAYOUTAGRAPHTHREAD_H 0021 #define LAYOUTAGRAPHTHREAD_H 0022 0023 #include <QSemaphore> 0024 #include <QThread> 0025 0026 #include <graphviz/gvc.h> 0027 0028 int threadsafe_wrap_gvLayout(GVC_t *gvc, graph_t *g, const char *engine); 0029 int threadsafe_wrap_gvRender(GVC_t *gvc, graph_t *g, const char *format, FILE *out); 0030 0031 class LayoutAGraphThread : public QThread 0032 { 0033 Q_OBJECT 0034 public: 0035 LayoutAGraphThread(); 0036 ~LayoutAGraphThread() override; 0037 void layoutGraph(graph_t *graph, const QString &layoutCommand); 0038 inline graph_t *g() 0039 { 0040 return m_g; 0041 } 0042 inline GVC_t *gvc() 0043 { 0044 return m_gvc; 0045 } 0046 inline const QString &layoutCommand() const 0047 { 0048 return m_layoutCommand; 0049 } 0050 void processed_finished() 0051 { 0052 sem.release(); 0053 } 0054 0055 protected: 0056 void run() override; 0057 0058 private: 0059 QSemaphore sem; 0060 QString m_layoutCommand; 0061 graph_t *m_g = nullptr; 0062 GVC_t *m_gvc = nullptr; 0063 }; 0064 0065 #endif // LAYOUTAGRAPHTHREAD_H