Tulip  4.6.0
Better Visualization Through Research
library/tulip-gui/include/tulip/TlpQtTools.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 #ifndef _TLPQTTOOLS_H
00021 #define _TLPQTTOOLS_H
00022 
00023 #include <QColor>
00024 #include <QDebug>
00025 
00026 #include <tulip/Color.h>
00027 #include <tulip/tulipconf.h>
00028 #include <tulip/PropertyInterface.h>
00029 
00030 class QWidget;
00031 class QString;
00032 
00033 namespace tlp {
00034 
00035 struct PluginLoader;
00036 
00037 TLP_QT_SCOPE bool getColorDialog(const QColor &color,QWidget *parent,const QString &title,QColor &result);
00038 
00039 inline QColor colorToQColor(const Color& color) {
00040   return QColor(color.getR(), color.getG(), color.getB(), color.getA());
00041 }
00042 inline Color QColorToColor(const QColor& color) {
00043   return Color(color.red(), color.green(), color.blue(), color.alpha());
00044 }
00045 /**
00046   * @brief Convert a string from Tulip to QString.
00047   **/
00048 inline std::string QStringToTlpString(const QString& toConvert) {
00049   return std::string(toConvert.toUtf8());
00050 }
00051 /**
00052   * @brief Convert a QString to tulip string.
00053   **/
00054 inline QString tlpStringToQString(const std::string& toConvert) {
00055   return QString::fromUtf8(toConvert.c_str());
00056 }
00057 
00058 /**
00059  * @brief Case insensitive comparison of two QStrings
00060  **/
00061 inline bool QStringCaseCmp(const QString& s1, const QString& s2) {
00062   return QString::localeAwareCompare(s1, s2) < 0;
00063 }
00064 
00065 
00066 
00067 /**
00068     * @brief Convert the property type string to a label to display in the GUI.
00069     * The property type label is the string to display in the GUI instead of the basic property type string.
00070     * By example for a property of type "double" the label displayed in the GUI will be "Metric".
00071     **/
00072 TLP_QT_SCOPE QString propertyTypeToPropertyTypeLabel(const std::string& typeName);
00073 
00074 /**
00075   * @brief Get the string to display as property type for the given property.
00076   * The property type label is the string to display in the GUI instead of the property type string.
00077   * By example for a property of type "double" the label displayed in the GUI will be "Metric".
00078   **/
00079 inline QString propertyInterfaceToPropertyTypeLabel(const tlp::PropertyInterface* const property) {
00080   return propertyTypeToPropertyTypeLabel(property->getTypename());
00081 }
00082 
00083 /**
00084   * @brief Convert the label of a property type to it's corresponding property type.
00085   * The property type label is the string to display in the GUI instead of the property type string.
00086   * By example for a property of type "double" the label displayed in the GUI will be "Metric".
00087   **/
00088 TLP_QT_SCOPE std::string propertyTypeLabelToPropertyType(const QString& typeNameLabel);
00089 
00090 /**
00091     * @brief Gets the name of the package to retrieve for this version of tulip.
00092     * 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.
00093     *
00094     * @param pluginName The name of the plugin for which we want the package name.
00095     **/
00096 TLP_QT_SCOPE QString getPluginPackageName(const QString& pluginName);
00097 
00098 TLP_QT_SCOPE QString getPluginStagingDirectory();
00099 
00100 TLP_QT_SCOPE QString getPluginLocalInstallationDir();
00101 
00102 TLP_QT_SCOPE QString localPluginsPath();
00103 
00104 /**
00105  @brief Sets up environment when creating an executable using Tulip libraries
00106  This method performs basic operations when starting a software using Tulip:
00107  @list
00108  @li It initializes the tulip library
00109  @li it checks plugins to be discarded and uninstalls them
00110  @li It loads plugins from the application path
00111  @endlist
00112  */
00113 extern TLP_QT_SCOPE void initTulipSoftware(PluginLoader *loader = NULL, bool removeDiscardedPlugins=false);
00114 
00115 /**
00116  * @brief redirect tlp::debug() to qDebug()
00117  */
00118 TLP_QT_SCOPE void redirectDebugOutputToQDebug();
00119 
00120 /**
00121  * @brief redirect tlp::warning() to qWarning()
00122  */
00123 TLP_QT_SCOPE void redirectWarningOutputToQWarning();
00124 
00125 /**
00126  * @brief redirect tlp::error() to qCritical()
00127  */
00128 TLP_QT_SCOPE void redirectErrorOutputToQCritical();
00129 
00130 // Gui test mode
00131 TLP_QT_SCOPE bool inGuiTestingMode();
00132 
00133 TLP_QT_SCOPE void setGuiTestingMode(bool);
00134 
00135 }
00136 
00137 // QDebug extension
00138 inline QDebug operator<<(QDebug dbg, const std::string& s) {
00139   dbg.nospace() << s.c_str();
00140   return dbg.space();
00141 }
00142 
00143 #endif
 All Classes Files Functions Variables Enumerations Enumerator Properties