diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-05-21 17:34:41 -0400 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-05-21 17:34:41 -0400 |
| commit | ba4f9b599069b93d2c73e13b43493da5bfe9b40e (patch) | |
| tree | 33ae8f45b810d751e292a8a303dd878b0a15d7a5 | |
| parent | 1c40145b3bfc2c1310bb126b5d876168dc3919cd (diff) | |
Add method for getting the game for an index instead of only the current index
| -rw-r--r-- | sigmodr/SigmodrUI.cpp | 24 | ||||
| -rw-r--r-- | sigmodr/tree/TreeWidget.cpp | 10 | ||||
| -rw-r--r-- | sigmodr/tree/TreeWidget.h | 3 |
3 files changed, 19 insertions, 18 deletions
diff --git a/sigmodr/SigmodrUI.cpp b/sigmodr/SigmodrUI.cpp index 53a70d17..72e452cc 100644 --- a/sigmodr/SigmodrUI.cpp +++ b/sigmodr/SigmodrUI.cpp @@ -164,13 +164,11 @@ void SigmodrUI::resizeEvent(QResizeEvent* event) void SigmodrUI::setChangedTitle(const bool changed) { - setCaption(treeSigmod->description(treeSigmod->currentIndex()), changed); + setCaption(treeSigmod->description(m_editedIndex), changed); } void SigmodrUI::setDirty(const bool dirty) { - const Game* game = treeSigmod->currentGame(); - treeSigmod->setDirty(game, dirty); setChangedTitle(dirty); actionCollection()->action("file_save")->setEnabled(dirty); } @@ -252,7 +250,7 @@ bool SigmodrUI::openGame(const QString& path, const bool isRemote) void SigmodrUI::saveGame() { - saveGame(treeSigmod->currentGame()); + saveGame(treeSigmod->game(treeSigmod->currentIndex())); } void SigmodrUI::saveGame(const Game* game) @@ -305,7 +303,7 @@ bool SigmodrUI::saveGame(const Game* game, const KUrl& url) void SigmodrUI::saveAsGame() { - saveAsGame(treeSigmod->currentGame()); + saveAsGame(treeSigmod->game(treeSigmod->currentIndex())); } void SigmodrUI::saveAsGame(const Game* game) @@ -330,7 +328,7 @@ void SigmodrUI::downloadGame() void SigmodrUI::uploadGame() { - uploadGame(treeSigmod->currentGame()); + uploadGame(treeSigmod->game(treeSigmod->currentIndex())); } void SigmodrUI::uploadGame(const Game* game) @@ -383,7 +381,7 @@ bool SigmodrUI::closeWidget() void SigmodrUI::closeGame() { - closeGame(treeSigmod->currentGame()); + closeGame(treeSigmod->game(treeSigmod->currentIndex())); setChangedTitle(treeSigmod->dirty()); } @@ -484,19 +482,23 @@ void SigmodrUI::on_treeSigmod_clicked(const QModelIndex& index) connect(editor, SIGNAL(saved()), this, SLOT(setDirty())); connect(buttonApply, SIGNAL(clicked()), editor, SLOT(apply())); connect(buttonReset, SIGNAL(clicked()), editor, SLOT(discard())); - setChangedTitle(treeSigmod->dirty(treeSigmod->currentGame())); + m_editedIndex = index; + setChangedTitle(treeSigmod->dirty(treeSigmod->game(index))); formPanel->setWidget(editor); formPanel->show(); - m_editedIndex = index; } break; } case 2: if ((m_editedIndex.internalId() != index.internalId()) || closeWidget()) - treeSigmod->model()->removeRow(index.row(), index.parent()); + { + if (treeSigmod->model()->removeRow(index.row(), index.parent())) + setDirty(); + } break; case 3: - treeSigmod->model()->insertRow(treeSigmod->model()->rowCount(index), index); + if (treeSigmod->model()->insertRow(treeSigmod->model()->rowCount(index), index)) + setDirty(); break; default: break; diff --git a/sigmodr/tree/TreeWidget.cpp b/sigmodr/tree/TreeWidget.cpp index fb7102dc..f1b46e5c 100644 --- a/sigmodr/tree/TreeWidget.cpp +++ b/sigmodr/tree/TreeWidget.cpp @@ -65,11 +65,6 @@ ObjectUI* TreeWidget::editorWidget(const QModelIndex& index) return widget; } -const Game* TreeWidget::currentGame() const -{ - return qobject_cast<TreeModel*>(model())->findGame(currentIndex()); -} - // QDomDocument TreeWidget::copy(const QModelIndex& index) // { // QDomDocument xml; @@ -82,6 +77,11 @@ const Game* TreeWidget::currentGame() const // model()->setData(index, data.toString(), BaseModel::XmlRole); // } // +const Game* TreeWidget::game(const QModelIndex& index) const +{ + return qobject_cast<TreeModel*>(model())->findGame(index); +} + QList<const Game*> TreeWidget::openedGames() const { return m_games.keys(); diff --git a/sigmodr/tree/TreeWidget.h b/sigmodr/tree/TreeWidget.h index fc2762f7..1ce12891 100644 --- a/sigmodr/tree/TreeWidget.h +++ b/sigmodr/tree/TreeWidget.h @@ -55,11 +55,10 @@ class SIGMODRTREE_EXPORT TreeWidget : public QTreeView QStringList dropTypes(const QModelIndex& index) const; Widgets::ObjectUI* editorWidget(const QModelIndex& index); - const Sigmod::Game* currentGame() const; - // QDomDocument copy(const QModelIndex& index); // void paste(const QModelIndex& index, const QDomDocument& data); // + const Sigmod::Game* game(const QModelIndex& index) const; QList<const Sigmod::Game*> openedGames() const; void addGame(Sigmod::Game* game, const KUrl& url = KUrl()); void deleteGame(const Sigmod::Game* game); |
