Changeset View
Changeset View
Standalone View
Standalone View
src/part/layoutagraphthread.cpp
Show All 11 Lines | 1 | /* | |||
---|---|---|---|---|---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. | ||
14 | 14 | | |||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | 17 | | |||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "kgraphviewerlib_debug.h" | | |||
21 | #include "layoutagraphthread.h" | 20 | #include "layoutagraphthread.h" | ||
21 | #include "kgraphviewerlib_debug.h" | ||||
22 | 22 | | |||
23 | #include <QMutex> | 23 | #include <QMutex> | ||
24 | 24 | | |||
25 | #include <QDebug> | 25 | #include <QDebug> | ||
26 | 26 | | |||
27 | static QMutex gv_mutex; | 27 | static QMutex gv_mutex; | ||
28 | 28 | | |||
29 | // Not sure just wrapping these two is really enough, but it | 29 | // Not sure just wrapping these two is really enough, but it | ||
30 | // fixed all crashes when loading many files at once for me. | 30 | // fixed all crashes when loading many files at once for me. | ||
31 | 31 | | |||
32 | int threadsafe_wrap_gvLayout(GVC_t *gvc, graph_t *g, const char *engine) | 32 | int threadsafe_wrap_gvLayout(GVC_t *gvc, graph_t *g, const char *engine) | ||
33 | { | 33 | { | ||
34 | QMutexLocker locker(&gv_mutex); | 34 | QMutexLocker locker(&gv_mutex); | ||
35 | return gvLayout(gvc, g, engine); | 35 | return gvLayout(gvc, g, engine); | ||
36 | } | 36 | } | ||
37 | 37 | | |||
38 | int threadsafe_wrap_gvRender(GVC_t *gvc, graph_t *g, const char *format, FILE *out) | 38 | int threadsafe_wrap_gvRender(GVC_t *gvc, graph_t *g, const char *format, FILE *out) | ||
39 | { | 39 | { | ||
40 | QMutexLocker locker(&gv_mutex); | 40 | QMutexLocker locker(&gv_mutex); | ||
41 | return gvRender(gvc, g, format, out); | 41 | return gvRender(gvc, g, format, out); | ||
42 | } | 42 | } | ||
43 | 43 | | |||
44 | LayoutAGraphThread::LayoutAGraphThread() : sem(1) | 44 | LayoutAGraphThread::LayoutAGraphThread() | ||
45 | : sem(1) | ||||
45 | { | 46 | { | ||
46 | m_gvc = gvContext(); | 47 | m_gvc = gvContext(); | ||
47 | } | 48 | } | ||
48 | 49 | | |||
49 | LayoutAGraphThread::~LayoutAGraphThread() | 50 | LayoutAGraphThread::~LayoutAGraphThread() | ||
50 | { | 51 | { | ||
51 | gvFreeContext(m_gvc); | 52 | gvFreeContext(m_gvc); | ||
52 | } | 53 | } | ||
53 | 54 | | |||
54 | void LayoutAGraphThread::run() | 55 | void LayoutAGraphThread::run() | ||
55 | { | 56 | { | ||
56 | if (!m_g) | 57 | if (!m_g) { | ||
57 | { | | |||
58 | qCWarning(KGRAPHVIEWERLIB_LOG) << "No graph loaded, skipping layout"; | 58 | qCWarning(KGRAPHVIEWERLIB_LOG) << "No graph loaded, skipping layout"; | ||
59 | return; | 59 | return; | ||
60 | } | 60 | } | ||
61 | threadsafe_wrap_gvLayout(m_gvc, m_g, m_layoutCommand.toUtf8().data()); | 61 | threadsafe_wrap_gvLayout(m_gvc, m_g, m_layoutCommand.toUtf8().data()); | ||
62 | threadsafe_wrap_gvRender(m_gvc, m_g, "xdot", nullptr); | 62 | threadsafe_wrap_gvRender(m_gvc, m_g, "xdot", nullptr); | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | void LayoutAGraphThread::layoutGraph(graph_t* graph, const QString& layoutCommand) | 65 | void LayoutAGraphThread::layoutGraph(graph_t *graph, const QString &layoutCommand) | ||
66 | { | 66 | { | ||
67 | sem.acquire(); | 67 | sem.acquire(); | ||
68 | m_g = graph; | 68 | m_g = graph; | ||
69 | m_layoutCommand = layoutCommand; | 69 | m_layoutCommand = layoutCommand; | ||
70 | start(); | 70 | start(); | ||
71 | } | 71 | } | ||
72 | |