Tulip  5.1.0
Large graphs analysis and drawing
TlpQtTools.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
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 <QColor>
24 #include <QDebug>
25 
26 #include <tulip/Color.h>
27 #include <tulip/tulipconf.h>
28 #include <tulip/PropertyInterface.h>
29 
30 class QWidget;
31 class QString;
32 
33 namespace tlp {
34 
35 struct PluginLoader;
36 
37 TLP_QT_SCOPE bool getColorDialog(const QColor &color,QWidget *parent,const QString &title,QColor &result);
38 
39 inline QColor colorToQColor(const Color& color) {
40  return QColor(color.getR(), color.getG(), color.getB(), color.getA());
41 }
42 inline Color QColorToColor(const QColor& color) {
43  return Color(color.red(), color.green(), color.blue(), color.alpha());
44 }
45 /**
46  * @brief Convert a QString to a Tulip UTF-8 encoded std::string.
47  **/
48 inline std::string QStringToTlpString(const QString& toConvert) {
49  return std::string(toConvert.toUtf8());
50 }
51 /**
52  * @brief Convert a Tulip UTF-8 encoded std::string to a QString
53  **/
54 inline QString tlpStringToQString(const std::string& toConvert) {
55  return QString::fromUtf8(toConvert.c_str());
56 }
57 
58 /**
59  * @brief Case insensitive comparison of two QStrings
60  **/
61 inline bool QStringCaseCmp(const QString& s1, const QString& s2) {
62  return QString::localeAwareCompare(s1, s2) < 0;
63 }
64 
65 
66 
67 /**
68  * @brief Convert the property type string to a label to display in the GUI.
69  * The property type label is the string to display in the GUI instead of the basic property type string.
70  **/
71 TLP_QT_SCOPE QString propertyTypeToPropertyTypeLabel(const std::string& typeName);
72 
73 /**
74  * @brief Get the string to display as property type for the given property.
75  * The property type label is the string to display in the GUI instead of the property type string.
76  * By example for a property of type "double" the label displayed in the GUI will be "Metric".
77  **/
78 inline QString propertyInterfaceToPropertyTypeLabel(const tlp::PropertyInterface* const property) {
79  return propertyTypeToPropertyTypeLabel(property->getTypename());
80 }
81 
82 /**
83  * @brief Convert the label of a property type to it's corresponding property type.
84  * The property type label is the string to display in the GUI instead of the property type string.
85  * By example for a property of type "double" the label displayed in the GUI will be "Metric".
86  **/
87 TLP_QT_SCOPE std::string propertyTypeLabelToPropertyType(const QString& typeNameLabel);
88 
89 /**
90  * @brief Gets the name of the package to retrieve for this version of tulip.
91  * 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.
92  *
93  * @param pluginName The name of the plugin for which we want the package name.
94  **/
95 TLP_QT_SCOPE QString getPluginPackageName(const QString& pluginName);
96 
97 TLP_QT_SCOPE QString getPluginStagingDirectory();
98 
99 TLP_QT_SCOPE QString getPluginLocalInstallationDir();
100 
101 TLP_QT_SCOPE QString localPluginsPath();
102 
103 /**
104  @brief Sets up environment when creating an executable using Tulip libraries
105  This method performs basic operations when starting a software using Tulip:
106  @list
107  @li It initializes the tulip library
108  @li it checks plugins to be discarded and uninstalls them
109  @li It loads plugins from the application path
110  @endlist
111  */
112 extern TLP_QT_SCOPE void initTulipSoftware(PluginLoader *loader = NULL, bool removeDiscardedPlugins=false);
113 
114 /**
115  * @brief redirect tlp::debug() to qDebug()
116  */
117 TLP_QT_SCOPE void redirectDebugOutputToQDebug();
118 
119 /**
120  * @brief redirect tlp::warning() to qWarning()
121  */
122 TLP_QT_SCOPE void redirectWarningOutputToQWarning();
123 
124 /**
125  * @brief redirect tlp::error() to qCritical()
126  */
127 TLP_QT_SCOPE void redirectErrorOutputToQCritical();
128 
129 TLP_QT_SCOPE void disableQtUserInput();
130 
131 TLP_QT_SCOPE void enableQtUserInput();
132 
133 }
134 
135 // QDebug extension
136 inline QDebug operator<<(QDebug dbg, const std::string& s) {
137  dbg.nospace() << s.c_str();
138  return dbg.space();
139 }
140 
141 // useful macros needed for menu actions building
142 #ifdef __APPLE__
143 #define SET_TOOLTIP_WITH_CTRL_SHORTCUT(a, tt, sc) a->setToolTip(QString(tt) + tlpStringToQString(" [⌘+") + sc + "]")
144 #else
145 #define SET_TOOLTIP_WITH_CTRL_SHORTCUT(a, tt, sc) a->setToolTip(QString(tt) + " [Ctrl+" + sc + "]")
146 #endif
147 
148 #define SET_TIPS_WITH_CTRL_SHORTCUT(a, tt, sc) SET_TOOLTIP_WITH_CTRL_SHORTCUT(a, tt, sc);a->setStatusTip(a->toolTip())
149 
150 #endif
void redirectDebugOutputToQDebug()
redirect tlp::debug() to qDebug()
std::ostream & operator<<(std::ostream &os, const Array< Obj, SIZE > &array)
operator << stream operator to easily print an array, or save it to a file.
Definition: Array.cxx:34
PropertyInterface describes the interface of a graph property.
void redirectWarningOutputToQWarning()
redirect tlp::warning() to qWarning()
bool QStringCaseCmp(const QString &s1, const QString &s2)
Case insensitive comparison of two QStrings.
Definition: TlpQtTools.h:61
void redirectErrorOutputToQCritical()
redirect tlp::error() to qCritical()
std::string QStringToTlpString(const QString &toConvert)
Convert a QString to a Tulip UTF-8 encoded std::string.
Definition: TlpQtTools.h:48
std::string propertyTypeLabelToPropertyType(const QString &typeNameLabel)
Convert the label of a property type to it&#39;s corresponding property type. The property type label is ...
QString propertyInterfaceToPropertyTypeLabel(const tlp::PropertyInterface *const property)
Get the string to display as property type for the given property. The property type label is the str...
Definition: TlpQtTools.h:78
void initTulipSoftware(PluginLoader *loader=NULL, bool removeDiscardedPlugins=false)
Sets up environment when creating an executable using Tulip libraries This method performs basic oper...
QString tlpStringToQString(const std::string &toConvert)
Convert a Tulip UTF-8 encoded std::string to a QString.
Definition: TlpQtTools.h:54
virtual const std::string & getTypename() const =0
Gets a string describing the type of the property (e.g. "graph", "double", "layout", "string", "integer", "color", "size").
QString propertyTypeToPropertyTypeLabel(const std::string &typeName)
Convert the property type string to a label to display in the GUI. The property type label is the str...
A callback class when loading plugins into Tulip.
Definition: PluginLoader.h:40
QString getPluginPackageName(const QString &pluginName)
Gets the name of the package to retrieve for this version of tulip. The package name uses the Tulip r...