Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
TlpQtTools.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef _TLPQTTOOLS_H
21 #define _TLPQTTOOLS_H
22 
23 #include "tulip/Color.h"
24 #include "tulip/Graph.h"
25 #include "tulip/GlMainWidget.h"
26 #include "tulip/DataSet.h"
27 
28 #include <QtGui/QColor>
29 #include <QtCore/QDebug>
30 
31 class QWidget;
32 
33 namespace tlp {
34 
35 TLP_QT_SCOPE bool getColorDialog(const QColor &color,QWidget *parent,const QString &title,QColor &result);
36 
37 inline QColor colorToQColor(const Color& color) {
38  return QColor(color.getR(), color.getG(), color.getB(), color.getA());
39 }
40 inline Color QColorToColor(const QColor& color) {
41  return Color(color.red(), color.green(), color.blue(), color.alpha());
42 }
43 /**
44  * @brief Convert a string from Tulip to QString.
45  **/
46 inline std::string QStringToTlpString(const QString& toConvert) {
47  return std::string(toConvert.toUtf8());
48 }
49 /**
50  * @brief Convert a QString to tulip string.
51  **/
52 inline QString tlpStringToQString(const std::string& toConvert) {
53  return QString::fromUtf8(toConvert.c_str());
54 }
55 
56 /**
57  * @brief Case insensitive comparison of two QStrings
58  **/
59 inline bool QStringCaseCmp(const QString& s1, const QString& s2) {
60  return QString::localeAwareCompare(s1, s2) < 0;
61 }
62 
63 
64 
65 /**
66  * @brief Convert the property type string to a label to display in the GUI.
67  * The property type label is the string to display in the GUI instead of the basic property type string.
68  * By example for a property of type "double" the label displayed in the GUI will be "Metric".
69  **/
70 TLP_QT_SCOPE QString propertyTypeToPropertyTypeLabel(const std::string& typeName);
71 
72 /**
73  * @brief Get the string to display as property type for the given property.
74  * The property type label is the string to display in the GUI instead of the property type string.
75  * By example for a property of type "double" the label displayed in the GUI will be "Metric".
76  **/
77 inline QString propertyInterfaceToPropertyTypeLabel(const tlp::PropertyInterface* const property) {
78  return propertyTypeToPropertyTypeLabel(property->getTypename());
79 }
80 
81 /**
82  * @brief Convert the label of a property type to it's corresponding property type.
83  * The property type label is the string to display in the GUI instead of the property type string.
84  * By example for a property of type "double" the label displayed in the GUI will be "Metric".
85  **/
86 TLP_QT_SCOPE std::string propertyTypeLabelToPropertyType(const QString& typeNameLabel);
87 
88 /**
89  * @brief Gets the name of the package to retrieve for this version of tulip.
90  * The package name uses the Tulip release, platform (windows, unix, ...), architecture (x86, x86_64), and compiler used (GCC, Clang, MSVC) to determine which package this version can use.
91  *
92  * @param pluginName The name of the plugin for which we want the package name.
93  **/
94 TLP_QT_SCOPE QString getPluginPackageName(const QString& pluginName);
95 
96 TLP_QT_SCOPE QString getPluginStagingDirectory();
97 
98 TLP_QT_SCOPE QString getPluginLocalInstallationDir();
99 
100 TLP_QT_SCOPE QGLFramebufferObject *createQGLFramebufferObject(int width, int height, QGLFramebufferObject::Attachment attachment);
101 
102 TLP_QT_SCOPE QString localPluginsPath();
103 
104 /**
105  @brief Sets up environment when creating an executable using Tulip libraries
106  This method performs basic operations when starting a software using Tulip:
107  @list
108  @li It initializes the tulip library
109  @li it checks plugins to be discarded and uninstalls them
110  @li It loads plugins from the application path
111  @endlist
112  */
113 extern TLP_QT_SCOPE void initTulipSoftware(PluginLoader *loader = NULL, bool removeDiscardedPlugins=false);
114 
115 /**
116  * @brief redirect tlp::debug() to qDebug()
117  */
118 TLP_QT_SCOPE void redirectDebugOutputToQDebug();
119 
120 /**
121  * @brief redirect tlp::warning() to qWarning()
122  */
123 TLP_QT_SCOPE void redirectWarningOutputToQWarning();
124 
125 /**
126  * @brief redirect tlp::error() to qCritical()
127  */
128 TLP_QT_SCOPE void redirectErrorOutputToQCritical();
129 
130 }
131 
132 // QDebug extension
133 inline QDebug operator<<(QDebug dbg, const std::string& s) {
134  dbg.nospace() << s.c_str();
135  return dbg.space();
136 }
137 
138 #endif