1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 12:35:46 +00:00

disable prev/next buttons if there is no previous/next record

This commit is contained in:
Marc Zinnschlag 2015-06-27 16:57:45 +02:00
parent e27a75bd10
commit 15bb2855a9
4 changed files with 69 additions and 11 deletions

View File

@ -719,6 +719,12 @@ void CSVWorld::DialogueSubView::setEditLock (bool locked)
mButtons->setEditLock (locked); mButtons->setEditLock (locked);
} }
void CSVWorld::DialogueSubView::updateUserSetting (const QString& name, const QStringList& value)
{
SimpleDialogueSubView::updateUserSetting (name, value);
mButtons->updateUserSetting (name, value);
}
void CSVWorld::DialogueSubView::showPreview () void CSVWorld::DialogueSubView::showPreview ()
{ {
QModelIndex currentIndex (getTable().getModelIndex (getUniversalId().getId(), 0)); QModelIndex currentIndex (getTable().getModelIndex (getUniversalId().getId(), 0));

View File

@ -228,6 +228,8 @@ namespace CSVWorld
virtual void setEditLock (bool locked); virtual void setEditLock (bool locked);
virtual void updateUserSetting (const QString& name, const QStringList& value);
private slots: private slots:
void showPreview(); void showPreview();

View File

@ -25,6 +25,29 @@ void CSVWorld::RecordButtonBar::updateModificationButtons()
mDeleteButton->setDisabled (commandDisabled); mDeleteButton->setDisabled (commandDisabled);
} }
void CSVWorld::RecordButtonBar::updatePrevNextButtons()
{
int rows = mTable.rowCount();
if (rows<=1)
{
mPrevButton->setDisabled (true);
mNextButton->setDisabled (true);
}
else if (CSMSettings::UserSettings::instance().settingValue ("general-input/cycle")=="true")
{
mPrevButton->setDisabled (false);
mNextButton->setDisabled (false);
}
else
{
int row = mTable.getModelIndex (mId.getId(), 0).row();
mPrevButton->setDisabled (row<=0);
mNextButton->setDisabled (row>=rows-1);
}
}
CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id, CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id,
CSMWorld::IdTable& table, TableBottomBox *bottomBox, CSMWorld::IdTable& table, TableBottomBox *bottomBox,
CSMWorld::CommandDispatcher *commandDispatcher, QWidget *parent) CSMWorld::CommandDispatcher *commandDispatcher, QWidget *parent)
@ -35,15 +58,15 @@ CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id,
buttonsLayout->setContentsMargins (0, 0, 0, 0); buttonsLayout->setContentsMargins (0, 0, 0, 0);
// left section // left section
QToolButton* prevButton = new QToolButton (this); mPrevButton = new QToolButton (this);
prevButton->setIcon(QIcon(":/go-previous.png")); mPrevButton->setIcon(QIcon(":/go-previous.png"));
prevButton->setToolTip ("Switch to previous record"); mPrevButton->setToolTip ("Switch to previous record");
buttonsLayout->addWidget (prevButton, 0); buttonsLayout->addWidget (mPrevButton, 0);
QToolButton* nextButton = new QToolButton (this); mNextButton = new QToolButton (this);
nextButton->setIcon(QIcon(":/go-next.png")); mNextButton->setIcon(QIcon(":/go-next.png"));
nextButton->setToolTip ("Switch to next record"); mNextButton->setToolTip ("Switch to next record");
buttonsLayout->addWidget (nextButton, 1); buttonsLayout->addWidget (mNextButton, 1);
buttonsLayout->addStretch(2); buttonsLayout->addStretch(2);
@ -96,8 +119,8 @@ CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id,
connect (mCloneButton, SIGNAL (clicked()), this, SLOT (cloneRequest())); connect (mCloneButton, SIGNAL (clicked()), this, SLOT (cloneRequest()));
} }
connect (nextButton, SIGNAL (clicked()), this, SLOT (nextId())); connect (mNextButton, SIGNAL (clicked()), this, SLOT (nextId()));
connect (prevButton, SIGNAL (clicked()), this, SLOT (prevId())); connect (mPrevButton, SIGNAL (clicked()), this, SLOT (prevId()));
if (mCommandDispatcher) if (mCommandDispatcher)
{ {
@ -105,7 +128,13 @@ CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id,
connect (mDeleteButton, SIGNAL (clicked()), mCommandDispatcher, SLOT (executeDelete())); connect (mDeleteButton, SIGNAL (clicked()), mCommandDispatcher, SLOT (executeDelete()));
} }
connect (&mTable, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
this, SLOT (rowNumberChanged (const QModelIndex&, int, int)));
connect (&mTable, SIGNAL (rowsRemoved (const QModelIndex&, int, int)),
this, SLOT (rowNumberChanged (const QModelIndex&, int, int)));
updateModificationButtons(); updateModificationButtons();
updatePrevNextButtons();
} }
void CSVWorld::RecordButtonBar::setEditLock (bool locked) void CSVWorld::RecordButtonBar::setEditLock (bool locked)
@ -114,9 +143,16 @@ void CSVWorld::RecordButtonBar::setEditLock (bool locked)
updateModificationButtons(); updateModificationButtons();
} }
void CSVWorld::RecordButtonBar::updateUserSetting (const QString& name, const QStringList& value)
{
if (name=="general-input/cycle")
updatePrevNextButtons();
}
void CSVWorld::RecordButtonBar::universalIdChanged (const CSMWorld::UniversalId& id) void CSVWorld::RecordButtonBar::universalIdChanged (const CSMWorld::UniversalId& id)
{ {
mId = id; mId = id;
updatePrevNextButtons();
} }
void CSVWorld::RecordButtonBar::cloneRequest() void CSVWorld::RecordButtonBar::cloneRequest()
@ -164,3 +200,8 @@ void CSVWorld::RecordButtonBar::prevId()
emit switchToRow (newRow); emit switchToRow (newRow);
} }
void CSVWorld::RecordButtonBar::rowNumberChanged (const QModelIndex& parent, int start, int end)
{
updatePrevNextButtons();
}

