[Ktutorial-commits] SF.net SVN: ktutorial:[128] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-03-09 04:33:54
|
Revision: 128
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=128&view=rev
Author: danxuliu
Date: 2010-03-09 04:33:47 +0000 (Tue, 09 Mar 2010)
Log Message:
-----------
Add TutorialInformationWidget to edit the name and description of a tutorial.
Modified Paths:
--------------
trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt
trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt
Added Paths:
-----------
trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.cpp
trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.h
trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui
trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialInformationWidgetTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-09 03:41:25 UTC (rev 127)
+++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-09 04:33:47 UTC (rev 128)
@@ -8,10 +8,15 @@
TreeItem.cpp
TreeItemUtil.cpp
TreeModel.cpp
+ TutorialInformationWidget.cpp
TutorialTreeItem.cpp
TutorialTreeSelectionManager.cpp
)
+kde4_add_ui_files(ktutorial_editor_view_SRCS
+ TutorialInformationWidget.ui
+)
+
kde4_add_library(ktutorial_editor_view ${ktutorial_editor_view_SRCS})
target_link_libraries(ktutorial_editor_view ktutorial_editor ${KDE4_KDEUI_LIBS})
Added: trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.cpp 2010-03-09 04:33:47 UTC (rev 128)
@@ -0,0 +1,51 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Daniel Calviño Sánchez *
+ * dan...@gm... *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+#include "TutorialInformationWidget.h"
+
+#include "ui_TutorialInformationWidget.h"
+#include "../Tutorial.h"
+
+//public:
+
+TutorialInformationWidget::TutorialInformationWidget(Tutorial* tutorial,
+ QWidget* parent):
+ EditionWidget(parent),
+ mTutorial(tutorial) {
+ ui = new Ui::TutorialInformationWidgetUi();
+ ui->setupUi(this);
+
+ ui->nameLineEdit->setText(tutorial->name());
+ ui->descriptionTextEdit->setText(tutorial->description());
+}
+
+TutorialInformationWidget::~TutorialInformationWidget() {
+ delete ui;
+}
+
+void TutorialInformationWidget::saveChanges() {
+ QString name = ui->nameLineEdit->text();
+ if (mTutorial->name() != name) {
+ mTutorial->setName(name);
+ }
+
+ QString description = ui->descriptionTextEdit->toPlainText();
+ if (mTutorial->description() != description) {
+ mTutorial->setDescription(description);
+ }
+}
Property changes on: trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.h (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.h 2010-03-09 04:33:47 UTC (rev 128)
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Daniel Calviño Sánchez *
+ * dan...@gm... *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+#ifndef TUTORIALINFORMATIONWIDGET_H
+#define TUTORIALINFORMATIONWIDGET_H
+
+#include "EditionWidget.h"
+
+class Tutorial;
+
+namespace Ui {
+class TutorialInformationWidgetUi;
+}
+
+/**
+ * Edition widget for the name and description of a Tutorial.
+ */
+class TutorialInformationWidget: public EditionWidget {
+Q_OBJECT
+public:
+
+ /**
+ * Creates a new TutorialInformationWidget for the given Tutorial.
+ *
+ * @param tutorial The tutorial to edit.
+ * @param parent The parent QWidget.
+ */
+ explicit TutorialInformationWidget(Tutorial* tutorial, QWidget* parent = 0);
+
+ /**
+ * Destroys this widget.
+ */
+ virtual ~TutorialInformationWidget();
+
+ /**
+ * Saves the name and description in the tutorial.
+ */
+ virtual void saveChanges();
+
+private:
+
+ /**
+ * The tutorial to edit.
+ */
+ Tutorial* mTutorial;
+
+ /**
+ * The Ui Designer generated class.
+ */
+ Ui::TutorialInformationWidgetUi* ui;
+
+};
+
+#endif
Property changes on: trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.h
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui 2010-03-09 04:33:47 UTC (rev 128)
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TutorialInformationWidgetUi</class>
+ <widget class="QWidget" name="TutorialInformationWidgetUi">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string comment="@title">Set tutorial information</string>
+ </property>
+ <property name="whatsThis">
+ <string comment="@info:whatsthis"><para>Set the name and description of the tutorial.</para><para>The name and the description are shown in the dialog where the tutorial to be started is selected.</para></string>
+ </property>
+ <layout class="QVBoxLayout" name="tutorialInformationWidgetUiLayout">
+ <item>
+ <widget class="QGroupBox" name="tutorialInformationGroupBox">
+ <property name="title">
+ <string comment="@title">Tutorial information</string>
+ </property>
+ <layout class="QVBoxLayout" name="tutorialInformationGroupBoxLayout">
+ <item>
+ <layout class="QHBoxLayout" name="nameLayout">
+ <item>
+ <widget class="QLabel" name="nameLabel">
+ <property name="whatsThis">
+ <string comment="@info:whatsthis">The name to set in the tutorial.</string>
+ </property>
+ <property name="text">
+ <string comment="@label:textbox">Name:</string>
+ </property>
+ <property name="buddy">
+ <cstring>nameLineEdit</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="KLineEdit" name="nameLineEdit"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="descriptionLayout">
+ <item>
+ <widget class="QLabel" name="descriptionLabel">
+ <property name="whatsThis">
+ <string comment="@info:whatsthis">The description to set in the tutorial.</string>
+ </property>
+ <property name="text">
+ <string comment="@label:textbox">Description:</string>
+ </property>
+ <property name="buddy">
+ <cstring>descriptionTextEdit</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="KTextEdit" name="descriptionTextEdit"/>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>KLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>klineedit.h</header>
+ </customwidget>
+ <customwidget>
+ <class>KTextEdit</class>
+ <extends>QTextEdit</extends>
+ <header>ktextedit.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-09 03:41:25 UTC (rev 127)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-09 04:33:47 UTC (rev 128)
@@ -16,7 +16,7 @@
ENDFOREACH(_className)
ENDMACRO(UNIT_TESTS)
-unit_tests(EditionDialog StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialTreeItem TutorialTreeSelectionManager)
+unit_tests(EditionDialog StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager)
MACRO(MEM_TESTS)
FOREACH(_testname ${ARGN})
@@ -24,4 +24,4 @@
ENDFOREACH(_testname)
ENDMACRO(MEM_TESTS)
-mem_tests(EditionDialog StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialTreeItem TutorialTreeSelectionManager)
+mem_tests(EditionDialog StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager)
Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialInformationWidgetTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialInformationWidgetTest.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialInformationWidgetTest.cpp 2010-03-09 04:33:47 UTC (rev 128)
@@ -0,0 +1,88 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Daniel Calviño Sánchez *
+ * dan...@gm... *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+#include <QtTest>
+
+#include "TutorialInformationWidget.h"
+
+#include <KLineEdit>
+#include <KTextEdit>
+
+#include "../Tutorial.h"
+
+class TutorialInformationWidgetTest: public QObject {
+Q_OBJECT
+
+private slots:
+
+ void testConstructor();
+
+ void testSaveChanges();
+
+private:
+
+ KLineEdit* nameLineEdit(TutorialInformationWidget* widget) const;
+ KTextEdit* descriptionTextEdit(TutorialInformationWidget* widget) const;
+
+};
+
+void TutorialInformationWidgetTest::testConstructor() {
+ Tutorial tutorial;
+ tutorial.setName("The name");
+ tutorial.setDescription("The description");
+
+ QWidget parent;
+ TutorialInformationWidget* widget = new TutorialInformationWidget(&tutorial,
+ &parent);
+
+ QCOMPARE(widget->parentWidget(), &parent);
+ QCOMPARE(nameLineEdit(widget)->text(), QString("The name"));
+ QCOMPARE(descriptionTextEdit(widget)->toPlainText(),
+ QString("The description"));
+}
+
+void TutorialInformationWidgetTest::testSaveChanges() {
+ Tutorial tutorial;
+ tutorial.setName("The name");
+ tutorial.setDescription("The description");
+
+ TutorialInformationWidget widget(&tutorial);
+ nameLineEdit(&widget)->setText("The new name");
+ descriptionTextEdit(&widget)->setText("The new description");
+
+ widget.saveChanges();
+
+ QCOMPARE(tutorial.name(), QString("The new name"));
+ QCOMPARE(tutorial.description(), QString("The new description"));
+}
+
+/////////////////////////////////// Helpers ////////////////////////////////////
+
+KLineEdit* TutorialInformationWidgetTest::nameLineEdit(
+ TutorialInformationWidget* widget) const {
+ return widget->findChild<KLineEdit*>("nameLineEdit");
+}
+
+KTextEdit* TutorialInformationWidgetTest::descriptionTextEdit(
+ TutorialInformationWidget* widget) const {
+ return widget->findChild<KTextEdit*>("descriptionTextEdit");
+}
+
+QTEST_MAIN(TutorialInformationWidgetTest)
+
+#include "TutorialInformationWidgetTest.moc"
Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialInformationWidgetTest.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|