Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
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
26#include <tulip/Color.h>
27#include <tulip/tulipconf.h>
28#include <tulip/PropertyInterface.h>
29
30class QWidget;
31class QString;
32
33namespace tlp {
34
35struct PluginLoader;
36
37TLP_QT_SCOPE bool getColorDialog(const QColor &color, QWidget *parent, const QString &title,
38 QColor &result);
39
40inline QColor colorToQColor(const Color &color) {
41 return QColor(color.getR(), color.getG(), color.getB(), color.getA());
42}
43inline Color QColorToColor(const QColor &color) {
44 return Color(color.red(), color.green(), color.blue(), color.alpha());
45}
46/**
47 * @brief Convert a QString to a Tulip UTF-8 encoded std::string.
48 **/
49inline std::string QStringToTlpString(const QString &toConvert) {
50 return std::string(toConvert.toUtf8());
51}
52/**
53 * @brief Convert a Tulip UTF-8 encoded std::string to a QString
54 **/
55inline QString tlpStringToQString(const std::string &toConvert) {
56 return QString::fromUtf8(toConvert.c_str());
57}
58
59/**
60 * @brief Case insensitive comparison of two QStrings
61 **/
62inline bool QStringCaseCmp(const QString &s1, const QString &s2) {
63 return QString::localeAwareCompare(s1, s2) < 0;
64}
65
66/**
67 * @brief Convert the property type string to a label to display in the GUI.
68 * The property type label is the string to display in the GUI instead of the basic property type
69 *string.
70 **/
71TLP_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 **/
78inline QString propertyInterfaceToPropertyTypeLabel(const tlp::PropertyInterface *const property) {
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 **/
87TLP_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,
92 *x86_64), and compiler used (GCC, Clang, MSVC) to determine which package this version can use.
93 *
94 * @param pluginName The name of the plugin for which we want the package name.
95 **/
96TLP_QT_SCOPE QString getPluginPackageName(const QString &pluginName);
97
98TLP_QT_SCOPE QString getPluginStagingDirectory();
99
100TLP_QT_SCOPE QString getPluginLocalInstallationDir();
101
102TLP_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 */
113extern TLP_QT_SCOPE void initTulipSoftware(PluginLoader *loader = nullptr,
114 bool removeDiscardedPlugins = false);
115
116/**
117 * @brief redirect tlp::debug() to qDebug()
118 */
119TLP_QT_SCOPE void redirectDebugOutputToQDebug();
120
121/**
122 * @brief redirect tlp::warning() to qWarning()
123 */
125
126/**
127 * @brief redirect tlp::error() to qCritical()
128 */
130
131TLP_QT_SCOPE void disableQtUserInput();
132
133TLP_QT_SCOPE void enableQtUserInput();
134
135/**
136 * @brief convert sql like filter into an acceptable regexp
137 */
138TLP_QT_SCOPE void convertLikeFilter(QString &filter);
139
140/**
141 * @brief associate a texture file path to a name
142 */
143TLP_QT_SCOPE void registerTextureFile(QString name, QString textureFilePath);
144
145/**
146 * @brief return the texture file path associated to a name
147 */
148TLP_QT_SCOPE QString getRegisteredTextureFile(QString name);
149
150/**
151 * @brief forget all registered texture files
152 */
153TLP_QT_SCOPE void clearRegisteredTextureFiles();
154
155} // namespace tlp
156
157// QDebug extension
158inline QDebug operator<<(QDebug dbg, const std::string &s) {
159 dbg.nospace() << s.c_str();
160 return dbg.space();
161}
162
163// Qt 5.15 warning fix
164#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
165#define QT_ENDL endl
166#else
167#define QT_ENDL Qt::endl
168#endif
169
170// useful macros needed for menu actions building
171#ifdef __APPLE__
172#define SET_TOOLTIP_WITH_CTRL_SHORTCUT(a, tt, sc) \
173 a->setToolTip(QString(tt) + tlpStringToQString(" [⌘+") + sc + "]")
174#else
175#define SET_TOOLTIP_WITH_CTRL_SHORTCUT(a, tt, sc) a->setToolTip(QString(tt) + " [Ctrl+" + sc + "]")
176#endif
177
178#define SET_TIPS_WITH_CTRL_SHORTCUT(a, tt, sc) \
179 SET_TOOLTIP_WITH_CTRL_SHORTCUT(a, tt, sc); \
180 a->setStatusTip(a->toolTip())
181
182#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:78
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:49
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:62
QString tlpStringToQString(const std::string &toConvert)
Convert a Tulip UTF-8 encoded std::string to a QString.
Definition: TlpQtTools.h:55
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