Merge branch 'globals'

pull/16/head
Marc Zinnschlag 12 years ago
commit cd662af634

@ -1,8 +1,8 @@
#include "columnbase.hpp" #include "columnbase.hpp"
CSMWorld::ColumnBase::ColumnBase (const std::string& title, int flags) CSMWorld::ColumnBase::ColumnBase (const std::string& title, Display displayType, int flags)
: mTitle (title), mFlags (flags) : mTitle (title), mDisplayType (displayType), mFlags (flags)
{} {}
CSMWorld::ColumnBase::~ColumnBase() {} CSMWorld::ColumnBase::~ColumnBase() {}

@ -14,7 +14,8 @@ namespace CSMWorld
{ {
enum Roles enum Roles
{ {
Role_Flags = Qt::UserRole Role_Flags = Qt::UserRole,
Role_Display = Qt::UserRole+1
}; };
enum Flags enum Flags
@ -23,10 +24,18 @@ namespace CSMWorld
Flag_Dialogue = 2 // column should be displayed in dialogue view Flag_Dialogue = 2 // column should be displayed in dialogue view
}; };
enum Display
{
Display_String,
Display_Integer,
Display_Float
};
std::string mTitle; std::string mTitle;
int mFlags; int mFlags;
Display mDisplayType;
ColumnBase (const std::string& title, int flag); ColumnBase (const std::string& title, Display displayType, int flag);
virtual ~ColumnBase(); virtual ~ColumnBase();
@ -34,6 +43,7 @@ namespace CSMWorld
virtual bool isUserEditable() const; virtual bool isUserEditable() const;
///< Can this column be edited directly by the user? ///< Can this column be edited directly by the user?
}; };
template<typename ESXRecordT> template<typename ESXRecordT>
@ -42,8 +52,8 @@ namespace CSMWorld
std::string mTitle; std::string mTitle;
int mFlags; int mFlags;
Column (const std::string& title, int flags = Flag_Table | Flag_Dialogue) Column (const std::string& title, Display displayType, int flags = Flag_Table | Flag_Dialogue)
: ColumnBase (title, flags) {} : ColumnBase (title, displayType, flags) {}
virtual QVariant get (const Record<ESXRecordT>& record) const = 0; virtual QVariant get (const Record<ESXRecordT>& record) const = 0;

