Kaynağa Gözat

Add qtHandleToString convenient function to ctkUtils

* For more details about Qt::HANDLE: http://doc.qt.nokia.com/latest/qt.html#HANDLE-typedef
Jean-Christophe Fillion-Robin 13 yıl önce
ebeveyn
işleme
f230f34ab0

+ 2 - 0
Libs/Core/Testing/Cpp/CMakeLists.txt

@@ -35,6 +35,7 @@ SET(KITTests_SRCS
   ctkModelTesterTest2.cpp
   ctkUtilsClosestPowerOfTenTest1.cpp
   ctkUtilsOrderOfMagnitudeTest1.cpp
+  ctkUtilsQtHandleToStringTest1.cpp
   ctkUtilsSignificantDecimalsTest1.cpp
   ctkUtilsTest1.cpp
   ctkUtilsTest2.cpp
@@ -148,6 +149,7 @@ SIMPLE_TEST( ctkTransferFunctionRepresentationTest1 )
 SIMPLE_TEST( ctkTransferFunctionRepresentationTest2 )
 SIMPLE_TEST( ctkUtilsClosestPowerOfTenTest1 )
 SIMPLE_TEST( ctkUtilsOrderOfMagnitudeTest1 )
+SIMPLE_TEST( ctkUtilsQtHandleToStringTest1 )
 SIMPLE_TEST( ctkUtilsSignificantDecimalsTest1 )
 SIMPLE_TEST( ctkUtilsTest1 )
 SIMPLE_TEST( ctkUtilsTest2 )

+ 68 - 0
Libs/Core/Testing/Cpp/ctkUtilsQtHandleToStringTest1.cpp

@@ -0,0 +1,68 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QDebug>
+#include <QTextStream>
+
+// CTK includes
+#include "ctkUtils.h"
+
+// STD includes
+#include <cstdlib>
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkUtilsQtHandleToStringTest1(int argc, char * argv [] )
+{
+  Q_UNUSED(argc);
+  Q_UNUSED(argv);
+
+  //#if defined(Q_WS_MAC)
+  //  typedef void * HANDLE;
+  //#elif defined(Q_WS_WIN)
+  //  typedef void *HANDLE;
+  //#elif defined(Q_WS_X11)
+  //  typedef unsigned long HANDLE;
+  //#elif defined(Q_WS_QWS)
+  //  typedef void * HANDLE;
+  //#elif defined(Q_OS_SYMBIAN)
+  // typedef unsigned long int HANDLE; // equivalent to TUint32
+  //#endif
+
+  {
+  unsigned long handle = 1234;
+  QString str;
+  QTextStream s(&str);
+  s << handle;
+  //std::cout << "handle:" << qPrintable(str) << std::endl;
+  }
+
+  {
+  int foo = 0;
+  void * handle = &foo;
+  QString str;
+  QTextStream s(&str);
+  s << handle;
+  //std::cout << "handle:" << qPrintable(str) << std::endl;
+  }
+
+  return EXIT_SUCCESS;
+}

+ 9 - 0
Libs/Core/ctkUtils.cpp

@@ -305,3 +305,12 @@ bool ctk::removeDirRecursively(const QString & dirName)
 
   return result;
 }
+
+//-----------------------------------------------------------------------------
+QString ctk::qtHandleToString(Qt::HANDLE handle)
+{
+  QString str;
+  QTextStream s(&str);
+  s << handle;
+  return str;
+}

+ 5 - 0
Libs/Core/ctkUtils.h

@@ -116,6 +116,11 @@ double CTK_CORE_EXPORT closestPowerOfTen(double value);
 /// \sa QDir::rmdir
 bool CTK_CORE_EXPORT removeDirRecursively(const QString & dirName);
 
+///
+/// \ingroup Core
+/// Convert Qt::HANDLE to string
+/// \sa Qt::HANDLE
+QString CTK_CORE_EXPORT qtHandleToString(Qt::HANDLE handle);
 }
 
 #endif