[Ktutorial-commits] SF.net SVN: ktutorial:[130] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-09 05:25:35
|
Revision: 130 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=130&view=rev Author: danxuliu Date: 2010-03-09 05:25:28 +0000 (Tue, 09 Mar 2010) Log Message: ----------- Add StepDataWidget to edit the id and text of a step. 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/StepDataWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.h trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.ui trunk/ktutorial/ktutorial-editor/tests/unit/view/StepDataWidgetTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-09 04:53:34 UTC (rev 129) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-09 05:25:28 UTC (rev 130) @@ -3,6 +3,7 @@ set(ktutorial_editor_view_SRCS EditionDialog.cpp EditionWidget.cpp + StepDataWidget.cpp StepTreeItem.cpp TextTreeItem.cpp TreeItem.cpp @@ -14,6 +15,7 @@ ) kde4_add_ui_files(ktutorial_editor_view_SRCS + StepDataWidget.ui TutorialInformationWidget.ui ) Added: trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.cpp 2010-03-09 05:25:28 UTC (rev 130) @@ -0,0 +1,50 @@ +/*************************************************************************** + * 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 "StepDataWidget.h" + +#include "ui_StepDataWidget.h" +#include "../Step.h" + +//public: + +StepDataWidget::StepDataWidget(Step* step, QWidget* parent): + EditionWidget(parent), + mStep(step) { + ui = new Ui::StepDataWidget(); + ui->setupUi(this); + + ui->idLineEdit->setText(step->id()); + ui->textTextEdit->setText(step->text()); +} + +StepDataWidget::~StepDataWidget() { + delete ui; +} + +void StepDataWidget::saveChanges() { + QString id = ui->idLineEdit->text(); + if (mStep->id() != id) { + mStep->setId(id); + } + + QString text = ui->textTextEdit->toPlainText(); + if (mStep->text() != text) { + mStep->setText(text); + } +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.h 2010-03-09 05:25:28 UTC (rev 130) @@ -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 STEPDATAWIDGET_H +#define STEPDATAWIDGET_H + +#include "EditionWidget.h" + +class Step; + +namespace Ui { +class StepDataWidget; +} + +/** + * Edition widget for the id and text of a Step. + */ +class StepDataWidget: public EditionWidget { +Q_OBJECT +public: + + /** + * Creates a new StepDataWidget for the given Step. + * + * @param step The step to edit. + * @param parent The parent QWidget. + */ + explicit StepDataWidget(Step* step, QWidget* parent = 0); + + /** + * Destroys this widget. + */ + virtual ~StepDataWidget(); + + /** + * Saves the id and text in the step. + */ + virtual void saveChanges(); + +private: + + /** + * The step to edit. + */ + Step* mStep; + + /** + * The Ui Designer generated class. + */ + Ui::StepDataWidget* ui; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.ui (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/StepDataWidget.ui 2010-03-09 05:25:28 UTC (rev 130) @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>StepDataWidget</class> + <widget class="QWidget" name="StepDataWidget"> + <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 step data</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><para>Set the id and the text of the step</para> +<para>The text is shown to the user when the tutorial changes to that step.</para> +<para>On the other hand, the id is only used internally and never shown to the user. It is used to tell the tutorial which is the next step to change to.</para></string> + </property> + <layout class="QVBoxLayout" name="StepDataWidgetLayout"> + <item> + <widget class="QGroupBox" name="stepDataGroupBox"> + <property name="title"> + <string comment="@title">Step data</string> + </property> + <layout class="QVBoxLayout" name="stepDataGroupBoxLayout"> + <item> + <layout class="QHBoxLayout" name="idLayout"> + <item> + <widget class="QLabel" name="idLabel"> + <property name="text"> + <string comment="@label:textbox">Id:</string> + </property> + <property name="buddy"> + <cstring>idLineEdit</cstring> + </property> + </widget> + </item> + <item> + <widget class="KLineEdit" name="idLineEdit"/> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="textLayout"> + <item> + <widget class="QLabel" name="textLabel"> + <property name="text"> + <string comment="@label:textbox">Text:</string> + </property> + <property name="buddy"> + <cstring>textTextEdit</cstring> + </property> + </widget> + </item> + <item> + <widget class="KTextEdit" name="textTextEdit"/> + </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 04:53:34 UTC (rev 129) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-09 05:25:28 UTC (rev 130) @@ -16,7 +16,7 @@ ENDFOREACH(_className) ENDMACRO(UNIT_TESTS) -unit_tests(EditionDialog StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager) +unit_tests(EditionDialog StepDataWidget 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 TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager) +mem_tests(EditionDialog StepDataWidget StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialInformationWidget TutorialTreeItem TutorialTreeSelectionManager) Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/StepDataWidgetTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/view/StepDataWidgetTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/view/StepDataWidgetTest.cpp 2010-03-09 05:25:28 UTC (rev 130) @@ -0,0 +1,84 @@ +/*************************************************************************** + * 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 "StepDataWidget.h" + +#include <KLineEdit> +#include <KTextEdit> + +#include "../Step.h" + +class StepDataWidgetTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testSaveChanges(); + +private: + + KLineEdit* idLineEdit(StepDataWidget* widget) const; + KTextEdit* textTextEdit(StepDataWidget* widget) const; + +}; + +void StepDataWidgetTest::testConstructor() { + Step step; + step.setId("The id"); + step.setText("The text"); + + QWidget parent; + StepDataWidget* widget = new StepDataWidget(&step, &parent); + + QCOMPARE(widget->parentWidget(), &parent); + QCOMPARE(idLineEdit(widget)->text(), QString("The id")); + QCOMPARE(textTextEdit(widget)->toPlainText(), QString("The text")); +} + +void StepDataWidgetTest::testSaveChanges() { + Step step; + step.setId("The id"); + step.setText("The text"); + + StepDataWidget widget(&step); + idLineEdit(&widget)->setText("The new id"); + textTextEdit(&widget)->setText("The new text"); + + widget.saveChanges(); + + QCOMPARE(step.id(), QString("The new id")); + QCOMPARE(step.text(), QString("The new text")); +} + +/////////////////////////////////// Helpers //////////////////////////////////// + +KLineEdit* StepDataWidgetTest::idLineEdit(StepDataWidget* widget) const { + return widget->findChild<KLineEdit*>("idLineEdit"); +} + +KTextEdit* StepDataWidgetTest::textTextEdit(StepDataWidget* widget) const { + return widget->findChild<KTextEdit*>("textTextEdit"); +} + +QTEST_MAIN(StepDataWidgetTest) + +#include "StepDataWidgetTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/StepDataWidgetTest.cpp ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |