Merge remote-tracking branch 'rcutmore/bug-3148'

0.6.1
Marc Zinnschlag 8 years ago
commit 6001e04e51

@ -327,7 +327,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mCells.getNestableColumn(index)->addColumn( mCells.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_WaterLevel, ColumnBase::Display_Float)); new NestedChildColumn (Columns::ColumnId_WaterLevel, ColumnBase::Display_Float));
mCells.getNestableColumn(index)->addColumn( mCells.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_MapColor, ColumnBase::Display_Integer)); new NestedChildColumn (Columns::ColumnId_MapColor, ColumnBase::Display_Colour));
mEnchantments.addColumn (new StringIdColumn<ESM::Enchantment>); mEnchantments.addColumn (new StringIdColumn<ESM::Enchantment>);
mEnchantments.addColumn (new RecordStateColumn<ESM::Enchantment>); mEnchantments.addColumn (new RecordStateColumn<ESM::Enchantment>);

@ -10,9 +10,20 @@
#include "colorpickerpopup.hpp" #include "colorpickerpopup.hpp"
CSVWidget::ColorEditor::ColorEditor(const QColor &color, QWidget *parent, bool popupOnStart) CSVWidget::ColorEditor::ColorEditor(const QColor &color, QWidget *parent, const bool popupOnStart)
: ColorEditor(parent, popupOnStart)
{
setColor(color);
}
CSVWidget::ColorEditor::ColorEditor(const int colorInt, QWidget *parent, const bool popupOnStart)
: ColorEditor(parent, popupOnStart)
{
setColor(colorInt);
}
CSVWidget::ColorEditor::ColorEditor(QWidget *parent, const bool popupOnStart)
: QPushButton(parent), : QPushButton(parent),
mColor(color),
mColorPicker(new ColorPickerPopup(this)), mColorPicker(new ColorPickerPopup(this)),
mPopupOnStart(popupOnStart) mPopupOnStart(popupOnStart)
{ {
@ -53,12 +64,25 @@ QColor CSVWidget::ColorEditor::color() const
return mColor; return mColor;
} }
int CSVWidget::ColorEditor::colorInt() const
{
return (mColor.blue() << 16) | (mColor.green() << 8) | (mColor.red());
}
void CSVWidget::ColorEditor::setColor(const QColor &color) void CSVWidget::ColorEditor::setColor(const QColor &color)
{ {
mColor = color; mColor = color;
update(); update();
} }
void CSVWidget::ColorEditor::setColor(const int colorInt)
{
// Color RGB values are stored in given integer.
// First byte is red, second byte is green, third byte is blue.
QColor color = QColor(colorInt & 0xff, (colorInt >> 8) & 0xff, (colorInt >> 16) & 0xff);
setColor(color);
}
void CSVWidget::ColorEditor::showPicker() void CSVWidget::ColorEditor::showPicker()
{ {
if (isChecked()) if (isChecked())

@ -22,15 +22,27 @@ namespace CSVWidget
QPoint calculatePopupPosition(); QPoint calculatePopupPosition();
public: public:
ColorEditor(const QColor &color, QWidget *parent = 0, bool popupOnStart = false); ColorEditor(const QColor &color, QWidget *parent = 0, const bool popupOnStart = false);
ColorEditor(const int colorInt, QWidget *parent = 0, const bool popupOnStart = false);
QColor color() const; QColor color() const;
/// \return Color RGB value encoded in an int.
int colorInt() const;
void setColor(const QColor &color); void setColor(const QColor &color);
/// \brief Set color using given int value.
/// \param colorInt RGB color value encoded as an integer.
void setColor(const int colorInt);
protected: protected:
virtual void paintEvent(QPaintEvent *event); virtual void paintEvent(QPaintEvent *event);
virtual void showEvent(QShowEvent *event); virtual void showEvent(QShowEvent *event);
private:
ColorEditor(QWidget *parent = 0, const bool popupOnStart = false);
private slots: private slots:
void showPicker(); void showPicker();
void pickerHid(); void pickerHid();

@ -127,22 +127,23 @@ void CSVWorld::CommandDelegate::setModelDataImp (QWidget *editor, QAbstractItemM
if (!mCommandDispatcher) if (!mCommandDispatcher)
return; return;
QVariant new_; QVariant variant;
// Color columns use a custom editor, so we need explicitly extract a data from it
// Color columns use a custom editor, so we need to fetch selected color from it.
CSVWidget::ColorEditor *colorEditor = qobject_cast<CSVWidget::ColorEditor *>(editor); CSVWidget::ColorEditor *colorEditor = qobject_cast<CSVWidget::ColorEditor *>(editor);
if (colorEditor != NULL) if (colorEditor != NULL)
{ {
new_ = colorEditor->color(); variant = colorEditor->colorInt();
} }
else else
{ {
NastyTableModelHack hack (*model); NastyTableModelHack hack (*model);
QStyledItemDelegate::setModelData (editor, &hack, index); QStyledItemDelegate::setModelData (editor, &hack, index);
new_ = hack.getData(); variant = hack.getData();
} }
if ((model->data (index)!=new_) && (model->flags(index) & Qt::ItemIsEditable)) if ((model->data (index)!=variant) && (model->flags(index) & Qt::ItemIsEditable))
mCommandDispatcher->executeModify (model, index, new_); mCommandDispatcher->executeModify (model, index, variant);
} }
CSVWorld::CommandDelegate::CommandDelegate (CSMWorld::CommandDispatcher *commandDispatcher, CSVWorld::CommandDelegate::CommandDelegate (CSMWorld::CommandDispatcher *commandDispatcher,
@ -179,7 +180,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
// (the third parameter of ColorEditor's constructor) // (the third parameter of ColorEditor's constructor)
else if (display == CSMWorld::ColumnBase::Display_Colour) else if (display == CSMWorld::ColumnBase::Display_Colour)
{ {
return new CSVWidget::ColorEditor(index.data().value<QColor>(), parent, true); return new CSVWidget::ColorEditor(index.data().toInt(), parent, true);
} }
return createEditor (parent, option, index, display); return createEditor (parent, option, index, display);
} }
@ -202,9 +203,9 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
switch (display) switch (display)
{ {
case CSMWorld::ColumnBase::Display_Colour: case CSMWorld::ColumnBase::Display_Colour:
{
return new CSVWidget::ColorEditor(index.data().value<QColor>(), parent); return new CSVWidget::ColorEditor(variant.toInt(), parent);
}
case CSMWorld::ColumnBase::Display_Integer: case CSMWorld::ColumnBase::Display_Integer:
{ {
DialogueSpinBox *sb = new DialogueSpinBox(parent); DialogueSpinBox *sb = new DialogueSpinBox(parent);
@ -291,13 +292,13 @@ void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelInde
void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay) const void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay) const
{ {
QVariant v = index.data(Qt::EditRole); QVariant variant = index.data(Qt::EditRole);
if (tryDisplay) if (tryDisplay)
{ {
if (!v.isValid()) if (!variant.isValid())
{ {
v = index.data(Qt::DisplayRole); variant = index.data(Qt::DisplayRole);
if (!v.isValid()) if (!variant.isValid())
{ {
return; return;
} }
@ -305,7 +306,7 @@ void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelInde
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(editor); QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(editor);
if(plainTextEdit) //for some reason it is easier to brake the loop here if(plainTextEdit) //for some reason it is easier to brake the loop here
{ {
if(plainTextEdit->toPlainText() == v.toString()) if (plainTextEdit->toPlainText() == variant.toString())
{ {
return; return;
} }
@ -316,23 +317,25 @@ void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelInde
CSVWidget::ColorEditor *colorEditor = qobject_cast<CSVWidget::ColorEditor *>(editor); CSVWidget::ColorEditor *colorEditor = qobject_cast<CSVWidget::ColorEditor *>(editor);
if (colorEditor != NULL) if (colorEditor != NULL)
{ {
colorEditor->setColor(index.data().value<QColor>()); colorEditor->setColor(variant.toInt());
return; return;
} }
QByteArray n = editor->metaObject()->userProperty().name(); QByteArray n = editor->metaObject()->userProperty().name();
if (n == "dateTime") { if (n == "dateTime")
{
if (editor->inherits("QTimeEdit")) if (editor->inherits("QTimeEdit"))
n = "time"; n = "time";
else if (editor->inherits("QDateEdit")) else if (editor->inherits("QDateEdit"))
n = "date"; n = "date";
} }
if (!n.isEmpty()) { if (!n.isEmpty())
if (!v.isValid()) {
v = QVariant(editor->property(n).userType(), (const void *)0); if (!variant.isValid())
editor->setProperty(n, v); variant = QVariant(editor->property(n).userType(), (const void *)0);
editor->setProperty(n, variant);
} }
} }

Loading…
Cancel
Save