View File

@ -6,6 +6,7 @@
#include "../../model/world/universalid.hpp" #include "../../model/world/universalid.hpp"
class QToolButton; class QToolButton;
class QModelIndex;
namespace CSMWorld namespace CSMWorld
{ {
@ -35,6 +36,8 @@ namespace CSVWorld
CSMWorld::IdTable& mTable; CSMWorld::IdTable& mTable;
TableBottomBox *mBottom; TableBottomBox *mBottom;
CSMWorld::CommandDispatcher *mCommandDispatcher; CSMWorld::CommandDispatcher *mCommandDispatcher;
QToolButton *mPrevButton;
QToolButton *mNextButton;
QToolButton *mCloneButton; QToolButton *mCloneButton;
QToolButton *mAddButton; QToolButton *mAddButton;
QToolButton *mDeleteButton; QToolButton *mDeleteButton;
@ -45,6 +48,8 @@ namespace CSVWorld
void updateModificationButtons(); void updateModificationButtons();
void updatePrevNextButtons();
public: public:
RecordButtonBar (const CSMWorld::UniversalId& id, RecordButtonBar (const CSMWorld::UniversalId& id,
@ -53,6 +58,8 @@ namespace CSVWorld
void setEditLock (bool locked); void setEditLock (bool locked);
void updateUserSetting (const QString& name, const QStringList& value);
public slots: public slots:
void universalIdChanged (const CSMWorld::UniversalId& id); void universalIdChanged (const CSMWorld::UniversalId& id);
@ -65,6 +72,8 @@ namespace CSVWorld
void prevId(); void prevId();
void rowNumberChanged (const QModelIndex& parent, int start, int end);
signals: signals:
void showPreview(); void showPreview();