[Ktutorial-commits] SF.net SVN: ktutorial:[125] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-03-09 02:18:31
|
Revision: 125
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=125&view=rev
Author: danxuliu
Date: 2010-03-09 02:18:24 +0000 (Tue, 09 Mar 2010)
Log Message:
-----------
-Added EditionWidget as base class for widgets that edit data in a tutorial.
-Added EditionDialog class that wraps an EditionWidget and provides "Ok" and "Cancel" buttons.
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/EditionDialog.cpp
trunk/ktutorial/ktutorial-editor/src/view/EditionDialog.h
trunk/ktutorial/ktutorial-editor/src/view/EditionWidget.cpp
trunk/ktutorial/ktutorial-editor/src/view/EditionWidget.h
trunk/ktutorial/ktutorial-editor/tests/unit/view/EditionDialogTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-08 18:47:18 UTC (rev 124)
+++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-03-09 02:18:24 UTC (rev 125)
@@ -1,6 +1,8 @@
include_directories(${KDE4_INCLUDES})
set(ktutorial_editor_view_SRCS
+ EditionDialog.cpp
+ EditionWidget.cpp
StepTreeItem.cpp
TextTreeItem.cpp
TreeItem.cpp
Added: trunk/ktutorial/ktutorial-editor/src/view/EditionDialog.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/EditionDialog.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/EditionDialog.cpp 2010-03-09 02:18:24 UTC (rev 125)
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * 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 "EditionDialog.h"
+
+#include <KLocalizedString>
+
+#include "EditionWidget.h"
+
+//public:
+
+EditionDialog::EditionDialog(EditionWidget* editionWidget, QWidget* parent):
+ KDialog(parent),
+ mEditionWidget(editionWidget) {
+
+ editionWidget->setParent(this);
+
+ setMainWidget(editionWidget);
+ setWindowTitle(editionWidget->windowTitle());
+
+ setModal(true);
+
+ setButtons(KDialog::Ok | KDialog::Cancel);
+}
+
+//protected slots:
+
+void EditionDialog::slotButtonClicked(int button) {
+ if (button == KDialog::Ok) {
+ mEditionWidget->saveChanges();
+ }
+
+ KDialog::slotButtonClicked(button);
+}
Property changes on: trunk/ktutorial/ktutorial-editor/src/view/EditionDialog.cpp
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-editor/src/view/EditionDialog.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/EditionDialog.h (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/EditionDialog.h 2010-03-09 02:18:24 UTC (rev 125)
@@ -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 EDITIONDIALOG_H
+#define EDITIONDIALOG_H
+
+#include <KDialog>
+
+class EditionWidget;
+
+/**
+ * Wrapper dialog for EditionWidgets that provides Ok and Cancel buttons.
+ * When the user clicks the "Ok" button, the changes are saved to the object
+ * being edited by the EditionWidget.
+ *
+ * By default, the dialog is modal and gets its window title from the edition
+ * widget own window title.
+ *
+ * @see EditionWidgdet
+ */
+class EditionDialog: public KDialog {
+Q_OBJECT
+public:
+
+ /**
+ * Creates and shows a new TutorialManagerDialog.
+ * The EditionWidget is reparented to this dialog and destroyed when this
+ * EditionDialog is destroyed.
+ *
+ * @param editionWidget The EditionWidget to wrap.
+ * @param parent The parent widget of this dialog, defaults to null.
+ */
+ explicit EditionDialog(EditionWidget* editionWidget, QWidget* parent = 0);
+
+protected Q_SLOTS:
+
+ /**
+ * Hides the dialog, saving the changes if the button clicked was "Ok"
+ * button.
+ *
+ * @param button The button clicked.
+ */
+ virtual void slotButtonClicked(int button);
+
+private:
+
+ /**
+ * The EditionWidget wrapped.
+ */
+ EditionWidget* mEditionWidget;
+
+};
+
+#endif
Property changes on: trunk/ktutorial/ktutorial-editor/src/view/EditionDialog.h
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-editor/src/view/EditionWidget.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/EditionWidget.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/EditionWidget.cpp 2010-03-09 02:18:24 UTC (rev 125)
@@ -0,0 +1,24 @@
+/***************************************************************************
+ * 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 "EditionWidget.h"
+
+//public:
+
+EditionWidget::EditionWidget(QWidget* parent): QWidget(parent) {
+}
Property changes on: trunk/ktutorial/ktutorial-editor/src/view/EditionWidget.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-editor/src/view/EditionWidget.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/EditionWidget.h (rev 0)
+++ trunk/ktutorial/ktutorial-editor/src/view/EditionWidget.h 2010-03-09 02:18:24 UTC (rev 125)
@@ -0,0 +1,55 @@
+/***************************************************************************
+ * 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 EDITIONWIDGET_H
+#define EDITIONWIDGET_H
+
+#include <QWidget>
+
+/**
+ * Base abstract class for edition widgets.
+ * Widgets mean to edit any data in the tutorial must inherit from this class.
+ * A generic edition dialog with Ok and Cancel buttons is provided by
+ * EditionDialog class. The dialog wraps an EditionWidget and saves the changes
+ * using saveChanges() method when needed.
+ *
+ * Subclasses must implement saveChanges method to commit the changes to the
+ * object being edited.
+ *
+ * @see EditionDialog
+ */
+class EditionWidget: public QWidget {
+Q_OBJECT
+public:
+
+ /**
+ * Creates a new EditionWidget with the given parent.
+ *
+ * @param parent The parent widget.
+ */
+ EditionWidget(QWidget* parent = 0);
+
+ /**
+ * Saves the changes to the object being edited.
+ * This method must be implemented in subclasses.
+ */
+ virtual void saveChanges() = 0;
+
+};
+
+#endif
Property changes on: trunk/ktutorial/ktutorial-editor/src/view/EditionWidget.h
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-08 18:47:18 UTC (rev 124)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt 2010-03-09 02:18:24 UTC (rev 125)
@@ -16,7 +16,7 @@
ENDFOREACH(_className)
ENDMACRO(UNIT_TESTS)
-unit_tests(StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialTreeItem TutorialTreeSelectionManager)
+unit_tests(EditionDialog StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialTreeItem TutorialTreeSelectionManager)
MACRO(MEM_TESTS)
FOREACH(_testname ${ARGN})
@@ -24,4 +24,4 @@
ENDFOREACH(_testname)
ENDMACRO(MEM_TESTS)
-mem_tests(StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialTreeItem TutorialTreeSelectionManager)
+mem_tests(EditionDialog StepTreeItem TextTreeItem TreeItem TreeItemUtil TreeModel TutorialTreeItem TutorialTreeSelectionManager)
Added: trunk/ktutorial/ktutorial-editor/tests/unit/view/EditionDialogTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/EditionDialogTest.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/EditionDialogTest.cpp 2010-03-09 02:18:24 UTC (rev 125)
@@ -0,0 +1,91 @@
+/***************************************************************************
+ * 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 "EditionDialog.h"
+
+#include <KPushButton>
+
+#include "EditionWidget.h"
+
+class EditionDialogTest: public QObject {
+Q_OBJECT
+
+private slots:
+
+ void testConstructor();
+
+ void testOk();
+ void testCancel();
+
+};
+
+class MockEditionWidget: public EditionWidget {
+public:
+
+ int mSaveChangesCallCount;
+
+ MockEditionWidget(QWidget* parent = 0): EditionWidget(parent),
+ mSaveChangesCallCount(0) {
+ setWindowTitle("The edition widget title");
+ }
+
+ virtual void saveChanges() {
+ mSaveChangesCallCount++;
+ }
+
+};
+
+void EditionDialogTest::testConstructor() {
+ EditionWidget* editionWidget = new MockEditionWidget();
+ QWidget parentWidget;
+ EditionDialog* dialog = new EditionDialog(editionWidget, &parentWidget);
+
+ QCOMPARE(dialog->mainWidget(), editionWidget);
+ QCOMPARE(dialog->mainWidget()->parent(), dialog);
+ QCOMPARE(dialog->parentWidget(), &parentWidget);
+ QVERIFY(dialog->isModal());
+ QCOMPARE(dialog->windowTitle(), QString("The edition widget title"));
+ QVERIFY(dialog->button(KDialog::Ok));
+ QVERIFY(dialog->button(KDialog::Cancel));
+}
+
+void EditionDialogTest::testOk() {
+ MockEditionWidget* editionWidget = new MockEditionWidget();
+ EditionDialog dialog(editionWidget);
+
+ dialog.button(KDialog::Ok)->click();
+
+ QCOMPARE(editionWidget->mSaveChangesCallCount, 1);
+ QVERIFY(dialog.isHidden());
+}
+
+void EditionDialogTest::testCancel() {
+ MockEditionWidget* editionWidget = new MockEditionWidget();
+ EditionDialog dialog(editionWidget);
+
+ dialog.button(KDialog::Cancel)->click();
+
+ QCOMPARE(editionWidget->mSaveChangesCallCount, 0);
+ QVERIFY(dialog.isHidden());
+}
+
+QTEST_MAIN(EditionDialogTest)
+
+#include "EditionDialogTest.moc"
Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/view/EditionDialogTest.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|