FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qt_utils.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "occtools.h"
19 
20 #include <Quantity_Color.hxx>
21 #include <Quantity_NameOfColor.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TCollection_ExtendedString.hxx>
24 
25 #include <QtCore/QString>
26 #include <QtGui/QColor>
27 
28 namespace occ {
29 
31 {
32 public:
33  // --- Color conversion
34 
35  static QColor toQColor(const Quantity_Color& c);
36  static QColor toQColor(const Quantity_NameOfColor c);
37  static Quantity_Color toOccColor(const QColor& c);
38  static Quantity_NameOfColor toOccNameOfColor(const QColor& c);
39 
40  // --- String conversion
41 
42  static TCollection_AsciiString toOccLatin1String(const QString& str);
43  static TCollection_AsciiString toOccLocal8BitString(const QString& str);
44  static TCollection_AsciiString toOccUtf8String(const QString& str);
45  static Standard_ExtString toOccExtString(const QString& str);
46  static TCollection_ExtendedString toOccExtendedString(const QString& str);
47 
48  static QString fromLatin1ToQString(const TCollection_AsciiString& str);
49  static QString fromLocal8BitToQString(const TCollection_AsciiString& str);
50  static QString fromUtf8ToQString(const TCollection_AsciiString& str);
51  static QString toQString(Standard_ExtString unicodeStr, int size = -1);
52  static QString toQString(const TCollection_ExtendedString& str);
53 
54  // TODO: add conversion for NCollection_String.hxx
55 
56  template<typename OCC_PNT_VEC>
57  static QString toQString(
58  const OCC_PNT_VEC& pv,
59  const QString& format = QLatin1String("(%x, %y, %z)"),
60  char realFormat = 'g',
61  unsigned prec = 6);
62 };
63 
64 //
65 // --- Implementation
66 //
67 
68 template<typename OCC_PNT_VEC>
70  const OCC_PNT_VEC& pv,
71  const QString& format,
72  char realFormat,
73  unsigned prec)
74 {
75  QString result = format;
76  result.replace(
77  QLatin1String("%x"), QString::number(pv.X(), realFormat, prec));
78  result.replace(
79  QLatin1String("%y"), QString::number(pv.Y(), realFormat, prec));
80  return result.replace(
81  QLatin1String("%z"), QString::number(pv.Z(), realFormat, prec));
82 }
83 
84 } // namespace occ
static QString toQString(Standard_ExtString unicodeStr, int size=-1)
Conversion of the OCC Standard_ExtString str to a QString.
Definition: qt_utils.cpp:106
Definition: qt_utils.h:30
#define OCCTOOLS_EXPORT
Definition: occtools.h:27
Definition: ais_text.cpp:31