1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-04 15:45:34 +00:00

Merge branch 'scriptbuttons'

This commit is contained in:
Marc Zinnschlag 2015-07-18 17:37:43 +02:00
commit b2ab0122ab
18 changed files with 605 additions and 145 deletions

View file

@ -64,7 +64,7 @@ opencs_units (view/world
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
cellcreator referenceablecreator referencecreator scenesubview cellcreator referenceablecreator referencecreator scenesubview
infocreator scriptedit dialoguesubview previewsubview regionmap dragrecordtable nestedtable infocreator scriptedit dialoguesubview previewsubview regionmap dragrecordtable nestedtable
dialoguespinbox recordbuttonbar tableeditidaction dialoguespinbox recordbuttonbar tableeditidaction scripterrortable
) )
opencs_units_noqt (view/world opencs_units_noqt (view/world

View file

@ -8,6 +8,20 @@ CSMDoc::Message::Message (const CSMWorld::UniversalId& id, const std::string& me
: mId (id), mMessage (message), mHint (hint), mSeverity (severity) : mId (id), mMessage (message), mHint (hint), mSeverity (severity)
{} {}
std::string CSMDoc::Message::toString (Severity severity)
{
switch (severity)
{
case CSMDoc::Message::Severity_Info: return "Information";
case CSMDoc::Message::Severity_Warning: return "Warning";
case CSMDoc::Message::Severity_Error: return "Error";
case CSMDoc::Message::Severity_SeriousError: return "Serious Error";
case CSMDoc::Message::Severity_Default: break;
}
return "";
}
CSMDoc::Messages::Messages (Message::Severity default_) CSMDoc::Messages::Messages (Message::Severity default_)
: mDefault (default_) : mDefault (default_)
@ -18,7 +32,7 @@ void CSMDoc::Messages::add (const CSMWorld::UniversalId& id, const std::string&
{ {
if (severity==Message::Severity_Default) if (severity==Message::Severity_Default)
severity = mDefault; severity = mDefault;
mMessages.push_back (Message (id, message, hint, severity)); mMessages.push_back (Message (id, message, hint, severity));
} }

View file

@ -21,18 +21,20 @@ namespace CSMDoc
// reporting it correctly // reporting it correctly
Severity_Default = 4 Severity_Default = 4
}; };
CSMWorld::UniversalId mId; CSMWorld::UniversalId mId;
std::string mMessage; std::string mMessage;
std::string mHint; std::string mHint;
Severity mSeverity; Severity mSeverity;
Message(); Message();
Message (const CSMWorld::UniversalId& id, const std::string& message, Message (const CSMWorld::UniversalId& id, const std::string& message,
const std::string& hint, Severity severity); const std::string& hint, Severity severity);
static std::string toString (Severity severity);
}; };
class Messages class Messages
{ {
public: public:

View file

@ -162,7 +162,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
ritd->setDeclaredValues (values); ritd->setDeclaredValues (values);
} }
declareSection ("table-input", "Table Input"); declareSection ("table-input", "ID Tables");
{ {
QString inPlaceEdit ("Edit in Place"); QString inPlaceEdit ("Edit in Place");
QString editRecord ("Edit Record"); QString editRecord ("Edit Record");
@ -217,7 +217,13 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
jumpToAdded->setDeclaredValues (jumpValues); jumpToAdded->setDeclaredValues (jumpValues);
} }
declareSection ("report-input", "Report Input"); declareSection ("dialogues", "ID Dialogues");
{
Setting *toolbar = createSetting (Type_CheckBox, "toolbar", "Show toolbar");
toolbar->setDefaultValue ("true");
}
declareSection ("report-input", "Reports");
{ {
QString none ("None"); QString none ("None");
QString edit ("Edit"); QString edit ("Edit");
@ -257,7 +263,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
shiftCtrlDoubleClick->setDefaultValue (none); shiftCtrlDoubleClick->setDefaultValue (none);
shiftCtrlDoubleClick->setToolTip ("Action on shift control double click in report table:<p>" + toolTip); shiftCtrlDoubleClick->setToolTip ("Action on shift control double click in report table:<p>" + toolTip);
} }
declareSection ("search", "Search & Replace"); declareSection ("search", "Search & Replace");
{ {
Setting *before = createSetting (Type_SpinBox, "char-before", Setting *before = createSetting (Type_SpinBox, "char-before",
@ -299,7 +305,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
QStringList modes; QStringList modes;
modes << "Ignore" << modeNormal << "Strict"; modes << "Ignore" << modeNormal << "Strict";
Setting *warnings = createSetting (Type_ComboBox, "warnings", Setting *warnings = createSetting (Type_ComboBox, "warnings",
"Warning Mode"); "Warning Mode");
warnings->setDeclaredValues (modes); warnings->setDeclaredValues (modes);
@ -309,7 +315,16 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
"<li>Normal: Report warning as a warning</li>" "<li>Normal: Report warning as a warning</li>"
"<li>Strict: Promote warning to an error</li>" "<li>Strict: Promote warning to an error</li>"
"</ul>"); "</ul>");
Setting *toolbar = createSetting (Type_CheckBox, "toolbar", "Show toolbar");
toolbar->setDefaultValue ("true");
Setting *delay = createSetting (Type_SpinBox, "compile-delay",
"Delay between updating of source errors");
delay->setDefaultValue (100);
delay->setRange (0, 10000);
delay->setToolTip ("Delay in milliseconds");
Setting *formatInt = createSetting (Type_LineEdit, "colour-int", "Highlight Colour: Int"); Setting *formatInt = createSetting (Type_LineEdit, "colour-int", "Highlight Colour: Int");
formatInt->setDefaultValues (QStringList() << "Dark magenta"); formatInt->setDefaultValues (QStringList() << "Dark magenta");
formatInt->setToolTip ("(Default: Green) Use one of the following formats:" + tooltip); formatInt->setToolTip ("(Default: Green) Use one of the following formats:" + tooltip);
@ -346,7 +361,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
cycle->setToolTip ("When using next/previous functions at the last/first item of a " cycle->setToolTip ("When using next/previous functions at the last/first item of a "
"list go to the first/last item"); "list go to the first/last item");
} }
{ {
/****************************************************************** /******************************************************************
* There are three types of values: * There are three types of values:

View file

@ -13,7 +13,7 @@ CSMTools::ReportModel::ReportModel (bool fieldColumn, bool severityColumn)
if (severityColumn) if (severityColumn)
mColumnSeverity = index++; mColumnSeverity = index++;
if (fieldColumn) if (fieldColumn)
mColumnField = index++; mColumnField = index++;
@ -46,7 +46,7 @@ QVariant CSMTools::ReportModel::data (const QModelIndex & index, int role) const
case Column_Type: case Column_Type:
return static_cast<int> (mRows.at (index.row()).mId.getType()); return static_cast<int> (mRows.at (index.row()).mId.getType());
case Column_Id: case Column_Id:
{ {
CSMWorld::UniversalId id = mRows.at (index.row()).mId; CSMWorld::UniversalId id = mRows.at (index.row()).mId;
@ -56,7 +56,7 @@ QVariant CSMTools::ReportModel::data (const QModelIndex & index, int role) const
return QString ("-"); return QString ("-");
} }
case Column_Hint: case Column_Hint:
return QString::fromUtf8 (mRows.at (index.row()).mHint.c_str()); return QString::fromUtf8 (mRows.at (index.row()).mHint.c_str());
@ -85,16 +85,10 @@ QVariant CSMTools::ReportModel::data (const QModelIndex & index, int role) const
if (index.column()==mColumnSeverity) if (index.column()==mColumnSeverity)
{ {
switch (mRows.at (index.row()).mSeverity) return QString::fromUtf8 (
{ CSMDoc::Message::toString (mRows.at (index.row()).mSeverity).c_str());
case CSMDoc::Message::Severity_Info: return "Information";
case CSMDoc::Message::Severity_Warning: return "Warning";
case CSMDoc::Message::Severity_Error: return "Error";
case CSMDoc::Message::Severity_SeriousError: return "Serious Error";
case CSMDoc::Message::Severity_Default: break;
}
} }
return QVariant(); return QVariant();
} }
@ -144,7 +138,7 @@ bool CSMTools::ReportModel::removeRows (int row, int count, const QModelIndex& p
void CSMTools::ReportModel::add (const CSMDoc::Message& message) void CSMTools::ReportModel::add (const CSMDoc::Message& message)
{ {
beginInsertRows (QModelIndex(), mRows.size(), mRows.size()); beginInsertRows (QModelIndex(), mRows.size(), mRows.size());
mRows.push_back (message); mRows.push_back (message);
endInsertRows(); endInsertRows();

View file

@ -16,7 +16,7 @@ void CSVTools::SearchSubView::replace (bool selection)
{ {
if (mLocked) if (mLocked)
return; return;
std::vector<int> indices = mTable->getReplaceIndices (selection); std::vector<int> indices = mTable->getReplaceIndices (selection);
std::string replace = mSearchBox.getReplaceText(); std::string replace = mSearchBox.getReplaceText();
@ -29,7 +29,7 @@ void CSVTools::SearchSubView::replace (bool selection)
CSMTools::Search search (mSearch); CSMTools::Search search (mSearch);
CSMWorld::IdTableBase *currentTable = 0; CSMWorld::IdTableBase *currentTable = 0;
// We are running through the indices in reverse order to avoid messing up multiple results // We are running through the indices in reverse order to avoid messing up multiple results
// in a single string. // in a single string.
for (std::vector<int>::const_reverse_iterator iter (indices.rbegin()); iter!=indices.rend(); ++iter) for (std::vector<int>::const_reverse_iterator iter (indices.rbegin()); iter!=indices.rend(); ++iter)
@ -46,7 +46,7 @@ void CSVTools::SearchSubView::replace (bool selection)
search.configure (table); search.configure (table);
currentTable = table; currentTable = table;
} }
std::string hint = model.getHint (*iter); std::string hint = model.getHint (*iter);
if (search.verify (mDocument, table, id, hint)) if (search.verify (mDocument, table, id, hint))
@ -63,7 +63,7 @@ void CSVTools::SearchSubView::replace (bool selection)
void CSVTools::SearchSubView::showEvent (QShowEvent *event) void CSVTools::SearchSubView::showEvent (QShowEvent *event)
{ {
CSVDoc::SubView::showEvent (event); CSVDoc::SubView::showEvent (event);
mSearchBox.focus(); mSearchBox.focus();
} }
CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
@ -71,25 +71,23 @@ CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc:
{ {
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins (QMargins (0, 0, 0, 0));
layout->addWidget (&mSearchBox); layout->addWidget (&mSearchBox);
layout->addWidget (mTable = new ReportTable (document, id, true), 2); layout->addWidget (mTable = new ReportTable (document, id, true), 2);
QWidget *widget = new QWidget; QWidget *widget = new QWidget;
widget->setLayout (layout); widget->setLayout (layout);
setWidget (widget); setWidget (widget);
stateChanged (document.getState(), &document); stateChanged (document.getState(), &document);
connect (mTable, SIGNAL (editRequest (const CSMWorld::UniversalId&, const std::string&)), connect (mTable, SIGNAL (editRequest (const CSMWorld::UniversalId&, const std::string&)),
SIGNAL (focusId (const CSMWorld::UniversalId&, const std::string&))); SIGNAL (focusId (const CSMWorld::UniversalId&, const std::string&)));
connect (mTable, SIGNAL (replaceRequest()), this, SLOT (replaceRequest())); connect (mTable, SIGNAL (replaceRequest()), this, SLOT (replaceRequest()));
connect (&document, SIGNAL (stateChanged (int, CSMDoc::Document *)), connect (&document, SIGNAL (stateChanged (int, CSMDoc::Document *)),
this, SLOT (stateChanged (int, CSMDoc::Document *))); this, SLOT (stateChanged (int, CSMDoc::Document *)));
@ -124,7 +122,7 @@ void CSVTools::SearchSubView::startSearch (const CSMTools::Search& search)
mSearch = search; mSearch = search;
mSearch.setPadding (paddingBefore, paddingAfter); mSearch.setPadding (paddingBefore, paddingAfter);
mTable->clear(); mTable->clear();
mDocument.runSearch (getUniversalId(), mSearch); mDocument.runSearch (getUniversalId(), mSearch);
} }

View file

@ -31,6 +31,7 @@
#include "../../model/world/idtree.hpp" #include "../../model/world/idtree.hpp"
#include "../../model/world/commands.hpp" #include "../../model/world/commands.hpp"
#include "../../model/doc/document.hpp" #include "../../model/doc/document.hpp"
#include "../../model/settings/usersettings.hpp"
#include "../widget/coloreditor.hpp" #include "../widget/coloreditor.hpp"
#include "../widget/droplineedit.hpp" #include "../widget/droplineedit.hpp"
@ -66,7 +67,7 @@ void CSVWorld::NotEditableSubDelegate::setEditorData (QWidget* editor, const QMo
CSMWorld::Columns::ColumnId columnId = static_cast<CSMWorld::Columns::ColumnId> ( CSMWorld::Columns::ColumnId columnId = static_cast<CSMWorld::Columns::ColumnId> (
mTable->getColumnId (index.column())); mTable->getColumnId (index.column()));
if (QVariant::String == v.type()) if (QVariant::String == v.type())
{ {
label->setText(v.toString()); label->setText(v.toString());
@ -75,7 +76,7 @@ void CSVWorld::NotEditableSubDelegate::setEditorData (QWidget* editor, const QMo
{ {
int data = v.toInt(); int data = v.toInt();
std::vector<std::string> enumNames (CSMWorld::Columns::getEnums (columnId)); std::vector<std::string> enumNames (CSMWorld::Columns::getEnums (columnId));
label->setText(QString::fromUtf8(enumNames.at(data).c_str())); label->setText(QString::fromUtf8(enumNames.at(data).c_str()));
} }
else else
@ -324,11 +325,11 @@ CSVWorld::IdContextMenu::IdContextMenu(QWidget *widget, CSMWorld::ColumnBase::Di
Q_ASSERT(mWidget != NULL); Q_ASSERT(mWidget != NULL);
Q_ASSERT(CSMWorld::ColumnBase::isId(display)); Q_ASSERT(CSMWorld::ColumnBase::isId(display));
Q_ASSERT(mIdType != CSMWorld::UniversalId::Type_None); Q_ASSERT(mIdType != CSMWorld::UniversalId::Type_None);
mWidget->setContextMenuPolicy(Qt::CustomContextMenu); mWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mWidget, connect(mWidget,
SIGNAL(customContextMenuRequested(const QPoint &)), SIGNAL(customContextMenuRequested(const QPoint &)),
this, this,
SLOT(showContextMenu(const QPoint &))); SLOT(showContextMenu(const QPoint &)));
mEditIdAction = new QAction(this); mEditIdAction = new QAction(this);
@ -352,7 +353,7 @@ void CSVWorld::IdContextMenu::excludeId(const std::string &id)
QString CSVWorld::IdContextMenu::getWidgetValue() const QString CSVWorld::IdContextMenu::getWidgetValue() const
{ {
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(mWidget); QLineEdit *lineEdit = qobject_cast<QLineEdit *>(mWidget);
QLabel *label = qobject_cast<QLabel *>(mWidget); QLabel *label = qobject_cast<QLabel *>(mWidget);
QString value = ""; QString value = "";
@ -411,7 +412,7 @@ void CSVWorld::IdContextMenu::showContextMenu(const QPoint &pos)
{ {
removeEditIdActionFromMenu(); removeEditIdActionFromMenu();
} }
if (!mContextMenu->actions().isEmpty()) if (!mContextMenu->actions().isEmpty())
{ {
mContextMenu->exec(mWidget->mapToGlobal(pos)); mContextMenu->exec(mWidget->mapToGlobal(pos));
@ -588,9 +589,9 @@ void CSVWorld::EditWidget::remake(int row)
tablesLayout->addWidget(label); tablesLayout->addWidget(label);
tablesLayout->addWidget(table); tablesLayout->addWidget(table);
connect(table, connect(table,
SIGNAL(editRequest(const CSMWorld::UniversalId &, const std::string &)), SIGNAL(editRequest(const CSMWorld::UniversalId &, const std::string &)),
this, this,
SIGNAL(editIdRequest(const CSMWorld::UniversalId &, const std::string &))); SIGNAL(editIdRequest(const CSMWorld::UniversalId &, const std::string &)));
} }
else if (!(flags & CSMWorld::ColumnBase::Flag_Dialogue_List)) else if (!(flags & CSMWorld::ColumnBase::Flag_Dialogue_List))
@ -830,45 +831,74 @@ void CSVWorld::SimpleDialogueSubView::updateCurrentId()
} }
CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, void CSVWorld::DialogueSubView::addButtonBar()
CSMDoc::Document& document, const CreatorFactoryBase& creatorFactory, bool sorting)
: SimpleDialogueSubView (id, document)
{ {
// bottom box if (mButtons)
mBottom = new TableBottomBox (creatorFactory, document, id, this); return;
mBottom->setSizePolicy (QSizePolicy::Ignored, QSizePolicy::Fixed); mButtons = new RecordButtonBar (getUniversalId(), getTable(), mBottom,
connect (mBottom, SIGNAL (requestFocus (const std::string&)),
this, SLOT (requestFocus (const std::string&)));
// button bar
mButtons = new RecordButtonBar (id, getTable(), mBottom,
&getCommandDispatcher(), this); &getCommandDispatcher(), this);
// layout getMainLayout().insertWidget (1, mButtons);
getMainLayout().addWidget (mButtons);
getMainLayout().addWidget (mBottom);
// connections // connections
connect (mButtons, SIGNAL (showPreview()), this, SLOT (showPreview())); connect (mButtons, SIGNAL (showPreview()), this, SLOT (showPreview()));
connect (mButtons, SIGNAL (viewRecord()), this, SLOT (viewRecord())); connect (mButtons, SIGNAL (viewRecord()), this, SLOT (viewRecord()));
connect (mButtons, SIGNAL (switchToRow (int)), this, SLOT (switchToRow (int))); connect (mButtons, SIGNAL (switchToRow (int)), this, SLOT (switchToRow (int)));
connect (this, SIGNAL (universalIdChanged (const CSMWorld::UniversalId&)), connect (this, SIGNAL (universalIdChanged (const CSMWorld::UniversalId&)),
mButtons, SLOT (universalIdChanged (const CSMWorld::UniversalId&))); mButtons, SLOT (universalIdChanged (const CSMWorld::UniversalId&)));
} }
CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id,
CSMDoc::Document& document, const CreatorFactoryBase& creatorFactory, bool sorting)
: SimpleDialogueSubView (id, document), mButtons (0)
{
// bottom box
mBottom = new TableBottomBox (creatorFactory, document, id, this);
connect (mBottom, SIGNAL (requestFocus (const std::string&)),
this, SLOT (requestFocus (const std::string&)));
// button bar
if (CSMSettings::UserSettings::instance().setting ("dialogues/toolbar", QString("true")) == "true")
addButtonBar();
// layout
getMainLayout().addWidget (mBottom);
}
void CSVWorld::DialogueSubView::setEditLock (bool locked) void CSVWorld::DialogueSubView::setEditLock (bool locked)
{ {
SimpleDialogueSubView::setEditLock (locked); SimpleDialogueSubView::setEditLock (locked);
mButtons->setEditLock (locked);
if (mButtons)
mButtons->setEditLock (locked);
} }
void CSVWorld::DialogueSubView::updateUserSetting (const QString& name, const QStringList& value) void CSVWorld::DialogueSubView::updateUserSetting (const QString& name, const QStringList& value)
{ {
SimpleDialogueSubView::updateUserSetting (name, value); SimpleDialogueSubView::updateUserSetting (name, value);
mButtons->updateUserSetting (name, value);
if (name=="dialogues/toolbar")
{
if (value.at(0)==QString ("true"))
{
addButtonBar();
}
else
{
if (mButtons)
{
getMainLayout().removeWidget (mButtons);
delete mButtons;
mButtons = 0;
}
}
}
if (mButtons)
mButtons->updateUserSetting (name, value);
} }
void CSVWorld::DialogueSubView::showPreview () void CSVWorld::DialogueSubView::showPreview ()
@ -908,7 +938,7 @@ void CSVWorld::DialogueSubView::switchToRow (int row)
setUniversalId (CSMWorld::UniversalId (type, id)); setUniversalId (CSMWorld::UniversalId (type, id));
updateCurrentId(); updateCurrentId();
getEditWidget().remake (row); getEditWidget().remake (row);
int stateColumn = getTable().findColumnIndex (CSMWorld::Columns::ColumnId_Modification); int stateColumn = getTable().findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
@ -923,5 +953,5 @@ void CSVWorld::DialogueSubView::requestFocus (const std::string& id)
QModelIndex index = getTable().getModelIndex (id, 0); QModelIndex index = getTable().getModelIndex (id, 0);
if (index.isValid()) if (index.isValid())
switchToRow (index.row()); switchToRow (index.row());
} }

View file

@ -195,8 +195,8 @@ namespace CSVWorld
CSMDoc::Document& mDocument; CSMDoc::Document& mDocument;
std::vector<CSMWorld::NestedTableProxyModel*> mNestedModels; //Plain, raw C pointers, deleted in the dtor std::vector<CSMWorld::NestedTableProxyModel*> mNestedModels; //Plain, raw C pointers, deleted in the dtor
void createEditorContextMenu(QWidget *editor, void createEditorContextMenu(QWidget *editor,
CSMWorld::ColumnBase::Display display, CSMWorld::ColumnBase::Display display,
int currentRow) const; int currentRow) const;
public: public:
@ -236,7 +236,7 @@ namespace CSVWorld
void updateCurrentId(); void updateCurrentId();
bool isLocked() const; bool isLocked() const;
public: public:
SimpleDialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document); SimpleDialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
@ -256,10 +256,14 @@ namespace CSVWorld
class DialogueSubView : public SimpleDialogueSubView class DialogueSubView : public SimpleDialogueSubView
{ {
Q_OBJECT Q_OBJECT
TableBottomBox* mBottom; TableBottomBox* mBottom;
RecordButtonBar *mButtons; RecordButtonBar *mButtons;
private:
void addButtonBar();
public: public:
DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document,
@ -268,14 +272,14 @@ namespace CSVWorld
virtual void setEditLock (bool locked); virtual void setEditLock (bool locked);
virtual void updateUserSetting (const QString& name, const QStringList& value); virtual void updateUserSetting (const QString& name, const QStringList& value);
private slots: private slots:
void showPreview(); void showPreview();
void viewRecord(); void viewRecord();
void switchToRow (int row); void switchToRow (int row);
void requestFocus (const std::string& id); void requestFocus (const std::string& id);
}; };

View file

@ -13,8 +13,6 @@ CSVWorld::PreviewSubView::PreviewSubView (const CSMWorld::UniversalId& id, CSMDo
{ {
QHBoxLayout *layout = new QHBoxLayout; QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins (QMargins (0, 0, 0, 0));
if (document.getData().getReferenceables().searchId (id.getId())==-1) if (document.getData().getReferenceables().searchId (id.getId())==-1)
{ {
std::string referenceableId = std::string referenceableId =

View file

@ -17,18 +17,17 @@ void CSVWorld::RecordButtonBar::updateModificationButtons()
mCloneButton->setDisabled (createAndDeleteDisabled); mCloneButton->setDisabled (createAndDeleteDisabled);
mAddButton->setDisabled (createAndDeleteDisabled); mAddButton->setDisabled (createAndDeleteDisabled);
mDeleteButton->setDisabled (createAndDeleteDisabled);
bool commandDisabled = !mCommandDispatcher || mLocked; bool commandDisabled = !mCommandDispatcher || mLocked;
mRevertButton->setDisabled (commandDisabled); mRevertButton->setDisabled (commandDisabled);
mDeleteButton->setDisabled (commandDisabled); mDeleteButton->setDisabled (commandDisabled || createAndDeleteDisabled);
} }
void CSVWorld::RecordButtonBar::updatePrevNextButtons() void CSVWorld::RecordButtonBar::updatePrevNextButtons()
{ {
int rows = mTable.rowCount(); int rows = mTable.rowCount();
if (rows<=1) if (rows<=1)
{ {
mPrevButton->setDisabled (true); mPrevButton->setDisabled (true);
@ -62,12 +61,12 @@ CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id,
mPrevButton->setIcon(QIcon(":/go-previous.png")); mPrevButton->setIcon(QIcon(":/go-previous.png"));
mPrevButton->setToolTip ("Switch to previous record"); mPrevButton->setToolTip ("Switch to previous record");
buttonsLayout->addWidget (mPrevButton, 0); buttonsLayout->addWidget (mPrevButton, 0);
mNextButton = new QToolButton (this); mNextButton = new QToolButton (this);
mNextButton->setIcon(QIcon(":/go-next.png")); mNextButton->setIcon(QIcon(":/go-next.png"));
mNextButton->setToolTip ("Switch to next record"); mNextButton->setToolTip ("Switch to next record");
buttonsLayout->addWidget (mNextButton, 1); buttonsLayout->addWidget (mNextButton, 1);
buttonsLayout->addStretch(2); buttonsLayout->addStretch(2);
// optional buttons of the right section // optional buttons of the right section
@ -94,22 +93,22 @@ CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id,
mCloneButton->setIcon(QIcon(":/edit-clone.png")); mCloneButton->setIcon(QIcon(":/edit-clone.png"));
mCloneButton->setToolTip ("Clone record"); mCloneButton->setToolTip ("Clone record");
buttonsLayout->addWidget(mCloneButton); buttonsLayout->addWidget(mCloneButton);
mAddButton = new QToolButton (this); mAddButton = new QToolButton (this);
mAddButton->setIcon(QIcon(":/add.png")); mAddButton->setIcon(QIcon(":/add.png"));
mAddButton->setToolTip ("Add new record"); mAddButton->setToolTip ("Add new record");
buttonsLayout->addWidget(mAddButton); buttonsLayout->addWidget(mAddButton);
mDeleteButton = new QToolButton (this); mDeleteButton = new QToolButton (this);
mDeleteButton->setIcon(QIcon(":/edit-delete.png")); mDeleteButton->setIcon(QIcon(":/edit-delete.png"));
mDeleteButton->setToolTip ("Delete record"); mDeleteButton->setToolTip ("Delete record");
buttonsLayout->addWidget(mDeleteButton); buttonsLayout->addWidget(mDeleteButton);
mRevertButton = new QToolButton (this); mRevertButton = new QToolButton (this);
mRevertButton->setIcon(QIcon(":/edit-undo.png")); mRevertButton->setIcon(QIcon(":/edit-undo.png"));
mRevertButton->setToolTip ("Revert record"); mRevertButton->setToolTip ("Revert record");
buttonsLayout->addWidget(mRevertButton); buttonsLayout->addWidget(mRevertButton);
setLayout (buttonsLayout); setLayout (buttonsLayout);
// connections // connections
@ -132,7 +131,7 @@ CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id,
this, SLOT (rowNumberChanged (const QModelIndex&, int, int))); this, SLOT (rowNumberChanged (const QModelIndex&, int, int)));
connect (&mTable, SIGNAL (rowsRemoved (const QModelIndex&, int, int)), connect (&mTable, SIGNAL (rowsRemoved (const QModelIndex&, int, int)),
this, SLOT (rowNumberChanged (const QModelIndex&, int, int))); this, SLOT (rowNumberChanged (const QModelIndex&, int, int)));
updateModificationButtons(); updateModificationButtons();
updatePrevNextButtons(); updatePrevNextButtons();
} }
@ -170,7 +169,7 @@ void CSVWorld::RecordButtonBar::cloneRequest()
} }
void CSVWorld::RecordButtonBar::nextId() void CSVWorld::RecordButtonBar::nextId()
{ {
int newRow = mTable.getModelIndex (mId.getId(), 0).row() + 1; int newRow = mTable.getModelIndex (mId.getId(), 0).row() + 1;
if (newRow >= mTable.rowCount()) if (newRow >= mTable.rowCount())
@ -180,8 +179,8 @@ void CSVWorld::RecordButtonBar::nextId()
newRow = 0; newRow = 0;
else else
return; return;
} }
emit switchToRow (newRow); emit switchToRow (newRow);
} }
@ -197,7 +196,7 @@ void CSVWorld::RecordButtonBar::prevId()
else else
return; return;
} }
emit switchToRow (newRow); emit switchToRow (newRow);
} }

View file

@ -31,8 +31,6 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D
{ {
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins (QMargins (0, 0, 0, 0));
layout->addWidget (mBottom = new TableBottomBox (NullCreatorFactory(), document, id, this), 0); layout->addWidget (mBottom = new TableBottomBox (NullCreatorFactory(), document, id, this), 0);
mLayout->setContentsMargins (QMargins (0, 0, 0, 0)); mLayout->setContentsMargins (QMargins (0, 0, 0, 0));

View file

@ -0,0 +1,138 @@
#include "scripterrortable.hpp"
#include <QHeaderView>
#include <components/compiler/tokenloc.hpp>
#include <components/compiler/scanner.hpp>
#include <components/compiler/fileparser.hpp>
#include <components/compiler/exception.hpp>
#include <components/compiler/extensions0.hpp>
#include "../../model/doc/document.hpp"
#include "../../model/settings/usersettings.hpp"
void CSVWorld::ScriptErrorTable::report (const std::string& message, const Compiler::TokenLoc& loc, Type type)
{
std::ostringstream stream;
stream << message << " (" << loc.mLiteral << ")";
addMessage (stream.str(), type==Compiler::ErrorHandler::WarningMessage ?
CSMDoc::Message::Severity_Warning : CSMDoc::Message::Severity_Error,
loc.mLine, loc.mColumn-loc.mLiteral.length());
}
void CSVWorld::ScriptErrorTable::report (const std::string& message, Type type)
{
addMessage (message, type==Compiler::ErrorHandler::WarningMessage ?
CSMDoc::Message::Severity_Warning : CSMDoc::Message::Severity_Error);
}
void CSVWorld::ScriptErrorTable::addMessage (const std::string& message,
CSMDoc::Message::Severity severity, int line, int column)
{
int row = rowCount();
setRowCount (row+1);
QTableWidgetItem *severityItem = new QTableWidgetItem (
QString::fromUtf8 (CSMDoc::Message::toString (severity).c_str()));
severityItem->setFlags (severityItem->flags() ^ Qt::ItemIsEditable);
setItem (row, 0, severityItem);
if (line!=-1)
{
QTableWidgetItem *lineItem = new QTableWidgetItem;
lineItem->setData (Qt::DisplayRole, line+1);
lineItem->setFlags (lineItem->flags() ^ Qt::ItemIsEditable);
setItem (row, 1, lineItem);
QTableWidgetItem *columnItem = new QTableWidgetItem;
columnItem->setData (Qt::DisplayRole, column);
columnItem->setFlags (columnItem->flags() ^ Qt::ItemIsEditable);
setItem (row, 3, columnItem);
}
QTableWidgetItem *messageItem = new QTableWidgetItem (QString::fromUtf8 (message.c_str()));
messageItem->setFlags (messageItem->flags() ^ Qt::ItemIsEditable);
setItem (row, 2, messageItem);
}
void CSVWorld::ScriptErrorTable::setWarningsMode (const QString& value)
{
if (value=="Ignore")
Compiler::ErrorHandler::setWarningsMode (0);
else if (value=="Normal")
Compiler::ErrorHandler::setWarningsMode (1);
else if (value=="Strict")
Compiler::ErrorHandler::setWarningsMode (2);
}
CSVWorld::ScriptErrorTable::ScriptErrorTable (const CSMDoc::Document& document, QWidget *parent)
: QTableWidget (parent), mContext (document.getData())
{
setColumnCount (4);
QStringList headers;
headers << "Severity" << "Line" << "Description";
setHorizontalHeaderLabels (headers);
horizontalHeader()->setResizeMode (0, QHeaderView::ResizeToContents);
horizontalHeader()->setResizeMode (1, QHeaderView::ResizeToContents);
horizontalHeader()->setStretchLastSection (true);
verticalHeader()->hide();
setColumnHidden (3, true);
setSelectionMode (QAbstractItemView::NoSelection);
Compiler::registerExtensions (mExtensions);
mContext.setExtensions (&mExtensions);
setWarningsMode (CSMSettings::UserSettings::instance().settingValue ("script-editor/warnings"));
connect (this, SIGNAL (cellClicked (int, int)), this, SLOT (cellClicked (int, int)));
}
void CSVWorld::ScriptErrorTable::updateUserSetting (const QString& name, const QStringList& value)
{
if (name=="script-editor/warnings" && !value.isEmpty())
setWarningsMode (value.at (0));
}
void CSVWorld::ScriptErrorTable::update (const std::string& source)
{
clear();
try
{
std::istringstream input (source);
Compiler::Scanner scanner (*this, input, mContext.getExtensions());
Compiler::FileParser parser (*this, mContext);
scanner.scan (parser);
}
catch (const Compiler::SourceException&)
{
// error has already been reported via error handler
}
catch (const std::exception& error)
{
addMessage (error.what(), CSMDoc::Message::Severity_SeriousError);
}
}
void CSVWorld::ScriptErrorTable::clear()
{
setRowCount (0);
}
void CSVWorld::ScriptErrorTable::cellClicked (int row, int column)
{
if (item (row, 1))
{
int scriptLine = item (row, 1)->data (Qt::DisplayRole).toInt();
int scriptColumn = item (row, 3)->data (Qt::DisplayRole).toInt();
emit highlightError (scriptLine-1, scriptColumn);
}
}

View file

@ -0,0 +1,57 @@
#ifndef CSV_WORLD_SCRIPTERRORTABLE_H
#define CSV_WORLD_SCRIPTERRORTABLE_H
#include <QTableWidget>
#include <components/compiler/errorhandler.hpp>
#include <components/compiler/extensions.hpp>
#include "../../model/world/scriptcontext.hpp"
#include "../../model/doc/messages.hpp"
namespace CSMDoc
{
class Document;
}
namespace CSVWorld
{
class ScriptErrorTable : public QTableWidget, private Compiler::ErrorHandler
{
Q_OBJECT
Compiler::Extensions mExtensions;
CSMWorld::ScriptContext mContext;
virtual void report (const std::string& message, const Compiler::TokenLoc& loc, Type type);
///< Report error to the user.
virtual void report (const std::string& message, Type type);
///< Report a file related error
void addMessage (const std::string& message, CSMDoc::Message::Severity severity,
int line = -1, int column = -1);
void setWarningsMode (const QString& value);
public:
ScriptErrorTable (const CSMDoc::Document& document, QWidget *parent = 0);
void updateUserSetting (const QString& name, const QStringList& value);
void update (const std::string& source);
void clear();
private slots:
void cellClicked (int row, int column);
signals:
void highlightError (int line, int column);
};
}
#endif

View file

@ -4,7 +4,8 @@
#include <QStatusBar> #include <QStatusBar>
#include <QStackedLayout> #include <QStackedLayout>
#include <QLabel> #include <QSplitter>
#include <QTimer>
#include "../../model/doc/document.hpp" #include "../../model/doc/document.hpp"
#include "../../model/world/universalid.hpp" #include "../../model/world/universalid.hpp"
@ -15,45 +16,96 @@
#include "../../model/settings/usersettings.hpp" #include "../../model/settings/usersettings.hpp"
#include "scriptedit.hpp" #include "scriptedit.hpp"
#include "recordbuttonbar.hpp"
#include "tablebottombox.hpp"
#include "genericcreator.hpp"
#include "scripterrortable.hpp"
void CSVWorld::ScriptSubView::addButtonBar()
{
if (mButtons)
return;
mButtons = new RecordButtonBar (getUniversalId(), *mModel, mBottom, &mCommandDispatcher, this);
mLayout.insertWidget (1, mButtons);
connect (mButtons, SIGNAL (switchToRow (int)), this, SLOT (switchToRow (int)));
connect (this, SIGNAL (universalIdChanged (const CSMWorld::UniversalId&)),
mButtons, SLOT (universalIdChanged (const CSMWorld::UniversalId&)));
}
void CSVWorld::ScriptSubView::recompile()
{
if (!mCompileDelay->isActive() && !isDeleted())
mCompileDelay->start (
CSMSettings::UserSettings::instance().setting ("script-editor/compile-delay").toInt());
}
bool CSVWorld::ScriptSubView::isDeleted() const
{
return mModel->data (mModel->getModelIndex (getUniversalId().getId(), mStateColumn)).toInt()
==CSMWorld::RecordBase::State_Deleted;
}
void CSVWorld::ScriptSubView::updateDeletedState()
{
if (isDeleted())
{
mErrors->clear();
mEditor->setEnabled (false);
}
else
{
mEditor->setEnabled (true);
recompile();
}
}
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
: SubView (id), mDocument (document), mColumn (-1), mBottom(0), mStatus(0) : SubView (id), mDocument (document), mColumn (-1), mBottom(0), mButtons (0),
mCommandDispatcher (document, CSMWorld::UniversalId::getParentType (id.getType()))
{ {
QVBoxLayout *layout = new QVBoxLayout; std::vector<std::string> selection (1, id.getId());
layout->setContentsMargins (QMargins (0, 0, 0, 0)); mCommandDispatcher.setSelection (selection);
mBottom = new QWidget(this); mMain = new QSplitter (this);
QStackedLayout *bottmLayout = new QStackedLayout(mBottom); mMain->setOrientation (Qt::Vertical);
bottmLayout->setContentsMargins (0, 0, 0, 0); mLayout.addWidget (mMain, 2);
QStatusBar *statusBar = new QStatusBar(mBottom);
mStatus = new QLabel(mBottom);
statusBar->addWidget (mStatus);
bottmLayout->addWidget (statusBar);
mBottom->setLayout (bottmLayout);
layout->addWidget (mBottom, 0); mEditor = new ScriptEdit (mDocument, ScriptHighlighter::Mode_General, this);
layout->insertWidget (0, mEditor = new ScriptEdit (mDocument, ScriptHighlighter::Mode_General, this), 2); mMain->addWidget (mEditor);
mMain->setCollapsible (0, false);
QWidget *widget = new QWidget; mErrors = new ScriptErrorTable (document, this);
widget->setLayout (layout); mMain->addWidget (mErrors);
QWidget *widget = new QWidget (this);;
widget->setLayout (&mLayout);
setWidget (widget); setWidget (widget);
mModel = &dynamic_cast<CSMWorld::IdTable&> ( mModel = &dynamic_cast<CSMWorld::IdTable&> (
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Scripts)); *document.getData().getTableModel (CSMWorld::UniversalId::Type_Scripts));
for (int i=0; i<mModel->columnCount(); ++i) mColumn = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_ScriptText);
if (mModel->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display)== mStateColumn = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
CSMWorld::ColumnBase::Display_ScriptFile)
{
mColumn = i;
break;
}
if (mColumn==-1) QString source = mModel->data (mModel->getModelIndex (id.getId(), mColumn)).toString();
throw std::logic_error ("Can't find script column");
mEditor->setPlainText (mModel->data (mModel->getModelIndex (id.getId(), mColumn)).toString()); mEditor->setPlainText (source);
// bottom box and buttons
mBottom = new TableBottomBox (CreatorFactory<GenericCreator>(), document, id, this);
if (CSMSettings::UserSettings::instance().setting ("script-editor/toolbar", QString("true")) == "true")
addButtonBar();
connect (mBottom, SIGNAL (requestFocus (const std::string&)),
this, SLOT (switchToId (const std::string&)));
mLayout.addWidget (mBottom);
// signals
connect (mEditor, SIGNAL (textChanged()), this, SLOT (textChanged())); connect (mEditor, SIGNAL (textChanged()), this, SLOT (textChanged()));
connect (mModel, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)), connect (mModel, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
@ -64,35 +116,80 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
updateStatusBar(); updateStatusBar();
connect(mEditor, SIGNAL(cursorPositionChanged()), this, SLOT(updateStatusBar())); connect(mEditor, SIGNAL(cursorPositionChanged()), this, SLOT(updateStatusBar()));
mErrors->update (source.toUtf8().constData());
connect (mErrors, SIGNAL (highlightError (int, int)),
this, SLOT (highlightError (int, int)));
mCompileDelay = new QTimer (this);
mCompileDelay->setSingleShot (true);
connect (mCompileDelay, SIGNAL (timeout()), this, SLOT (updateRequest()));
updateDeletedState();
} }
void CSVWorld::ScriptSubView::updateUserSetting (const QString& name, const QStringList& value) void CSVWorld::ScriptSubView::updateUserSetting (const QString& name, const QStringList& value)
{ {
if (name == "script-editor/show-linenum") if (name == "script-editor/show-linenum")
{ {
std::string showLinenum = value.at(0).toStdString(); std::string showLinenum = value.at(0).toUtf8().constData();
mEditor->showLineNum(showLinenum == "true"); mEditor->showLineNum(showLinenum == "true");
mBottom->setVisible(showLinenum == "true"); mBottom->setVisible(showLinenum == "true");
} }
else if (name == "script-editor/mono-font") else if (name == "script-editor/mono-font")
{ {
mEditor->setMonoFont(value.at(0).toStdString() == "true"); mEditor->setMonoFont (value.at(0)==QString ("true"));
} }
else if (name=="script-editor/toolbar")
{
if (value.at(0)==QString ("true"))
{
addButtonBar();
}
else
{
if (mButtons)
{
mLayout.removeWidget (mButtons);
delete mButtons;
mButtons = 0;
}
}
}
else if (name=="script-editor/compile-delay")
{
mCompileDelay->setInterval (value.at (0).toInt());
}
if (mButtons)
mButtons->updateUserSetting (name, value);
mErrors->updateUserSetting (name, value);
if (name=="script-editor/warnings")
recompile();
}
void CSVWorld::ScriptSubView::setStatusBar (bool show)
{
mBottom->setStatusBar (show);
} }
void CSVWorld::ScriptSubView::updateStatusBar () void CSVWorld::ScriptSubView::updateStatusBar ()
{ {
std::ostringstream stream; mBottom->positionChanged (mEditor->textCursor().blockNumber() + 1,
mEditor->textCursor().columnNumber() + 1);
stream << "(" << mEditor->textCursor().blockNumber() + 1 << ", "
<< mEditor->textCursor().columnNumber() + 1 << ")";
mStatus->setText (QString::fromUtf8 (stream.str().c_str()));
} }
void CSVWorld::ScriptSubView::setEditLock (bool locked) void CSVWorld::ScriptSubView::setEditLock (bool locked)
{ {
mEditor->setReadOnly (locked); mEditor->setReadOnly (locked);
if (mButtons)
mButtons->setEditLock (locked);
mCommandDispatcher.setEditLock (locked);
} }
void CSVWorld::ScriptSubView::useHint (const std::string& hint) void CSVWorld::ScriptSubView::useHint (const std::string& hint)
@ -129,8 +226,12 @@ void CSVWorld::ScriptSubView::textChanged()
ScriptEdit::ChangeLock lock (*mEditor); ScriptEdit::ChangeLock lock (*mEditor);
QString source = mEditor->toPlainText();
mDocument.getUndoStack().push (new CSMWorld::ModifyCommand (*mModel, mDocument.getUndoStack().push (new CSMWorld::ModifyCommand (*mModel,
mModel->getModelIndex (getUniversalId().getId(), mColumn), mEditor->toPlainText())); mModel->getModelIndex (getUniversalId().getId(), mColumn), source));
recompile();
} }
void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight)
@ -142,12 +243,21 @@ void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QMo
QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn); QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn);
if (index.row()>=topLeft.row() && index.row()<=bottomRight.row() && if (index.row()>=topLeft.row() && index.row()<=bottomRight.row())
index.column()>=topLeft.column() && index.column()<=bottomRight.column())
{ {
QTextCursor cursor = mEditor->textCursor(); if (mStateColumn>=topLeft.column() && mStateColumn<=bottomRight.column())
mEditor->setPlainText (mModel->data (index).toString()); updateDeletedState();
mEditor->setTextCursor (cursor);
if (mColumn>=topLeft.column() && mColumn<=bottomRight.column())
{
QString source = mModel->data (index).toString();
QTextCursor cursor = mEditor->textCursor();
mEditor->setPlainText (source);
mEditor->setTextCursor (cursor);
recompile();
}
} }
} }
@ -159,3 +269,42 @@ void CSVWorld::ScriptSubView::rowsAboutToBeRemoved (const QModelIndex& parent, i
emit closeRequest(); emit closeRequest();
} }
void CSVWorld::ScriptSubView::switchToRow (int row)
{
int idColumn = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id);
std::string id = mModel->data (mModel->index (row, idColumn)).toString().toUtf8().constData();
setUniversalId (CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Script, id));
mEditor->setPlainText (mModel->data (mModel->index (row, mColumn)).toString());
std::vector<std::string> selection (1, id);
mCommandDispatcher.setSelection (selection);
updateDeletedState();
}
void CSVWorld::ScriptSubView::switchToId (const std::string& id)
{
switchToRow (mModel->getModelIndex (id, 0).row());
}
void CSVWorld::ScriptSubView::highlightError (int line, int column)
{
QTextCursor cursor = mEditor->textCursor();
cursor.movePosition (QTextCursor::Start);
if (cursor.movePosition (QTextCursor::Down, QTextCursor::MoveAnchor, line))
cursor.movePosition (QTextCursor::Right, QTextCursor::MoveAnchor, column);
mEditor->setFocus();
mEditor->setTextCursor (cursor);
}
void CSVWorld::ScriptSubView::updateRequest()
{
QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn);
QString source = mModel->data (index).toString();
mErrors->update (source.toUtf8().constData());
}

View file

@ -1,10 +1,17 @@
#ifndef CSV_WORLD_SCRIPTSUBVIEW_H #ifndef CSV_WORLD_SCRIPTSUBVIEW_H
#define CSV_WORLD_SCRIPTSUBVIEW_H #define CSV_WORLD_SCRIPTSUBVIEW_H
#include <QVBoxLayout>
#include "../../model/world/commanddispatcher.hpp"
#include "../doc/subview.hpp" #include "../doc/subview.hpp"
class QModelIndex; class QModelIndex;
class QLabel; class QLabel;
class QVBoxLayout;
class QSplitter;
class QTime;
namespace CSMDoc namespace CSMDoc
{ {
@ -19,6 +26,9 @@ namespace CSMWorld
namespace CSVWorld namespace CSVWorld
{ {
class ScriptEdit; class ScriptEdit;
class RecordButtonBar;
class TableBottomBox;
class ScriptErrorTable;
class ScriptSubView : public CSVDoc::SubView class ScriptSubView : public CSVDoc::SubView
{ {
@ -28,8 +38,24 @@ namespace CSVWorld
CSMDoc::Document& mDocument; CSMDoc::Document& mDocument;
CSMWorld::IdTable *mModel; CSMWorld::IdTable *mModel;
int mColumn; int mColumn;
QWidget *mBottom; int mStateColumn;
QLabel *mStatus; TableBottomBox *mBottom;
RecordButtonBar *mButtons;
CSMWorld::CommandDispatcher mCommandDispatcher;
QVBoxLayout mLayout;
QSplitter *mMain;
ScriptErrorTable *mErrors;
QTimer *mCompileDelay;
private:
void addButtonBar();
void recompile();
bool isDeleted() const;
void updateDeletedState();
public: public:
@ -41,6 +67,8 @@ namespace CSVWorld
virtual void updateUserSetting (const QString& name, const QStringList& value); virtual void updateUserSetting (const QString& name, const QStringList& value);
virtual void setStatusBar (bool show);
public slots: public slots:
void textChanged(); void textChanged();
@ -52,6 +80,14 @@ namespace CSVWorld
private slots: private slots:
void updateStatusBar(); void updateStatusBar();
void switchToRow (int row);
void switchToId (const std::string& id);
void highlightError (int line, int column);
void updateRequest();
}; };
} }

View file

@ -35,15 +35,23 @@ void CSVWorld::TableBottomBox::updateStatus()
} }
} }
if (mHasPosition)
{
if (!first)
stream << " -- ";
stream << "(" << mRow << ", " << mColumn << ")";
}
mStatus->setText (QString::fromUtf8 (stream.str().c_str())); mStatus->setText (QString::fromUtf8 (stream.str().c_str()));
} }
} }
CSVWorld::TableBottomBox::TableBottomBox (const CreatorFactoryBase& creatorFactory, CSVWorld::TableBottomBox::TableBottomBox (const CreatorFactoryBase& creatorFactory,
CSMDoc::Document& document, CSMDoc::Document& document,
const CSMWorld::UniversalId& id, const CSMWorld::UniversalId& id,
QWidget *parent) QWidget *parent)
: QWidget (parent), mShowStatusBar (false), mCreating (false) : QWidget (parent), mShowStatusBar (false), mCreating (false), mHasPosition (false)
{ {
for (int i=0; i<4; ++i) for (int i=0; i<4; ++i)
mStatusCount[i] = 0; mStatusCount[i] = 0;
@ -74,6 +82,8 @@ CSVWorld::TableBottomBox::TableBottomBox (const CreatorFactoryBase& creatorFacto
connect (mCreator, SIGNAL (requestFocus (const std::string&)), connect (mCreator, SIGNAL (requestFocus (const std::string&)),
this, SIGNAL (requestFocus (const std::string&))); this, SIGNAL (requestFocus (const std::string&)));
} }
setSizePolicy (QSizePolicy::Ignored, QSizePolicy::Fixed);
} }
void CSVWorld::TableBottomBox::setEditLock (bool locked) void CSVWorld::TableBottomBox::setEditLock (bool locked)
@ -152,6 +162,20 @@ void CSVWorld::TableBottomBox::tableSizeChanged (int size, int deleted, int modi
updateStatus(); updateStatus();
} }
void CSVWorld::TableBottomBox::positionChanged (int row, int column)
{
mRow = row;
mColumn = column;
mHasPosition = true;
updateStatus();
}
void CSVWorld::TableBottomBox::noMorePosition()
{
mHasPosition = false;
updateStatus();
}
void CSVWorld::TableBottomBox::createRequest() void CSVWorld::TableBottomBox::createRequest()
{ {
mCreator->reset(); mCreator->reset();
@ -162,8 +186,8 @@ void CSVWorld::TableBottomBox::createRequest()
mCreator->focus(); mCreator->focus();
} }
void CSVWorld::TableBottomBox::cloneRequest(const std::string& id, void CSVWorld::TableBottomBox::cloneRequest(const std::string& id,
const CSMWorld::UniversalId::Type type) const CSMWorld::UniversalId::Type type)
{ {
mCreator->reset(); mCreator->reset();
mCreator->cloneMode(id, type); mCreator->cloneMode(id, type);

View file

@ -30,6 +30,9 @@ namespace CSVWorld
Creator *mCreator; Creator *mCreator;
bool mCreating; bool mCreating;
QStackedLayout *mLayout; QStackedLayout *mLayout;
bool mHasPosition;
int mRow;
int mColumn;
private: private:
@ -41,9 +44,9 @@ namespace CSVWorld
public: public:
TableBottomBox (const CreatorFactoryBase& creatorFactory, TableBottomBox (const CreatorFactoryBase& creatorFactory,
CSMDoc::Document& document, CSMDoc::Document& document,
const CSMWorld::UniversalId& id, const CSMWorld::UniversalId& id,
QWidget *parent = 0); QWidget *parent = 0);
virtual ~TableBottomBox(); virtual ~TableBottomBox();
@ -77,6 +80,10 @@ namespace CSVWorld
/// \param deleted Number of deleted records /// \param deleted Number of deleted records
/// \param modified Number of added and modified records /// \param modified Number of added and modified records
void positionChanged (int row, int column);
void noMorePosition();
void createRequest(); void createRequest();
void cloneRequest(const std::string& id, void cloneRequest(const std::string& id,
const CSMWorld::UniversalId::Type type); const CSMWorld::UniversalId::Type type);

View file

@ -23,8 +23,6 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
{ {
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins (QMargins (0, 0, 0, 0));
layout->addWidget (mBottom = layout->addWidget (mBottom =
new TableBottomBox (creatorFactory, document, id, this), 0); new TableBottomBox (creatorFactory, document, id, this), 0);
@ -166,4 +164,3 @@ bool CSVWorld::TableSubView::eventFilter (QObject* object, QEvent* event)
} }
return false; return false;
} }