mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 20:19:57 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
7182d564d7
11 changed files with 407 additions and 189 deletions
|
@ -64,7 +64,7 @@ opencs_units (view/world
|
|||
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
|
||||
cellcreator referenceablecreator referencecreator scenesubview
|
||||
infocreator scriptedit dialoguesubview previewsubview regionmap dragrecordtable nestedtable
|
||||
dialoguespinbox
|
||||
dialoguespinbox recordbuttonbar
|
||||
)
|
||||
|
||||
opencs_units_noqt (view/world
|
||||
|
|
|
@ -356,6 +356,14 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
|
|||
formatId->setToolTip ("(Default: Blue) Use one of the following formats:" + tooltip);
|
||||
}
|
||||
|
||||
declareSection ("general-input", "General Input");
|
||||
{
|
||||
Setting *cycle = createSetting (Type_CheckBox, "cycle", "Cyclic next/previous");
|
||||
cycle->setDefaultValue ("false");
|
||||
cycle->setToolTip ("When using next/previous functions at the last/first item of a "
|
||||
"list go to the first/last item");
|
||||
}
|
||||
|
||||
{
|
||||
/******************************************************************
|
||||
* There are three types of values:
|
||||
|
|
|
@ -45,6 +45,7 @@ void CSVDoc::SubView::setUniversalId (const CSMWorld::UniversalId& id)
|
|||
{
|
||||
mUniversalId = id;
|
||||
setWindowTitle (QString::fromUtf8(mUniversalId.toString().c_str()));
|
||||
emit universalIdChanged (mUniversalId);
|
||||
}
|
||||
|
||||
void CSVDoc::SubView::closeEvent (QCloseEvent *event)
|
||||
|
|
|
@ -68,6 +68,8 @@ namespace CSVDoc
|
|||
|
||||
void updateSubViewIndicies (SubView *view = 0);
|
||||
|
||||
void universalIdChanged (const CSMWorld::UniversalId& universalId);
|
||||
|
||||
protected slots:
|
||||
|
||||
void closeRequest();
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
#include <QLineEdit>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QComboBox>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
#include <QHeaderView>
|
||||
#include <QScrollBar>
|
||||
|
||||
|
@ -40,6 +38,7 @@
|
|||
#include "util.hpp"
|
||||
#include "tablebottombox.hpp"
|
||||
#include "nestedtable.hpp"
|
||||
#include "recordbuttonbar.hpp"
|
||||
/*
|
||||
==============================NotEditableSubDelegate==========================================
|
||||
*/
|
||||
|
@ -572,11 +571,6 @@ CSMWorld::CommandDispatcher& CSVWorld::SimpleDialogueSubView::getCommandDispatch
|
|||
return mCommandDispatcher;
|
||||
}
|
||||
|
||||
std::string CSVWorld::SimpleDialogueSubView::getCurrentId() const
|
||||
{
|
||||
return mCurrentId;
|
||||
}
|
||||
|
||||
CSVWorld::EditWidget& CSVWorld::SimpleDialogueSubView::getEditWidget()
|
||||
{
|
||||
return *mEditWidget;
|
||||
|
@ -592,7 +586,6 @@ CSVWorld::SimpleDialogueSubView::SimpleDialogueSubView (const CSMWorld::Universa
|
|||
mEditWidget(0),
|
||||
mMainLayout(NULL),
|
||||
mTable(dynamic_cast<CSMWorld::IdTable*>(document.getData().getTableModel(id))),
|
||||
mUndoStack(document.getUndoStack()),
|
||||
mLocked(false),
|
||||
mDocument(document),
|
||||
mCommandDispatcher (document, CSMWorld::UniversalId::getParentType (id.getType()))
|
||||
|
@ -600,7 +593,7 @@ CSVWorld::SimpleDialogueSubView::SimpleDialogueSubView (const CSMWorld::Universa
|
|||
connect(mTable, SIGNAL(dataChanged (const QModelIndex&, const QModelIndex&)), this, SLOT(dataChanged(const QModelIndex&)));
|
||||
connect(mTable, SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int, int)), this, SLOT(rowsAboutToBeRemoved(const QModelIndex&, int, int)));
|
||||
|
||||
changeCurrentId(id.getId());
|
||||
updateCurrentId();
|
||||
|
||||
QWidget *mainWidget = new QWidget(this);
|
||||
|
||||
|
@ -608,21 +601,21 @@ CSVWorld::SimpleDialogueSubView::SimpleDialogueSubView (const CSMWorld::Universa
|
|||
setWidget (mainWidget);
|
||||
|
||||
mEditWidget = new EditWidget(mainWidget,
|
||||
mTable->getModelIndex(mCurrentId, 0).row(), mTable, mCommandDispatcher, document, false);
|
||||
mTable->getModelIndex(getUniversalId().getId(), 0).row(), mTable, mCommandDispatcher, document, false);
|
||||
|
||||
mMainLayout->addWidget(mEditWidget);
|
||||
mEditWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
|
||||
dataChanged(mTable->getModelIndex (mCurrentId, 0));
|
||||
dataChanged(mTable->getModelIndex (getUniversalId().getId(), 0));
|
||||
}
|
||||
|
||||
void CSVWorld::SimpleDialogueSubView::setEditLock (bool locked)
|
||||
{
|
||||
if (!mEditWidget) // hack to indicate that mCurrentId is no longer valid
|
||||
if (!mEditWidget) // hack to indicate that getUniversalId().getId() is no longer valid
|
||||
return;
|
||||
|
||||
mLocked = locked;
|
||||
QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
|
||||
QModelIndex currentIndex(mTable->getModelIndex(getUniversalId().getId(), 0));
|
||||
|
||||
if (currentIndex.isValid())
|
||||
{
|
||||
|
@ -637,7 +630,7 @@ void CSVWorld::SimpleDialogueSubView::setEditLock (bool locked)
|
|||
|
||||
void CSVWorld::SimpleDialogueSubView::dataChanged (const QModelIndex & index)
|
||||
{
|
||||
QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
|
||||
QModelIndex currentIndex(mTable->getModelIndex(getUniversalId().getId(), 0));
|
||||
|
||||
if (currentIndex.isValid() &&
|
||||
(index.parent().isValid() ? index.parent().row() : index.row()) == currentIndex.row())
|
||||
|
@ -670,7 +663,7 @@ void CSVWorld::SimpleDialogueSubView::dataChanged (const QModelIndex & index)
|
|||
|
||||
void CSVWorld::SimpleDialogueSubView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
|
||||
{
|
||||
QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
|
||||
QModelIndex currentIndex(mTable->getModelIndex(getUniversalId().getId(), 0));
|
||||
|
||||
if (currentIndex.isValid() && currentIndex.row() >= start && currentIndex.row() <= end)
|
||||
{
|
||||
|
@ -683,19 +676,10 @@ void CSVWorld::SimpleDialogueSubView::rowsAboutToBeRemoved(const QModelIndex &pa
|
|||
}
|
||||
}
|
||||
|
||||
void CSVWorld::SimpleDialogueSubView::requestFocus (const std::string& id)
|
||||
{
|
||||
changeCurrentId(id);
|
||||
|
||||
mEditWidget->remake(mTable->getModelIndex (id, 0).row());
|
||||
}
|
||||
|
||||
void CSVWorld::SimpleDialogueSubView::changeCurrentId (const std::string& newId)
|
||||
void CSVWorld::SimpleDialogueSubView::updateCurrentId()
|
||||
{
|
||||
std::vector<std::string> selection;
|
||||
mCurrentId = std::string(newId);
|
||||
|
||||
selection.push_back(mCurrentId);
|
||||
selection.push_back (getUniversalId().getId());
|
||||
mCommandDispatcher.setSelection(selection);
|
||||
}
|
||||
|
||||
|
@ -705,172 +689,57 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id,
|
|||
: SimpleDialogueSubView (id, document)
|
||||
{
|
||||
// bottom box
|
||||
getMainLayout().addWidget (mBottom = new TableBottomBox (creatorFactory, document, id, this));
|
||||
mBottom = new TableBottomBox (creatorFactory, document, id, this);
|
||||
|
||||
mBottom->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
||||
mBottom->setSizePolicy (QSizePolicy::Ignored, QSizePolicy::Fixed);
|
||||
|
||||
connect(mBottom, SIGNAL(requestFocus(const std::string&)), this, SLOT(requestFocus(const std::string&)));
|
||||
connect (mBottom, SIGNAL (requestFocus (const std::string&)),
|
||||
this, SLOT (requestFocus (const std::string&)));
|
||||
|
||||
// buttons
|
||||
QHBoxLayout *buttonsLayout = new QHBoxLayout;
|
||||
QToolButton* prevButton = new QToolButton (this);
|
||||
prevButton->setIcon(QIcon(":/go-previous.png"));
|
||||
prevButton->setToolTip ("Switch to previous record");
|
||||
QToolButton* nextButton = new QToolButton (this);
|
||||
nextButton->setIcon(QIcon(":/go-next.png"));
|
||||
nextButton->setToolTip ("Switch to next record");
|
||||
buttonsLayout->addWidget(prevButton, 0);
|
||||
buttonsLayout->addWidget(nextButton, 1);
|
||||
buttonsLayout->addStretch(2);
|
||||
// button bar
|
||||
mButtons = new RecordButtonBar (id, getTable(), mBottom,
|
||||
&getCommandDispatcher(), this);
|
||||
|
||||
QToolButton* cloneButton = new QToolButton (this);
|
||||
cloneButton->setIcon(QIcon(":/edit-clone.png"));
|
||||
cloneButton->setToolTip ("Clone record");
|
||||
QToolButton* addButton = new QToolButton (this);
|
||||
addButton->setIcon(QIcon(":/add.png"));
|
||||
addButton->setToolTip ("Add new record");
|
||||
QToolButton* deleteButton = new QToolButton (this);
|
||||
deleteButton->setIcon(QIcon(":/edit-delete.png"));
|
||||
deleteButton->setToolTip ("Delete record");
|
||||
QToolButton* revertButton = new QToolButton (this);
|
||||
revertButton->setIcon(QIcon(":/edit-undo.png"));
|
||||
revertButton->setToolTip ("Revert record");
|
||||
// layout
|
||||
getMainLayout().addWidget (mButtons);
|
||||
getMainLayout().addWidget (mBottom);
|
||||
|
||||
if (getTable().getFeatures() & CSMWorld::IdTable::Feature_Preview)
|
||||
{
|
||||
QToolButton* previewButton = new QToolButton (this);
|
||||
previewButton->setIcon(QIcon(":/edit-preview.png"));
|
||||
previewButton->setToolTip ("Open a preview of this record");
|
||||
buttonsLayout->addWidget(previewButton);
|
||||
connect(previewButton, SIGNAL(clicked()), this, SLOT(showPreview()));
|
||||
}
|
||||
|
||||
if (getTable().getFeatures() & CSMWorld::IdTable::Feature_View)
|
||||
{
|
||||
QToolButton* viewButton = new QToolButton (this);
|
||||
viewButton->setIcon(QIcon(":/cell.png"));
|
||||
viewButton->setToolTip ("Open a scene view of the cell this record is located in");
|
||||
buttonsLayout->addWidget(viewButton);
|
||||
connect(viewButton, SIGNAL(clicked()), this, SLOT(viewRecord()));
|
||||
}
|
||||
|
||||
buttonsLayout->addWidget(cloneButton);
|
||||
buttonsLayout->addWidget(addButton);
|
||||
buttonsLayout->addWidget(deleteButton);
|
||||
buttonsLayout->addWidget(revertButton);
|
||||
|
||||
connect(nextButton, SIGNAL(clicked()), this, SLOT(nextId()));
|
||||
connect(prevButton, SIGNAL(clicked()), this, SLOT(prevId()));
|
||||
connect(cloneButton, SIGNAL(clicked()), this, SLOT(cloneRequest()));
|
||||
connect(revertButton, SIGNAL(clicked()), &getCommandDispatcher(), SLOT(executeRevert()));
|
||||
connect(deleteButton, SIGNAL(clicked()), &getCommandDispatcher(), SLOT(executeDelete()));
|
||||
|
||||
connect(addButton, SIGNAL(clicked()), mBottom, SLOT(createRequest()));
|
||||
|
||||
if(!mBottom->canCreateAndDelete())
|
||||
{
|
||||
cloneButton->setDisabled (true);
|
||||
addButton->setDisabled (true);
|
||||
deleteButton->setDisabled (true);
|
||||
}
|
||||
|
||||
getMainLayout().addLayout (buttonsLayout);
|
||||
// connections
|
||||
connect (mButtons, SIGNAL (showPreview()), this, SLOT (showPreview()));
|
||||
connect (mButtons, SIGNAL (viewRecord()), this, SLOT (viewRecord()));
|
||||
connect (mButtons, SIGNAL (switchToRow (int)), this, SLOT (switchToRow (int)));
|
||||
|
||||
connect (this, SIGNAL (universalIdChanged (const CSMWorld::UniversalId&)),
|
||||
mButtons, SLOT (universalIdChanged (const CSMWorld::UniversalId&)));
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueSubView::cloneRequest()
|
||||
void CSVWorld::DialogueSubView::setEditLock (bool locked)
|
||||
{
|
||||
mBottom->cloneRequest (getCurrentId(),
|
||||
static_cast<CSMWorld::UniversalId::Type> (getTable().
|
||||
data (getTable().getModelIndex(getCurrentId(), 2)).toInt()));
|
||||
SimpleDialogueSubView::setEditLock (locked);
|
||||
mButtons->setEditLock (locked);
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueSubView::prevId()
|
||||
void CSVWorld::DialogueSubView::updateUserSetting (const QString& name, const QStringList& value)
|
||||
{
|
||||
int newRow = getTable().getModelIndex (getCurrentId(), 0).row() - 1;
|
||||
|
||||
if (newRow < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
while (newRow >= 0)
|
||||
{
|
||||
QModelIndex newIndex (getTable().index(newRow, 0));
|
||||
|
||||
if (!newIndex.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State> (getTable().data (getTable().index (newRow, 1)).toInt());
|
||||
if (!(state == CSMWorld::RecordBase::State_Deleted || state == CSMWorld::RecordBase::State_Erased))
|
||||
{
|
||||
getEditWidget().remake (newRow);
|
||||
|
||||
setUniversalId(CSMWorld::UniversalId (static_cast<CSMWorld::UniversalId::Type> (getTable().data (getTable().index (newRow, 2)).toInt()),
|
||||
getTable().data (getTable().index (newRow, 0)).toString().toUtf8().constData()));
|
||||
|
||||
changeCurrentId(std::string (getTable().data (getTable().index (newRow, 0)).toString().toUtf8().constData()));
|
||||
|
||||
getEditWidget().setDisabled (isLocked());
|
||||
|
||||
return;
|
||||
}
|
||||
--newRow;
|
||||
}
|
||||
SimpleDialogueSubView::updateUserSetting (name, value);
|
||||
mButtons->updateUserSetting (name, value);
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueSubView::nextId ()
|
||||
{
|
||||
int newRow = getTable().getModelIndex (getCurrentId(), 0).row() + 1;
|
||||
|
||||
if (newRow >= getTable().rowCount())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (newRow < getTable().rowCount())
|
||||
{
|
||||
QModelIndex newIndex (getTable().index(newRow, 0));
|
||||
|
||||
if (!newIndex.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State> (getTable().data (getTable().index (newRow, 1)).toInt());
|
||||
if (!(state == CSMWorld::RecordBase::State_Deleted))
|
||||
{
|
||||
getEditWidget().remake(newRow);
|
||||
|
||||
setUniversalId(CSMWorld::UniversalId (static_cast<CSMWorld::UniversalId::Type> (getTable().data (getTable().index (newRow, 2)).toInt()),
|
||||
getTable().data (getTable().index (newRow, 0)).toString().toUtf8().constData()));
|
||||
|
||||
changeCurrentId(std::string (getTable().data (getTable().index (newRow, 0)).toString().toUtf8().constData()));
|
||||
|
||||
getEditWidget().setDisabled (isLocked());
|
||||
|
||||
return;
|
||||
}
|
||||
++newRow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CSVWorld::DialogueSubView::showPreview ()
|
||||
{
|
||||
QModelIndex currentIndex (getTable().getModelIndex (getCurrentId(), 0));
|
||||
QModelIndex currentIndex (getTable().getModelIndex (getUniversalId().getId(), 0));
|
||||
|
||||
if (currentIndex.isValid() &&
|
||||
getTable().getFeatures() & CSMWorld::IdTable::Feature_Preview &&
|
||||
currentIndex.row() < getTable().rowCount())
|
||||
{
|
||||
emit focusId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Preview, getCurrentId()), "");
|
||||
emit focusId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Preview, getUniversalId().getId()), "");
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueSubView::viewRecord ()
|
||||
{
|
||||
QModelIndex currentIndex (getTable().getModelIndex (getCurrentId(), 0));
|
||||
QModelIndex currentIndex (getTable().getModelIndex (getUniversalId().getId(), 0));
|
||||
|
||||
if (currentIndex.isValid() &&
|
||||
currentIndex.row() < getTable().rowCount())
|
||||
|
@ -881,3 +750,32 @@ void CSVWorld::DialogueSubView::viewRecord ()
|
|||
emit focusId (params.first, params.second);
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueSubView::switchToRow (int row)
|
||||
{
|
||||
int idColumn = getTable().findColumnIndex (CSMWorld::Columns::ColumnId_Id);
|
||||
std::string id = getTable().data (getTable().index (row, idColumn)).toString().toUtf8().constData();
|
||||
|
||||
int typeColumn = getTable().findColumnIndex (CSMWorld::Columns::ColumnId_RecordType);
|
||||
CSMWorld::UniversalId::Type type = static_cast<CSMWorld::UniversalId::Type> (
|
||||
getTable().data (getTable().index (row, typeColumn)).toInt());
|
||||
|
||||
setUniversalId (CSMWorld::UniversalId (type, id));
|
||||
updateCurrentId();
|
||||
|
||||
getEditWidget().remake (row);
|
||||
|
||||
int stateColumn = getTable().findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
|
||||
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State> (
|
||||
getTable().data (getTable().index (row, stateColumn)).toInt());
|
||||
|
||||
getEditWidget().setDisabled (isLocked() || state==CSMWorld::RecordBase::State_Deleted);
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueSubView::requestFocus (const std::string& id)
|
||||
{
|
||||
QModelIndex index = getTable().getModelIndex (id, 0);
|
||||
|
||||
if (index.isValid())
|
||||
switchToRow (index.row());
|
||||
}
|
||||
|
|
|
@ -175,16 +175,14 @@ namespace CSVWorld
|
|||
|
||||
class SimpleDialogueSubView : public CSVDoc::SubView
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
EditWidget* mEditWidget;
|
||||
QVBoxLayout* mMainLayout;
|
||||
CSMWorld::IdTable* mTable;
|
||||
QUndoStack& mUndoStack;
|
||||
std::string mCurrentId;
|
||||
bool mLocked;
|
||||
const CSMDoc::Document& mDocument;
|
||||
CSMWorld::CommandDispatcher mCommandDispatcher;
|
||||
EditWidget* mEditWidget;
|
||||
QVBoxLayout* mMainLayout;
|
||||
CSMWorld::IdTable* mTable;
|
||||
bool mLocked;
|
||||
const CSMDoc::Document& mDocument;
|
||||
CSMWorld::CommandDispatcher mCommandDispatcher;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -194,11 +192,9 @@ namespace CSVWorld
|
|||
|
||||
CSMWorld::CommandDispatcher& getCommandDispatcher();
|
||||
|
||||
std::string getCurrentId() const;
|
||||
|
||||
EditWidget& getEditWidget();
|
||||
|
||||
void changeCurrentId(const std::string& newCurrent);
|
||||
void updateCurrentId();
|
||||
|
||||
bool isLocked() const;
|
||||
|
||||
|
@ -213,33 +209,36 @@ namespace CSVWorld
|
|||
void dataChanged(const QModelIndex & index);
|
||||
///\brief we need to care for deleting currently edited record
|
||||
|
||||
void requestFocus (const std::string& id);
|
||||
|
||||
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);
|
||||
|
||||
virtual void updateUserSetting (const QString& name, const QStringList& value);
|
||||
|
||||
private slots:
|
||||
|
||||
void cloneRequest();
|
||||
|
||||
void nextId();
|
||||
|
||||
void prevId();
|
||||
|
||||
void showPreview();
|
||||
|
||||
void viewRecord();
|
||||
|
||||
void switchToRow (int row);
|
||||
|
||||
void requestFocus (const std::string& id);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
207
apps/opencs/view/world/recordbuttonbar.cpp
Normal file
207
apps/opencs/view/world/recordbuttonbar.cpp
Normal file
|
@ -0,0 +1,207 @@
|
|||
|
||||
#include "recordbuttonbar.hpp"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QToolButton>
|
||||
|
||||
#include "../../model/world/idtable.hpp"
|
||||
#include "../../model/world/commanddispatcher.hpp"
|
||||
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
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,
|
||||
CSMWorld::IdTable& table, TableBottomBox *bottomBox,
|
||||
CSMWorld::CommandDispatcher *commandDispatcher, QWidget *parent)
|
||||
: QWidget (parent), mId (id), mTable (table), mBottom (bottomBox),
|
||||
mCommandDispatcher (commandDispatcher), mLocked (false)
|
||||
{
|
||||
QHBoxLayout *buttonsLayout = new QHBoxLayout;
|
||||
buttonsLayout->setContentsMargins (0, 0, 0, 0);
|
||||
|
||||
// left section
|
||||
mPrevButton = new QToolButton (this);
|
||||
mPrevButton->setIcon(QIcon(":/go-previous.png"));
|
||||
mPrevButton->setToolTip ("Switch to previous record");
|
||||
buttonsLayout->addWidget (mPrevButton, 0);
|
||||
|
||||
mNextButton = new QToolButton (this);
|
||||
mNextButton->setIcon(QIcon(":/go-next.png"));
|
||||
mNextButton->setToolTip ("Switch to next record");
|
||||
buttonsLayout->addWidget (mNextButton, 1);
|
||||
|
||||
buttonsLayout->addStretch(2);
|
||||
|
||||
// optional buttons of the right section
|
||||
if (mTable.getFeatures() & CSMWorld::IdTable::Feature_Preview)
|
||||
{
|
||||
QToolButton* previewButton = new QToolButton (this);
|
||||
previewButton->setIcon(QIcon(":/edit-preview.png"));
|
||||
previewButton->setToolTip ("Open a preview of this record");
|
||||
buttonsLayout->addWidget(previewButton);
|
||||
connect (previewButton, SIGNAL(clicked()), this, SIGNAL (showPreview()));
|
||||
}
|
||||
|
||||
if (mTable.getFeatures() & CSMWorld::IdTable::Feature_View)
|
||||
{
|
||||
QToolButton* viewButton = new QToolButton (this);
|
||||
viewButton->setIcon(QIcon(":/cell.png"));
|
||||
viewButton->setToolTip ("Open a scene view of the cell this record is located in");
|
||||
buttonsLayout->addWidget(viewButton);
|
||||
connect (viewButton, SIGNAL(clicked()), this, SIGNAL (viewRecord()));
|
||||
}
|
||||
|
||||
// right section
|
||||
mCloneButton = new QToolButton (this);
|
||||
mCloneButton->setIcon(QIcon(":/edit-clone.png"));
|
||||
mCloneButton->setToolTip ("Clone record");
|
||||
buttonsLayout->addWidget(mCloneButton);
|
||||
|
||||
mAddButton = new QToolButton (this);
|
||||
mAddButton->setIcon(QIcon(":/add.png"));
|
||||
mAddButton->setToolTip ("Add new record");
|
||||
buttonsLayout->addWidget(mAddButton);
|
||||
|
||||
mDeleteButton = new QToolButton (this);
|
||||
mDeleteButton->setIcon(QIcon(":/edit-delete.png"));
|
||||
mDeleteButton->setToolTip ("Delete record");
|
||||
buttonsLayout->addWidget(mDeleteButton);
|
||||
|
||||
mRevertButton = new QToolButton (this);
|
||||
mRevertButton->setIcon(QIcon(":/edit-undo.png"));
|
||||
mRevertButton->setToolTip ("Revert record");
|
||||
buttonsLayout->addWidget(mRevertButton);
|
||||
|
||||
setLayout (buttonsLayout);
|
||||
|
||||
// connections
|
||||
if(mBottom && mBottom->canCreateAndDelete())
|
||||
{
|
||||
connect (mAddButton, SIGNAL (clicked()), mBottom, SLOT (createRequest()));
|
||||
connect (mCloneButton, SIGNAL (clicked()), this, SLOT (cloneRequest()));
|
||||
}
|
||||
|
||||
connect (mNextButton, SIGNAL (clicked()), this, SLOT (nextId()));
|
||||
connect (mPrevButton, SIGNAL (clicked()), this, SLOT (prevId()));
|
||||
|
||||
if (mCommandDispatcher)
|
||||
{
|
||||
connect (mRevertButton, SIGNAL (clicked()), mCommandDispatcher, SLOT (executeRevert()));
|
||||
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();
|
||||
updatePrevNextButtons();
|
||||
}
|
||||
|
||||
void CSVWorld::RecordButtonBar::setEditLock (bool locked)
|
||||
{
|
||||
mLocked = locked;
|
||||
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)
|
||||
{
|
||||
mId = id;
|
||||
updatePrevNextButtons();
|
||||
}
|
||||
|
||||
void CSVWorld::RecordButtonBar::cloneRequest()
|
||||
{
|
||||
if (mBottom)
|
||||
{
|
||||
int typeColumn = mTable.findColumnIndex (CSMWorld::Columns::ColumnId_RecordType);
|
||||
|
||||
QModelIndex typeIndex = mTable.getModelIndex (mId.getId(), typeColumn);
|
||||
CSMWorld::UniversalId::Type type = static_cast<CSMWorld::UniversalId::Type> (
|
||||
mTable.data (typeIndex).toInt());
|
||||
|
||||
mBottom->cloneRequest (mId.getId(), type);
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWorld::RecordButtonBar::nextId()
|
||||
{
|
||||
int newRow = mTable.getModelIndex (mId.getId(), 0).row() + 1;
|
||||
|
||||
if (newRow >= mTable.rowCount())
|
||||
{
|
||||
if (CSMSettings::UserSettings::instance().settingValue ("general-input/cycle")
|
||||
=="true")
|
||||
newRow = 0;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
emit switchToRow (newRow);
|
||||
}
|
||||
|
||||
void CSVWorld::RecordButtonBar::prevId()
|
||||
{
|
||||
int newRow = mTable.getModelIndex (mId.getId(), 0).row() - 1;
|
||||
|
||||
if (newRow < 0)
|
||||
{
|
||||
if (CSMSettings::UserSettings::instance().settingValue ("general-input/cycle")
|
||||
=="true")
|
||||
newRow = mTable.rowCount()-1;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
emit switchToRow (newRow);
|
||||
}
|
||||
|
||||
void CSVWorld::RecordButtonBar::rowNumberChanged (const QModelIndex& parent, int start, int end)
|
||||
{
|
||||
updatePrevNextButtons();
|
||||
}
|
87
apps/opencs/view/world/recordbuttonbar.hpp
Normal file
87
apps/opencs/view/world/recordbuttonbar.hpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
#ifndef CSV_WORLD_RECORDBUTTONBAR_H
|
||||
#define CSV_WORLD_RECORDBUTTONBAR_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
class QToolButton;
|
||||
class QModelIndex;
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class IdTable;
|
||||
class CommandDispatcher;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class TableBottomBox;
|
||||
|
||||
/// \brief Button bar for use in dialogue-type subviews
|
||||
///
|
||||
/// Contains the following buttons:
|
||||
/// - next/prev
|
||||
/// - clone
|
||||
/// - add
|
||||
/// - delete
|
||||
/// - revert
|
||||
/// - preview (optional)
|
||||
/// - view (optional)
|
||||
class RecordButtonBar : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSMWorld::UniversalId mId;
|
||||
CSMWorld::IdTable& mTable;
|
||||
TableBottomBox *mBottom;
|
||||
CSMWorld::CommandDispatcher *mCommandDispatcher;
|
||||
QToolButton *mPrevButton;
|
||||
QToolButton *mNextButton;
|
||||
QToolButton *mCloneButton;
|
||||
QToolButton *mAddButton;
|
||||
QToolButton *mDeleteButton;
|
||||
QToolButton *mRevertButton;
|
||||
bool mLocked;
|
||||
|
||||
private:
|
||||
|
||||
void updateModificationButtons();
|
||||
|
||||
void updatePrevNextButtons();
|
||||
|
||||
public:
|
||||
|
||||
RecordButtonBar (const CSMWorld::UniversalId& id,
|
||||
CSMWorld::IdTable& table, TableBottomBox *bottomBox = 0,
|
||||
CSMWorld::CommandDispatcher *commandDispatcher = 0, QWidget *parent = 0);
|
||||
|
||||
void setEditLock (bool locked);
|
||||
|
||||
void updateUserSetting (const QString& name, const QStringList& value);
|
||||
|
||||
public slots:
|
||||
|
||||
void universalIdChanged (const CSMWorld::UniversalId& id);
|
||||
|
||||
private slots:
|
||||
|
||||
void cloneRequest();
|
||||
|
||||
void nextId();
|
||||
|
||||
void prevId();
|
||||
|
||||
void rowNumberChanged (const QModelIndex& parent, int start, int end);
|
||||
|
||||
signals:
|
||||
|
||||
void showPreview();
|
||||
|
||||
void viewRecord();
|
||||
|
||||
void switchToRow (int row);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -174,6 +174,15 @@ namespace ESM
|
|||
endRecord(name);
|
||||
}
|
||||
|
||||
void ESMWriter::writeFixedSizeString(const std::string &data, int size)
|
||||
{
|
||||
std::string string;
|
||||
if (!data.empty())
|
||||
string = mEncoder ? mEncoder->getLegacyEnc(data) : data;
|
||||
string.resize(size);
|
||||
write(string.c_str(), string.size());
|
||||
}
|
||||
|
||||
void ESMWriter::writeHString(const std::string& data)
|
||||
{
|
||||
if (data.size() == 0)
|
||||
|
|
|
@ -120,6 +120,7 @@ public:
|
|||
void startSubRecord(const std::string& name);
|
||||
void endRecord(const std::string& name);
|
||||
void endRecord(uint32_t name);
|
||||
void writeFixedSizeString(const std::string& data, int size);
|
||||
void writeHString(const std::string& data);
|
||||
void writeHCString(const std::string& data);
|
||||
void writeName(const std::string& data);
|
||||
|
|
|
@ -71,7 +71,13 @@ void ESM::Header::save (ESMWriter &esm)
|
|||
if (mFormat>0)
|
||||
esm.writeHNT ("FORM", mFormat);
|
||||
|
||||
esm.writeHNT ("HEDR", mData, 300);
|
||||
esm.startSubRecord("HEDR");
|
||||
esm.writeT(mData.version);
|
||||
esm.writeT(mData.type);
|
||||
esm.writeFixedSizeString(mData.author.toString(), 32);
|
||||
esm.writeFixedSizeString(mData.desc.toString(), 256);
|
||||
esm.writeT(mData.records);
|
||||
esm.endRecord("HEDR");
|
||||
|
||||
for (std::vector<Header::MasterData>::iterator iter = mMaster.begin();
|
||||
iter != mMaster.end(); ++iter)
|
||||
|
|
Loading…
Reference in a new issue