[Ktutorial-commits] SF.net SVN: ktutorial:[159] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-03-16 00:16:39
|
Revision: 159
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=159&view=rev
Author: danxuliu
Date: 2010-03-16 00:16:31 +0000 (Tue, 16 Mar 2010)
Log Message:
-----------
-Fix adding and removing the root WaitForTreeItem when the root WaitFor was added or removed.
-Fix disabling add button when the root WaitFor was added or when a negated WaitFor was added to a WaitForNot.
-Fix cancelling the addWaitFor dialog.
-Fix the window title for the addWaitFor dialog.
Modified Paths:
--------------
trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp
trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h
trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2010-03-15 19:02:05 UTC (rev 158)
+++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp 2010-03-16 00:16:31 UTC (rev 159)
@@ -64,14 +64,15 @@
//private:
void WaitForWidget::setupTreeView(WaitFor* waitFor) {
- TextTreeItem* rootItem = new TextTreeItem();
+ mRootItem = new TextTreeItem();
if (waitFor) {
- TreeItem* item = WaitForTreeItem::treeItemForWaitFor(waitFor, rootItem);
- rootItem->appendChild(item);
+ TreeItem* item = WaitForTreeItem::treeItemForWaitFor(waitFor,
+ mRootItem);
+ mRootItem->appendChild(item);
}
QTreeView* treeView = ui->waitForTreeView;
- TreeModel* model = new TreeModel(rootItem, treeView);
+ TreeModel* model = new TreeModel(mRootItem, treeView);
QAbstractItemModel* oldModel = treeView->model();
treeView->setModel(model);
@@ -156,14 +157,26 @@
KDialog* dialog = new KDialog(this);
NewWaitForWidget* widget = new NewWaitForWidget(dialog);
dialog->setMainWidget(widget);
+ dialog->setWindowTitle(widget->windowTitle());
dialog->setObjectName("addWaitForDialog");
if (dialog->exec() == QDialog::Accepted) {
newWaitFor = widget->waitFor();
}
dialog->deleteLater();
+ if (!newWaitFor) {
+ return;
+ }
+
if (!mWaitFor) {
+ ui->addButton->setEnabled(false);
+
+ TreeItem* item = WaitForTreeItem::treeItemForWaitFor(newWaitFor,
+ mRootItem);
+ mRootItem->appendChild(item);
+
mWaitFor = newWaitFor;
+
return;
}
@@ -176,6 +189,8 @@
}
if (qobject_cast<WaitForNot*>(mCurrentWaitFor)) {
+ ui->addButton->setEnabled(false);
+
WaitForNot* waitForNot = static_cast<WaitForNot*>(mCurrentWaitFor);
waitForNot->setNegatedWaitFor(newWaitFor);
@@ -208,6 +223,10 @@
delete mWaitFor;
mWaitFor = 0;
+ TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
+ mRootItem->removeChild(item);
+ delete item;
+
return;
}
Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h 2010-03-15 19:02:05 UTC (rev 158)
+++ trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.h 2010-03-16 00:16:31 UTC (rev 159)
@@ -22,6 +22,7 @@
#include <QWidget>
class QItemSelection;
+class TreeItem;
class WaitFor;
namespace Ui {
@@ -81,6 +82,13 @@
WaitFor* mCurrentWaitFor;
/**
+ * The root tree item in the tree view.
+ * It provides the header in the tree view, and acts as parent item for the
+ * tree item that represents mWaitFor.
+ */
+ TreeItem* mRootItem;
+
+ /**
* The Ui Designer generated class.
*/
Ui::WaitForWidget* ui;
@@ -113,7 +121,10 @@
/**
* Shows a dialog with a NewWaitForWidget and adds the new WaitFor.
* The WaitFor is added to the selected WaitFor, or as the root WaitFor if
- * there is none.
+ * there is none (a new WaitForTreeItem is also added in that case).
+ *
+ * When a WaitFor is added the selection doesn't change, so some buttons are
+ * updated as needed.
*/
void addWaitFor();
@@ -124,6 +135,8 @@
/**
* Removes the selected WaitFor.
+ * If the root WaitFor is removed, its tree item is also removed from the
+ * root item.
*/
void removeWaitFor();
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp 2010-03-15 19:02:05 UTC (rev 158)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/WaitForWidgetTest.cpp 2010-03-16 00:16:31 UTC (rev 159)
@@ -36,6 +36,7 @@
public slots:
void addWaitForSignal() const;
+ void cancelAddWaitForDialog() const;
void setSignalData() const;
@@ -57,6 +58,7 @@
void testAddWaitForWhenEmpty();
void testAddWaitForToWaitForComposed();
void testAddWaitForToWaitForNot();
+ void testAddWaitForCancellingDialog();
void testEditWaitForSignal();
@@ -189,6 +191,9 @@
QVERIFY(mWidget->waitFor());
QVERIFY(qobject_cast<WaitForSignal*>(mWidget->waitFor()));
+ QVERIFY(getIndex(0).isValid());
+ //No item is selected after adding the WaitFor
+ assertButtonEnabled(false, false, false);
delete mWidget->waitFor();
}
@@ -235,8 +240,28 @@
QCOMPARE(mWaitFor->waitFors()[2], mWaitFor3);
QCOMPARE(mWaitFor->waitFors()[3], mWaitFor4);
QVERIFY(qobject_cast<WaitForSignal*>(mWaitFor4->negatedWaitFor()));
+ //The WaitForNot item is selected after adding the negated WaitFor, so "Add"
+ //button must be disabled
+ assertButtonEnabled(false, false, true);
}
+void WaitForWidgetTest::testAddWaitForCancellingDialog() {
+ delete mWidget;
+ mWidget = new WaitForWidget(0);
+
+ //The dialog is modal, so it won't return to the test code until it is
+ //closed. Thus, the commands to execute on the dialog must be "queued",
+ //as calling cancelAddWaitForDialog after the button click won't work.
+ QTimer::singleShot(500, this, SLOT(cancelAddWaitForDialog()));
+
+ button("addButton")->click();
+
+ QVERIFY(!mWidget->waitFor());
+ QVERIFY(!getIndex(0).isValid());
+ //Buttons shouldn't change after cancelling the dialog
+ assertButtonEnabled(true, false, false);
+}
+
void WaitForWidgetTest::testEditWaitForSignal() {
selectItem(getIndex(0, getIndex(0)));
@@ -260,6 +285,8 @@
button("removeButton")->click();
QVERIFY(!mWidget->waitFor());
+ QVERIFY(!getIndex(0).isValid());
+ assertButtonEnabled(true, false, false);
}
void WaitForWidgetTest::testRemoveWaitForFromWaitForComposed() {
@@ -296,6 +323,12 @@
dialog->button(KDialog::Ok)->click();
}
+void WaitForWidgetTest::cancelAddWaitForDialog() const {
+ KDialog* dialog = mWidget->findChild<KDialog*>("addWaitForDialog");
+ QVERIFY(dialog);
+ dialog->button(KDialog::Cancel)->click();
+}
+
void WaitForWidgetTest::setSignalData() const {
KLineEdit* emitterNameLineEdit =
mWidget->findChild<KLineEdit*>("emitterNameLineEdit");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|