rework xqitem::setData, part I
This commit is contained in:
@@ -37,18 +37,18 @@ XQItem::XQItemFlagMap XQItem::s_ItemFlagMap
|
|||||||
|
|
||||||
XQItem::XQItemDataRoleMap XQItem::s_ItemDataRoleMap
|
XQItem::XQItemDataRoleMap XQItem::s_ItemDataRoleMap
|
||||||
{
|
{
|
||||||
{"ItemType", ItemTypeRole},
|
{"ItemTypeRole", ItemTypeRole},
|
||||||
{"Content", ContentRole},
|
{"ContentRole", ContentRole},
|
||||||
{"RenderStyle", RenderStyleRole},
|
{"RenderStyleRole", RenderStyleRole},
|
||||||
{"EditorType", EditorTypeRole},
|
{"EditorTypeRole", EditorTypeRole},
|
||||||
{"ItemFlags", FlagsRole},
|
{"ItemFlagsRole", FlagsRole},
|
||||||
{"UnitType", UnitTypeRole},
|
{"UnitTypeRole", UnitTypeRole},
|
||||||
{"ContentFormat", ContentFormatRole},
|
{"ContentFormatRole", ContentFormatRole},
|
||||||
{"FlagsRole", FlagsRole},
|
{"FlagsRoleRole", FlagsRole},
|
||||||
{"Icon", IconRole},
|
{"IconRole", IconRole},
|
||||||
{"FixedChoices", FixedChoicesRole},
|
{"FixedChoicesRole", FixedChoicesRole},
|
||||||
{"DataNode", ContentNodeRole},
|
{"DataNodeRole", ContentNodeRole},
|
||||||
{"SheetNode", SheetNodeRole}
|
{"SheetNodeRole", SheetNodeRole}
|
||||||
};
|
};
|
||||||
|
|
||||||
// No bi-map needed here, qmap.key() is sufficient for the job
|
// No bi-map needed here, qmap.key() is sufficient for the job
|
||||||
@@ -388,7 +388,12 @@ bool XQItem::isHeaderStyle()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString XQItem::dataRoleName(int role)
|
||||||
|
{
|
||||||
|
if( role < XQItem::NoRole && model() )
|
||||||
|
return model()->roleNames()[role];
|
||||||
|
return XQItem::fetchItemDataRoleName(role);
|
||||||
|
}
|
||||||
|
|
||||||
QVariant XQItem::data(int role ) const
|
QVariant XQItem::data(int role ) const
|
||||||
{
|
{
|
||||||
@@ -470,7 +475,8 @@ QVariant XQItem::data(int role ) const
|
|||||||
|
|
||||||
void XQItem::setData(const QVariant& value, int role )
|
void XQItem::setData(const QVariant& value, int role )
|
||||||
{
|
{
|
||||||
//replaceAttribute( XQItem* item, XQItem::ItemDataRole role, const QVariant& newValue)
|
|
||||||
|
//qDebug() << " -- item set data: " << value.toString() << " for: " << role << ": " << dataRoleName(role);
|
||||||
|
|
||||||
//emitDataChanged()
|
//emitDataChanged()
|
||||||
switch(role)
|
switch(role)
|
||||||
@@ -489,19 +495,34 @@ void XQItem::setData(const QVariant& value, int role )
|
|||||||
itemType().replaceAttribute( this, value, role );
|
itemType().replaceAttribute( this, value, role );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ContentNodeRole:
|
|
||||||
case SheetNodeRole:
|
|
||||||
|
|
||||||
case TypeKeyRole:
|
|
||||||
case Qt::DisplayRole :
|
case Qt::DisplayRole :
|
||||||
case Qt::EditRole :
|
case Qt::EditRole :
|
||||||
// return the raw, unformatted data
|
// return the raw, unformatted data
|
||||||
case ContentRole:
|
case ContentRole:
|
||||||
|
{
|
||||||
|
//qDebug() << " -- item set data xxx: " << value.toString() << " for: " << role;
|
||||||
|
break;
|
||||||
|
|
||||||
|
QString* contentPtr = QStandardItem::data( XQItem::ContentRole ).value<QString*>();
|
||||||
|
if(contentPtr)
|
||||||
|
{
|
||||||
|
|
||||||
|
contentPtr->operator=( value.toString() );
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// what to do here?
|
||||||
|
case ContentNodeRole:
|
||||||
|
case SheetNodeRole:
|
||||||
|
case TypeKeyRole:
|
||||||
default:
|
default:
|
||||||
QStandardItem::setData( value,role);
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStandardItem::setData( value,role);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -534,6 +555,8 @@ int XQItem::fetchItemDataRole( const QString& dataRoleKey )
|
|||||||
|
|
||||||
QString XQItem::fetchItemDataRoleName( int dataRole )
|
QString XQItem::fetchItemDataRoleName( int dataRole )
|
||||||
{
|
{
|
||||||
|
//if( dataRole < XQItem::NoRole)
|
||||||
|
// return this->model()->
|
||||||
return s_ItemDataRoleMap.key(dataRole);
|
return s_ItemDataRoleMap.key(dataRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -225,6 +225,7 @@ public:
|
|||||||
bool isHeaderStyle();
|
bool isHeaderStyle();
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
|
QString dataRoleName(int role);
|
||||||
QVariant data(int role = Qt::DisplayRole ) const override;
|
QVariant data(int role = Qt::DisplayRole ) const override;
|
||||||
void setData(const QVariant &value, int role ) override;
|
void setData(const QVariant &value, int role ) override;
|
||||||
|
|
||||||
|
@@ -40,6 +40,7 @@ public:
|
|||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
|
|
||||||
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
||||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
||||||
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
|
@@ -105,6 +105,7 @@ void XQCommand::saveNodes( const QModelIndexList& list )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! erzeugt einen string aus dem command-type, fürs debuggen.
|
//! erzeugt einen string aus dem command-type, fürs debuggen.
|
||||||
|
|
||||||
QString XQCommand::toString()
|
QString XQCommand::toString()
|
||||||
|
@@ -27,6 +27,9 @@ struct XQNodeBackup
|
|||||||
XQNodePtr contentNode;
|
XQNodePtr contentNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! \brief The XQNodeStore class
|
||||||
|
//!
|
||||||
class XQNodeStore : public QVector<XQNodeBackup>
|
class XQNodeStore : public QVector<XQNodeBackup>
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -37,8 +40,9 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Das command enthält immer auch die betroffenen items
|
//! Das command enthält immer auch die betroffenen items
|
||||||
// ist also auch eine SavedNodeList
|
//! ist also auch ein node store
|
||||||
|
|
||||||
class XQCommand : public QUndoCommand, public XQNodeStore
|
class XQCommand : public QUndoCommand, public XQNodeStore
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user