@ -8,7 +8,7 @@ namespace CSMWorld
template<typename ESXRecordT> template<typename ESXRecordT>
struct FloatValueColumn : public Column<ESXRecordT> struct FloatValueColumn : public Column<ESXRecordT>
{ {
FloatValueColumn() : Column<ESXRecordT> ("Value") {} FloatValueColumn() : Column<ESXRecordT> ("Value", ColumnBase::Display_Float) {}
virtual QVariant get (const Record<ESXRecordT>& record) const virtual QVariant get (const Record<ESXRecordT>& record) const
{ {
@ -31,7 +31,7 @@ namespace CSMWorld
template<typename ESXRecordT> template<typename ESXRecordT>
struct StringIdColumn : public Column<ESXRecordT> struct StringIdColumn : public Column<ESXRecordT>
{ {
StringIdColumn() : Column<ESXRecordT> ("ID") {} StringIdColumn() : Column<ESXRecordT> ("ID", ColumnBase::Display_String) {}
virtual QVariant get (const Record<ESXRecordT>& record) const virtual QVariant get (const Record<ESXRecordT>& record) const
{ {
@ -47,7 +47,7 @@ namespace CSMWorld
template<typename ESXRecordT> template<typename ESXRecordT>
struct RecordStateColumn : public Column<ESXRecordT> struct RecordStateColumn : public Column<ESXRecordT>
{ {
RecordStateColumn() : Column<ESXRecordT> ("*") {} RecordStateColumn() : Column<ESXRecordT> ("*", ColumnBase::Display_Integer) {}
virtual QVariant get (const Record<ESXRecordT>& record) const virtual QVariant get (const Record<ESXRecordT>& record) const
{ {
@ -78,7 +78,8 @@ namespace CSMWorld
{ {
int mType; int mType;
FixedRecordTypeColumn (int type) : Column<ESXRecordT> ("Type", 0), mType (type) {} FixedRecordTypeColumn (int type)
: Column<ESXRecordT> ("Type", ColumnBase::Display_Integer, 0), mType (type) {}
virtual QVariant get (const Record<ESXRecordT>& record) const virtual QVariant get (const Record<ESXRecordT>& record) const
{ {

@ -51,6 +51,9 @@ QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation
if (role==ColumnBase::Role_Flags) if (role==ColumnBase::Role_Flags)
return mIdCollection->getColumn (section).mFlags; return mIdCollection->getColumn (section).mFlags;
if (role==ColumnBase::Role_Display)
return mIdCollection->getColumn (section).mDisplayType;
return QVariant(); return QVariant();
} }

@ -4,8 +4,13 @@
#include <QGridLayout> #include <QGridLayout>
#include <QLabel> #include <QLabel>
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include <QDoubleSpinBox>
#include <QSpinBox>
#include <QLineEdit>
#include <QDataWidgetMapper>
#include "../../model/world/columnbase.hpp" #include "../../model/world/columnbase.hpp"
#include "../../model/world/idtable.hpp"
CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document,
bool createAndDelete) bool createAndDelete)
@ -23,6 +28,9 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
int columns = model->columnCount(); int columns = model->columnCount();
mWidgetMapper = new QDataWidgetMapper (this);
mWidgetMapper->setModel (model);
for (int i=0; i<columns; ++i) for (int i=0; i<columns; ++i)
{ {
int flags = model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Flags).toInt(); int flags = model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Flags).toInt();
@ -30,8 +38,54 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
if (flags & CSMWorld::ColumnBase::Flag_Dialogue) if (flags & CSMWorld::ColumnBase::Flag_Dialogue)
{ {
layout->addWidget (new QLabel (model->headerData (i, Qt::Horizontal).toString()), i, 0); layout->addWidget (new QLabel (model->headerData (i, Qt::Horizontal).toString()), i, 0);
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
(model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
QWidget *widget = 0;
if (model->flags (model->index (0, i)) & Qt::ItemIsEditable)
{
switch (display)
{
case CSMWorld::ColumnBase::Display_String:
layout->addWidget (widget = new QLineEdit, i, 1);
break;
case CSMWorld::ColumnBase::Display_Integer:
/// \todo configure widget properly (range)
layout->addWidget (widget = new QSpinBox, i, 1);
break;
case CSMWorld::ColumnBase::Display_Float:
/// \todo configure widget properly (range, format?)
layout->addWidget (widget = new QDoubleSpinBox, i, 1);
break;
}
}
else
{
switch (display)
{
case CSMWorld::ColumnBase::Display_String:
case CSMWorld::ColumnBase::Display_Integer:
case CSMWorld::ColumnBase::Display_Float:
layout->addWidget (widget = new QLabel, i, 1);
break;
}
}
if (widget)
mWidgetMapper->addMapping (widget, i);
} }
} }
mWidgetMapper->setCurrentModelIndex (
dynamic_cast<CSMWorld::IdTable&> (*model).getModelIndex (id.getId(), 0));
} }
void CSVWorld::DialogueSubView::setEditLock (bool locked) void CSVWorld::DialogueSubView::setEditLock (bool locked)

@ -3,6 +3,8 @@
#include "../doc/subview.hpp" #include "../doc/subview.hpp"
class QDataWidgetMapper;
namespace CSMDoc namespace CSMDoc
{ {
class Document; class Document;
@ -12,6 +14,7 @@ namespace CSVWorld
{ {
class DialogueSubView : public CSVDoc::SubView class DialogueSubView : public CSVDoc::SubView
{ {
QDataWidgetMapper *mWidgetMapper;
public: public:

Loading…
Cancel
Save