Tulip  5.7.4
Large graphs analysis and drawing
TlpQtTools.h
1 /*
2  *
3  * This file is part of Tulip (https://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 #include <QCursor>
26 
27 #include <tulip/Color.h>
28 #include <tulip/tulipconf.h>
29 #include <tulip/PropertyInterface.h>
30 
31 class QWidget;
32 class QString;
33 
34 namespace tlp {
35 
36 struct PluginLoader;
37 
38 TLP_QT_SCOPE bool getColorDialog(const QColor &color, QWidget *parent, const QString &title,
39  QColor &result);
40 
41 inline QColor colorToQColor(const Color &color) {
42  return QColor(color.getR(), color.getG(), color.getB(), color.getA());
43 }
44 inline Color QColorToColor(const QColor &color) {
45  return Color(color.red(), color.green(), color.blue(), color.alpha());
46 }
47 /**
48  * @brief Convert a QString to a Tulip UTF-8 encoded std::string.
49  **/
50 inline std::string QStringToTlpString(const QString &toConvert) {
51  return std::string(toConvert.toUtf8());
52 }
53 /**
54  * @brief Convert a Tulip UTF-8 encoded std::string to a QString
55  **/
56 inline QString tlpStringToQString(const std::string &toConvert) {
57  return QString::fromUtf8(toConvert.c_str());
58 }
59 
60 /**
61  * @brief Case insensitive comparison of two QStrings
62  **/
63 inline bool QStringCaseCmp(const QString &s1, const QString &s2) {
64  return QString::localeAwareCompare(s1, s2) < 0;
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
70  *string.
71  **/
72 TLP_QT_SCOPE QString propertyTypeToPropertyTypeLabel(const std::string &typeName);
73 
74 /**
75  * @brief Get the string to display as property type for the given property.
76  * The property type label is the string to display in the GUI instead of the property type string.
77  * By example for a property of type "double" the label displayed in the GUI will be "Metric".
78  **/
79 inline QString propertyInterfaceToPropertyTypeLabel(const tlp::PropertyInterface *const property) {
80  return propertyTypeToPropertyTypeLabel(property->getTypename());
81 }
82 
83 /**
84  * @brief Convert the label of a property type to it's corresponding property type.
85  * The property type label is the string to display in the GUI instead of the property type string.
86  * By example for a property of type "double" the label displayed in the GUI will be "Metric".
87  **/
88 TLP_QT_SCOPE std::string propertyTypeLabelToPropertyType(const QString &typeNameLabel);
89 
90 /**
91  * @brief Gets the name of the package to retrieve for this version of tulip.
92  * The package name uses the Tulip release, platform (windows, unix, ...), architecture (x86,
93  *x86_64), and compiler used (GCC, Clang, MSVC) to determine which package this version can use.
94  *
95  * @param pluginName The name of the plugin for which we want the package name.
96  **/
97 TLP_QT_SCOPE QString getPluginPackageName(const QString &pluginName);
98 
99 TLP_QT_SCOPE QString getPluginStagingDirectory();
100 
101 TLP_QT_SCOPE QString getPluginLocalInstallationDir();
102 
103 TLP_QT_SCOPE QString localPluginsPath();
104 
105 /**
106  @brief Sets up environment when creating an executable using Tulip libraries
107  This method performs basic operations when starting a software using Tulip:
108  @list
109  @li It initializes the tulip library
110  @li it checks plugins to be discarded and uninstalls them
111  @li It loads plugins from the application path
112  @endlist
113  */
114 extern TLP_QT_SCOPE void initTulipSoftware(PluginLoader *loader = nullptr,
115  bool removeDiscardedPlugins = false);
116 
117 /**
118  * @brief redirect tlp::debug() to qDebug()
119  */
120 TLP_QT_SCOPE void redirectDebugOutputToQDebug();
121 
122 /**
123  * @brief redirect tlp::warning() to qWarning()
124  */
126 
127 /**
128  * @brief redirect tlp::error() to qCritical()
129  */
130 TLP_QT_SCOPE void redirectErrorOutputToQCritical();
131 
132 TLP_QT_SCOPE void disableQtUserInput();
133 
134 TLP_QT_SCOPE void enableQtUserInput();
135 
136 /**
137  * @brief convert sql like filter into an acceptable regexp
138  */
139 TLP_QT_SCOPE void convertLikeFilter(QString &filter);
140 
141 /**
142  * @brief associate a texture file path to a name
143  */
144 TLP_QT_SCOPE void registerTextureFile(QString name, QString textureFilePath);
145 
146 /**
147  * @brief return the texture file path associated to a name
148  */
149 TLP_QT_SCOPE QString getRegisteredTextureFile(QString name);
150 
151 /**
152  * @brief forget all registered texture files
153  */
154 TLP_QT_SCOPE void clearRegisteredTextureFiles();
155 
156 #ifdef __APPLE__
157 // on macosx Qt::WhatsThisCursor is not displayed,
158 // Qt::PointingHandCursor is displayed instead
159 TLP_QT_SCOPE const QCursor &QtWhatsThisCursor();
160 #define qtWhatsThisCursor QtWhatsThisCursor()
161 #else
162 #define qtWhatsThisCursor Qt::WhatsThisCursor
163 #endif
164 
165 } // namespace tlp
166 
167 // QDebug extension
168 inline QDebug operator<<(QDebug dbg, const std::string &s) {
169  dbg.nospace() << s.c_str();
170  return dbg.space();
171 }
172 
173 // Qt 5.15 warning fix
174 #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
175 #define QT_ENDL endl
176 #else
177 #define QT_ENDL Qt::endl
178 #endif
179 
180 // useful macros needed for menu actions building
181 #ifdef __APPLE__
182 #define SET_TOOLTIP_WITH_CTRL_SHORTCUT(a, tt, sc) \
183  a->setToolTip(QString(tt) + tlpStringToQString(" [⌘+") + sc + "]")
184 #else
185 #define SET_TOOLTIP_WITH_CTRL_SHORTCUT(a, tt, sc) a->setToolTip(QString(tt) + " [Ctrl+" + sc + "]")
186 #endif
187 
188 #define SET_TIPS_WITH_CTRL_SHORTCUT(a, tt, sc) \
189  SET_TOOLTIP_WITH_CTRL_SHORTCUT(a, tt, sc); \
190  a->setStatusTip(a->toolTip())
191 
192 // the color to display html links
193 #define HTML_LINK_COLOR "#0d71f1"
194 
195 #endif
PropertyInterface describes the interface of a graph property.
virtual const std::string & getTypename() const =0
Gets a string describing the type of the property value (e.g. "graph", "double", "layout",...
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:79
void redirectWarningOutputToQWarning()
redirect tlp::warning() to qWarning()
std::string QStringToTlpString(const QString &toConvert)
Convert a QString to a Tulip UTF-8 encoded std::string.
Definition: TlpQtTools.h:50
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...
void registerTextureFile(QString name, QString textureFilePath)
associate a texture file path to a name
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...
void initTulipSoftware(PluginLoader *loader=nullptr, bool removeDiscardedPlugins=false)
Sets up environment when creating an executable using Tulip libraries This method performs basic oper...
void convertLikeFilter(QString &filter)
convert sql like filter into an acceptable regexp
void redirectErrorOutputToQCritical()
redirect tlp::error() to qCritical()
void redirectDebugOutputToQDebug()
redirect tlp::debug() to qDebug()
std::string propertyTypeLabelToPropertyType(const QString &typeNameLabel)
Convert the label of a property type to it's corresponding property type. The property type label is ...
bool QStringCaseCmp(const QString &s1, const QString &s2)
Case insensitive comparison of two QStrings.
Definition: TlpQtTools.h:63
QString tlpStringToQString(const std::string &toConvert)
Convert a Tulip UTF-8 encoded std::string to a QString.
Definition: TlpQtTools.h:56
QString getRegisteredTextureFile(QString name)
return the texture file path associated to a name
void clearRegisteredTextureFiles()
forget all registered texture files
A callback class when loading plugins into Tulip.
Definition: PluginLoader.h:41