forked from teamnwah/openmw-tes3coop
Merge remote-tracking branch 'rcutmore/bug-3148'
This commit is contained in:
commit
6001e04e51
4 changed files with 64 additions and 25 deletions
|
@ -327,7 +327,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
|
|||
mCells.getNestableColumn(index)->addColumn(
|
||||
new NestedChildColumn (Columns::ColumnId_WaterLevel, ColumnBase::Display_Float));
|
||||
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 RecordStateColumn<ESM::Enchantment>);
|
||||
|
|
|
@ -10,9 +10,20 @@
|
|||
|
||||
#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),
|
||||
mColor(color),
|
||||
mColorPicker(new ColorPickerPopup(this)),
|
||||
mPopupOnStart(popupOnStart)
|
||||
{
|
||||
|
@ -53,12 +64,25 @@ QColor CSVWidget::ColorEditor::color() const
|
|||
return mColor;
|
||||
}
|
||||
|
||||
int CSVWidget::ColorEditor::colorInt() const
|
||||
{
|
||||
return (mColor.blue() << 16) | (mColor.green() << 8) | (mColor.red());
|
||||
}
|
||||
|
||||
void CSVWidget::ColorEditor::setColor(const QColor &color)
|
||||
{
|
||||
mColor = color;
|
||||
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()
|
||||
{
|
||||
if (isChecked())
|
||||
|
|
|
@ -22,15 +22,27 @@ namespace CSVWidget
|
|||
QPoint calculatePopupPosition();
|
||||
|
||||
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;
|
||||
|
||||
/// \return Color RGB value encoded in an int.
|
||||
int colorInt() const;
|
||||
|
||||
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:
|
||||
virtual void paintEvent(QPaintEvent *event);
|
||||
virtual void showEvent(QShowEvent *event);
|
||||
|
||||
private:
|
||||
ColorEditor(QWidget *parent = 0, const bool popupOnStart = false);
|
||||
|
||||
private slots:
|
||||
void showPicker();
|
||||
void pickerHid();
|
||||
|
|
|
@ -127,22 +127,23 @@ void CSVWorld::CommandDelegate::setModelDataImp (QWidget *editor, QAbstractItemM
|
|||
if (!mCommandDispatcher)
|
||||
return;
|
||||
|
||||
QVariant new_;
|
||||
// Color columns use a custom editor, so we need explicitly extract a data from it
|
||||
QVariant variant;
|
||||
|
||||
// Color columns use a custom editor, so we need to fetch selected color from it.
|
||||
CSVWidget::ColorEditor *colorEditor = qobject_cast<CSVWidget::ColorEditor *>(editor);
|
||||
if (colorEditor != NULL)
|
||||
{
|
||||
new_ = colorEditor->color();
|
||||
variant = colorEditor->colorInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
NastyTableModelHack hack (*model);
|
||||
QStyledItemDelegate::setModelData (editor, &hack, index);
|
||||
new_ = hack.getData();
|
||||
variant = hack.getData();
|
||||
}
|
||||
|
||||
if ((model->data (index)!=new_) && (model->flags(index) & Qt::ItemIsEditable))
|
||||
mCommandDispatcher->executeModify (model, index, new_);
|
||||
if ((model->data (index)!=variant) && (model->flags(index) & Qt::ItemIsEditable))
|
||||
mCommandDispatcher->executeModify (model, index, variant);
|
||||
}
|
||||
|
||||
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)
|
||||
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);
|
||||
}
|
||||
|
@ -202,9 +203,9 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
|
|||
switch (display)
|
||||
{
|
||||
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:
|
||||
{
|
||||
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
|
||||
{
|
||||
QVariant v = index.data(Qt::EditRole);
|
||||
QVariant variant = index.data(Qt::EditRole);
|
||||
if (tryDisplay)
|
||||
{
|
||||
if (!v.isValid())
|
||||
if (!variant.isValid())
|
||||
{
|
||||
v = index.data(Qt::DisplayRole);
|
||||
if (!v.isValid())
|
||||
variant = index.data(Qt::DisplayRole);
|
||||
if (!variant.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -305,7 +306,7 @@ void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelInde
|
|||
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(editor);
|
||||
if(plainTextEdit) //for some reason it is easier to brake the loop here
|
||||
{
|
||||
if(plainTextEdit->toPlainText() == v.toString())
|
||||
if (plainTextEdit->toPlainText() == variant.toString())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -316,23 +317,25 @@ void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelInde
|
|||
CSVWidget::ColorEditor *colorEditor = qobject_cast<CSVWidget::ColorEditor *>(editor);
|
||||
if (colorEditor != NULL)
|
||||
{
|
||||
colorEditor->setColor(index.data().value<QColor>());
|
||||
colorEditor->setColor(variant.toInt());
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray n = editor->metaObject()->userProperty().name();
|
||||
|
||||
if (n == "dateTime") {
|
||||
if (n == "dateTime")
|
||||
{
|
||||
if (editor->inherits("QTimeEdit"))
|
||||
n = "time";
|
||||
else if (editor->inherits("QDateEdit"))
|
||||
n = "date";
|
||||
}
|
||||
|
||||
if (!n.isEmpty()) {
|
||||
if (!v.isValid())
|
||||
v = QVariant(editor->property(n).userType(), (const void *)0);
|
||||
editor->setProperty(n, v);
|
||||
if (!n.isEmpty())
|
||||
{
|
||||
if (!variant.isValid())
|
||||
variant = QVariant(editor->property(n).userType(), (const void *)0);
|
||||
editor->setProperty(n, variant);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue