From d5e6d8a58bf666518cb21e7508e8f28b335effd4 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 27 Jun 2015 14:25:48 +0200 Subject: [PATCH] disable dialogue subview buttons while document is locked --- apps/opencs/view/world/dialoguesubview.cpp | 20 ++++-- apps/opencs/view/world/dialoguesubview.hpp | 5 ++ apps/opencs/view/world/recordbuttonbar.cpp | 81 ++++++++++++---------- apps/opencs/view/world/recordbuttonbar.hpp | 13 ++++ 4 files changed, 77 insertions(+), 42 deletions(-) diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index 92b9807e85..ffb6064975 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -714,20 +714,26 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, this, SLOT (requestFocus (const std::string&))); // button bar - RecordButtonBar *buttons = new RecordButtonBar (id, getTable(), mBottom, + mButtons = new RecordButtonBar (id, getTable(), mBottom, &getCommandDispatcher(), this); // layout - getMainLayout().addWidget (buttons); + getMainLayout().addWidget (mButtons); getMainLayout().addWidget (mBottom); // connections - connect (buttons, SIGNAL (nextId()), this, SLOT (nextId())); - connect (buttons, SIGNAL (prevId()), this, SLOT (prevId())); - connect (buttons, SIGNAL (showPreview()), this, SLOT (showPreview())); - connect (buttons, SIGNAL (viewRecord()), this, SLOT (viewRecord())); + connect (mButtons, SIGNAL (nextId()), this, SLOT (nextId())); + connect (mButtons, SIGNAL (prevId()), this, SLOT (prevId())); + connect (mButtons, SIGNAL (showPreview()), this, SLOT (showPreview())); + connect (mButtons, SIGNAL (viewRecord()), this, SLOT (viewRecord())); connect (this, SIGNAL (universalIdChanged (const CSMWorld::UniversalId&)), - buttons, SLOT (universalIdChanged (const CSMWorld::UniversalId&))); + mButtons, SLOT (universalIdChanged (const CSMWorld::UniversalId&))); +} + +void CSVWorld::DialogueSubView::setEditLock (bool locked) +{ + SimpleDialogueSubView::setEditLock (locked); + mButtons->setEditLock (locked); } void CSVWorld::DialogueSubView::prevId() diff --git a/apps/opencs/view/world/dialoguesubview.hpp b/apps/opencs/view/world/dialoguesubview.hpp index 6c0fcc59b0..63b25d06e5 100644 --- a/apps/opencs/view/world/dialoguesubview.hpp +++ b/apps/opencs/view/world/dialoguesubview.hpp @@ -218,17 +218,22 @@ namespace CSVWorld void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); }; + class RecordButtonBar; + class DialogueSubView : public SimpleDialogueSubView { Q_OBJECT TableBottomBox* mBottom; + RecordButtonBar *mButtons; public: DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, const CreatorFactoryBase& creatorFactory, bool sorting = false); + virtual void setEditLock (bool locked); + private slots: void nextId(); diff --git a/apps/opencs/view/world/recordbuttonbar.cpp b/apps/opencs/view/world/recordbuttonbar.cpp index 1560a31a56..93a6a5823c 100644 --- a/apps/opencs/view/world/recordbuttonbar.cpp +++ b/apps/opencs/view/world/recordbuttonbar.cpp @@ -9,11 +9,25 @@ #include "../world/tablebottombox.hpp" +void CSVWorld::RecordButtonBar::updateModificationButtons() +{ + bool createAndDeleteDisabled = !mBottom || !mBottom->canCreateAndDelete() || mLocked; + + mCloneButton->setDisabled (createAndDeleteDisabled); + mAddButton->setDisabled (createAndDeleteDisabled); + mDeleteButton->setDisabled (createAndDeleteDisabled); + + bool commandDisabled = !mCommandDispatcher || mLocked; + + mRevertButton->setDisabled (commandDisabled); + mDeleteButton->setDisabled (commandDisabled); +} + CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id, CSMWorld::IdTable& table, TableBottomBox *bottomBox, CSMWorld::CommandDispatcher *commandDispatcher, QWidget *parent) : QWidget (parent), mId (id), mTable (table), mBottom (bottomBox), - mCommandDispatcher (commandDispatcher) + mCommandDispatcher (commandDispatcher), mLocked (false) { QHBoxLayout *buttonsLayout = new QHBoxLayout; buttonsLayout->setContentsMargins (0, 0, 0, 0); @@ -51,54 +65,51 @@ CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id, } // right section - QToolButton* cloneButton = new QToolButton (this); - cloneButton->setIcon(QIcon(":/edit-clone.png")); - cloneButton->setToolTip ("Clone record"); - buttonsLayout->addWidget(cloneButton); + mCloneButton = new QToolButton (this); + mCloneButton->setIcon(QIcon(":/edit-clone.png")); + mCloneButton->setToolTip ("Clone record"); + buttonsLayout->addWidget(mCloneButton); - QToolButton* addButton = new QToolButton (this); - addButton->setIcon(QIcon(":/add.png")); - addButton->setToolTip ("Add new record"); - buttonsLayout->addWidget(addButton); + mAddButton = new QToolButton (this); + mAddButton->setIcon(QIcon(":/add.png")); + mAddButton->setToolTip ("Add new record"); + buttonsLayout->addWidget(mAddButton); - QToolButton* deleteButton = new QToolButton (this); - deleteButton->setIcon(QIcon(":/edit-delete.png")); - deleteButton->setToolTip ("Delete record"); - buttonsLayout->addWidget(deleteButton); + mDeleteButton = new QToolButton (this); + mDeleteButton->setIcon(QIcon(":/edit-delete.png")); + mDeleteButton->setToolTip ("Delete record"); + buttonsLayout->addWidget(mDeleteButton); - QToolButton* revertButton = new QToolButton (this); - revertButton->setIcon(QIcon(":/edit-undo.png")); - revertButton->setToolTip ("Revert record"); - buttonsLayout->addWidget(revertButton); + mRevertButton = new QToolButton (this); + mRevertButton->setIcon(QIcon(":/edit-undo.png")); + mRevertButton->setToolTip ("Revert record"); + buttonsLayout->addWidget(mRevertButton); setLayout (buttonsLayout); - // disabling and connections - if(!mBottom || !mBottom->canCreateAndDelete()) + // connections + if(mBottom && mBottom->canCreateAndDelete()) { - cloneButton->setDisabled (true); - addButton->setDisabled (true); - deleteButton->setDisabled (true); - } - else - { - connect (addButton, SIGNAL (clicked()), mBottom, SLOT (createRequest())); - connect (cloneButton, SIGNAL (clicked()), this, SLOT (cloneRequest())); + connect (mAddButton, SIGNAL (clicked()), mBottom, SLOT (createRequest())); + connect (mCloneButton, SIGNAL (clicked()), this, SLOT (cloneRequest())); } connect (nextButton, SIGNAL (clicked()), this, SIGNAL (nextId())); connect (prevButton, SIGNAL (clicked()), this, SIGNAL (prevId())); - if (!mCommandDispatcher) + if (mCommandDispatcher) { - revertButton->setDisabled (true); - deleteButton->setDisabled (true); - } - else - { - connect (revertButton, SIGNAL (clicked()), mCommandDispatcher, SLOT (executeRevert())); - connect (deleteButton, SIGNAL (clicked()), mCommandDispatcher, SLOT (executeDelete())); + connect (mRevertButton, SIGNAL (clicked()), mCommandDispatcher, SLOT (executeRevert())); + connect (mDeleteButton, SIGNAL (clicked()), mCommandDispatcher, SLOT (executeDelete())); } + + updateModificationButtons(); +} + +void CSVWorld::RecordButtonBar::setEditLock (bool locked) +{ + mLocked = locked; + updateModificationButtons(); } void CSVWorld::RecordButtonBar::universalIdChanged (const CSMWorld::UniversalId& id) diff --git a/apps/opencs/view/world/recordbuttonbar.hpp b/apps/opencs/view/world/recordbuttonbar.hpp index 08f16a6877..95b567594f 100644 --- a/apps/opencs/view/world/recordbuttonbar.hpp +++ b/apps/opencs/view/world/recordbuttonbar.hpp @@ -5,6 +5,8 @@ #include "../../model/world/universalid.hpp" +class QToolButton; + namespace CSMWorld { class IdTable; @@ -33,13 +35,24 @@ namespace CSVWorld CSMWorld::IdTable& mTable; TableBottomBox *mBottom; CSMWorld::CommandDispatcher *mCommandDispatcher; + QToolButton *mCloneButton; + QToolButton *mAddButton; + QToolButton *mDeleteButton; + QToolButton *mRevertButton; + bool mLocked; + private: + + void updateModificationButtons(); + public: RecordButtonBar (const CSMWorld::UniversalId& id, CSMWorld::IdTable& table, TableBottomBox *bottomBox = 0, CSMWorld::CommandDispatcher *commandDispatcher = 0, QWidget *parent = 0); + void setEditLock (bool locked); + public slots: void universalIdChanged (const CSMWorld::UniversalId& id);