Ver código fonte

Add file templates for a widget class

Julien Finet 14 anos atrás
pai
commit
2a22430d76

+ 68 - 0
Libs/Widgets/Plugins/ctkTemplateWidgetPlugin.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.
+
+=========================================================================*/
+
+// CTK includes
+#include "ctkTemplateWidgetPlugin.h"
+#include "ctkTemplateWidget.h"
+
+//-----------------------------------------------------------------------------
+ctkTemplateWidgetPlugin::ctkTemplateWidgetPlugin(QObject* parentObject)
+  : QObject(parentObject)
+{
+}
+
+//-----------------------------------------------------------------------------
+QWidget* ctkTemplateWidgetPlugin::createWidget(QWidget* parentWidget)
+{
+  ctkTemplateWidget* newWidget = new ctkTemplateWidget(parentWidget);
+  return newWidget;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkTemplateWidgetPlugin::domXml() const
+{
+  return "<widget class=\"ctkTemplateWidget\" \
+          name=\"TemplateWidget\">\n"
+          "</widget>\n";
+}
+
+//-----------------------------------------------------------------------------
+QIcon ctkTemplateWidgetPlugin::icon() const
+{
+  return QIcon(":/Icons/pushbutton.png");
+}
+
+//-----------------------------------------------------------------------------
+QString ctkTemplateWidgetPlugin::includeFile() const
+{
+  return "ctkTemplateWidget.h";
+}
+
+//-----------------------------------------------------------------------------
+bool ctkTemplateWidgetPlugin::isContainer() const
+{
+  return false;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkTemplateWidgetPlugin::name() const
+{
+  return "ctkTemplateWidget";
+}

+ 44 - 0
Libs/Widgets/Plugins/ctkTemplateWidgetPlugin.h

@@ -0,0 +1,44 @@
+/*=========================================================================
+
+  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.
+
+=========================================================================*/
+
+#ifndef __ctkTemplateWidgetPlugin_h
+#define __ctkTemplateWidgetPlugin_h
+
+// CTK includes
+#include "ctkWidgetsAbstractPlugin.h"
+
+class CTK_WIDGETS_PLUGINS_EXPORT ctkTemplateWidgetPlugin
+  : public QObject
+  , public ctkWidgetsAbstractPlugin
+{
+  Q_OBJECT
+
+public:
+  ctkTemplateWidgetPlugin(QObject *_parent = 0);
+  
+  QWidget *createWidget(QWidget *_parent);
+  QString  domXml() const;
+  QIcon    icon() const;
+  QString  includeFile() const;
+  bool     isContainer() const;
+  QString  name() const;
+};
+
+#endif

+ 19 - 0
Libs/Widgets/Resources/UI/ctkTemplateWidget.ui

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkTemplateWidget</class>
+ <widget class="QWidget" name="ctkTemplateWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>200</width>
+    <height>200</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Template Widget</string>
+  </property>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 56 - 0
Libs/Widgets/Testing/Cpp/ctkTemplateWidgetTest1.cpp

@@ -0,0 +1,56 @@
+/*=========================================================================
+
+  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 <QApplication>
+#include <QSignalSpy>
+#include <QTimer>
+
+// CTK includes
+#include "ctkTemplateWidget.h"
+
+// STD includes
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkTemplateWidgetTest1(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  ctkTemplateWidget templateWidget;
+  
+  QSignalSpy spy(&templateWidget, SIGNAL(propertyChanged()));
+  //do something to trigger the signal
+  if (spy.count() != 1)
+    {
+    std::cerr << "ctkTemplateWidget::setProperty(): "
+              << spy.count() << std::endl;
+    return EXIT_FAILURE;
+    }
+  spy.clear();
+
+  templateWidget.show();
+  if (argc < 2 || QString(argv[1]) != "-I" )
+    {
+    QTimer::singleShot(200, &app, SLOT(quit()));
+    }
+  return app.exec();
+}
+

+ 67 - 0
Libs/Widgets/ctkTemplateWidget.cpp

@@ -0,0 +1,67 @@
+/*=========================================================================
+
+  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>
+
+// CTK includes
+#include "ctkTemplateWidget.h"
+#include "ui_ctkTemplateWidget.h"
+#include "ctkLogger.h"
+
+static ctkLogger logger("org.commontk.libs.widgets.ctkTemplateWidget");
+
+//-----------------------------------------------------------------------------
+class ctkTemplateWidgetPrivate: public Ui_ctkTemplateWidget
+{
+  Q_DECLARE_PUBLIC(ctkTemplateWidget);
+protected:
+  ctkTemplateWidget* const q_ptr;
+public:
+  ctkTemplateWidgetPrivate(ctkTemplateWidget& object);
+  void init();
+};
+
+// --------------------------------------------------------------------------
+ctkTemplateWidgetPrivate::ctkTemplateWidgetPrivate(ctkTemplateWidget& object)
+  :q_ptr(&object)
+{
+}
+
+// --------------------------------------------------------------------------
+void ctkTemplateWidgetPrivate::init()
+{
+  Q_Q(ctkTemplateWidgetPrivate);
+  this->setupUi(q);
+}
+
+// --------------------------------------------------------------------------
+ctkTemplateWidget::ctkTemplateWidget(QWidget* parentWidget)
+  : Superclass(parentWidget)
+  , d_ptr(new ctkTemplateWidgetPrivate(*this))
+{
+  Q_D(ctkTemplateWidget);
+  d->init();
+}
+
+// --------------------------------------------------------------------------
+ctkTemplateWidget::~ctkTemplateWidget()
+{
+}

+ 61 - 0
Libs/Widgets/ctkTemplateWidget.h

@@ -0,0 +1,61 @@
+/*=========================================================================
+
+  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.
+
+=========================================================================*/
+
+#ifndef __ctkTemplateWidget_h
+#define __ctkTemplateWidget_h
+
+// Qt includes
+#include <QWidget>
+
+// CTK includes
+#include "ctkWidgetsExport.h"
+class ctkTemplateWidgetPrivate;
+
+///
+/// ctkTemplateWidget allows the user to ...
+class CTK_WIDGETS_EXPORT ctkTemplateWidget : public QWidget
+{
+  Q_OBJECT
+
+public:
+  /// Superclass typedef
+  typedef QWidget Superclass;
+
+  /// Constructor
+  /// If \li parent is null, ctkTemplateWidget will be a top-level widget
+  /// \note The \li parent can be set later using QWidget::setParent()
+  explicit ctkTemplateWidget(QWidget* parent = 0);
+  
+  /// Destructor
+  virtual ~ctkTemplateWidget();
+
+public slots:
+
+signals:
+
+protected:
+  QScopedPointer<ctkTemplateWidgetPrivate> d_ptr;
+
+private:
+  Q_DECLARE_PRIVATE(ctkTemplateWidget);
+  Q_DISABLE_COPY(ctkTemplateWidget);
+};
+
+#endif