simplified model commands.
This commit is contained in:
@@ -77,10 +77,10 @@ namespace XQAppData
|
||||
namedInsert( "BrowserStop", QStyle::SP_BrowserStop );
|
||||
namedInsert( "icn33Dummy", QStyle::SP_DriveHDIcon );
|
||||
namedInsert( "icn34Dummy", QStyle::SP_MessageBoxQuestion );
|
||||
namedInsert( "icn35Dummy", QStyle::SP_CommandLink );
|
||||
namedInsert( "CommandLink", QStyle::SP_CommandLink );
|
||||
namedInsert( "icn36Dummy", QStyle::SP_DriveNetIcon );
|
||||
namedInsert( "icn37Dummy", QStyle::SP_MessageBoxWarning );
|
||||
namedInsert( "icn38Dummy", QStyle::SP_ComputerIcon );
|
||||
namedInsert( "MessageBoxWarning", QStyle::SP_MessageBoxWarning );
|
||||
namedInsert( "ComputerIcon", QStyle::SP_ComputerIcon );
|
||||
namedInsert( "icn39Dummy", QStyle::SP_FileDialogBack );
|
||||
namedInsert( "icn40Dummy", QStyle::SP_TitleBarCloseButton );
|
||||
namedInsert( "icn42Dummy", QStyle::SP_FileDialogContentsView );
|
||||
@@ -114,7 +114,7 @@ namespace XQAppData
|
||||
namedInsert( "TrashIcon", QStyle::SP_TrashIcon );
|
||||
namedInsert( "icn72Dummy", QStyle::SP_DialogSaveButton );
|
||||
namedInsert( "icn73Dummy", QStyle::SP_MediaPause );
|
||||
namedInsert( "icn74Dummy", QStyle::SP_VistaShield );
|
||||
namedInsert( "VistaShield", QStyle::SP_VistaShield );
|
||||
namedInsert( "icn75Dummy", QStyle::SP_DialogYesButton );
|
||||
namedInsert( "icn76Dummy", QStyle::SP_MediaPlay );
|
||||
namedInsert( "icn77Dummy", QStyle::SP_DirClosedIcon );
|
||||
|
@@ -257,6 +257,14 @@ void XQItem::clearFlag( Qt::ItemFlag newFlag )
|
||||
setFlags( flags() & ~newFlag);
|
||||
}
|
||||
|
||||
|
||||
//! gibt die itemFlags als string zurück.
|
||||
|
||||
QString XQItem::itemFlagsToString() const
|
||||
{
|
||||
return'(' + data(XQItem::FlagsRole).toString() +')';
|
||||
}
|
||||
|
||||
///
|
||||
/// data() access shortcuts
|
||||
///
|
||||
@@ -277,6 +285,7 @@ QString XQItem::renderStyleToString() const
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! setzt den editorType. wird im itemType gespeichert.
|
||||
|
||||
void XQItem::setRenderStyle(RenderStyle renderStyle )
|
||||
@@ -483,7 +492,7 @@ QVariant XQItem::data(int role ) const
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
{
|
||||
return content() + ":" + itemType().text() + ":" + renderStyleToString() + ":" + unitTypeToString();
|
||||
return content() + ":" + unitTypeToString() + ":" + renderStyleToString() + ":" + unitTypeToString() + ":" + itemFlagsToString();
|
||||
}
|
||||
|
||||
//
|
||||
|
@@ -161,6 +161,7 @@ public:
|
||||
// __fix! das können die selber !?
|
||||
void addFlag( Qt::ItemFlag newFlag );
|
||||
void clearFlag( Qt::ItemFlag newFlag );
|
||||
QString itemFlagsToString() const;
|
||||
|
||||
//das ist ein Sonderfall: Ein ist ein dereferenzierter Zeiger auf 'unser' Atrribut in
|
||||
// XQNodePtr, also unserem contentNode(). Das wird hier direkt aufgelöst und nicht auf
|
||||
|
@@ -81,22 +81,6 @@ XQItem& XQItemDelegate::xqItemFromIndex( const QModelIndex& index ) const
|
||||
}
|
||||
|
||||
|
||||
|
||||
QWidget* XQItemDelegate::prepareHeaderOption(const QStyleOptionViewItem& option, const QModelIndex& index, QStyleOptionHeader& headerOption) const
|
||||
{
|
||||
// use the header as "parent" for style init
|
||||
QWidget* srcWidget = treeTable()->header();
|
||||
headerOption.initFrom(srcWidget);
|
||||
headerOption.text = index.data(Qt::DisplayRole).toString();
|
||||
headerOption.rect = option.rect;
|
||||
headerOption.styleObject = option.styleObject;
|
||||
// __ch: reduce inner offset when painting
|
||||
headerOption.textAlignment |= Qt::AlignVCenter;
|
||||
|
||||
return srcWidget;
|
||||
|
||||
}
|
||||
|
||||
void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
if( !index.isValid() )
|
||||
@@ -131,11 +115,24 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
|
||||
|
||||
}
|
||||
|
||||
//! einen section header im header-style zeichnen
|
||||
|
||||
void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
QStyleOptionHeader headerOption;
|
||||
QWidget* srcWidget = prepareHeaderOption(option, index, headerOption);
|
||||
|
||||
XQItem& item = xqItemFromIndex( index );
|
||||
|
||||
// use the header as "parent" for style init
|
||||
QWidget* srcWidget = treeTable();//->header();
|
||||
headerOption.initFrom(srcWidget);
|
||||
headerOption.text = index.data(Qt::DisplayRole).toString();
|
||||
headerOption.rect = option.rect.adjusted(0,0,0,3);
|
||||
headerOption.styleObject = option.styleObject;
|
||||
// __ch: reduce inner offset when painting
|
||||
headerOption.textAlignment |= Qt::AlignVCenter;
|
||||
headerOption.icon = item.icon();
|
||||
|
||||
if (srcWidget != nullptr)
|
||||
{
|
||||
// save painter
|
||||
|
@@ -46,8 +46,6 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
QWidget* prepareHeaderOption(const QStyleOptionViewItem& option, const QModelIndex& index, QStyleOptionHeader& headerOption) const;
|
||||
|
||||
void drawHeaderStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
void drawProgressBarStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
void drawComboBoxStyle(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
@@ -278,7 +278,14 @@ XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const XQNodePtr& co
|
||||
// der content wird indirect über den tag-name des sheetnode geholt
|
||||
contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() );
|
||||
|
||||
return new XQItem( itemType, contentPtr );
|
||||
XQItem* newItem = new XQItem( itemType, contentPtr );
|
||||
if( newItem->isCheckable() )
|
||||
{
|
||||
qDebug() << " --- yooo: " << newItem->toolTip();
|
||||
newItem->setCheckState( Qt::Checked );
|
||||
}
|
||||
|
||||
return newItem;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -255,8 +255,8 @@ QString XQItemType::makeItemTypeKey()
|
||||
key = key.arg( renderStyleToString() );
|
||||
key = key.arg( editorTypeToString() );
|
||||
key = key.arg( unitTypeToString() );
|
||||
key = key.arg( contentFormat() );
|
||||
key = key.arg( data(XQItem::FlagsRole).toString() );
|
||||
key = key.arg( contentFormat() );
|
||||
key = key.arg( itemFlagsToString() );
|
||||
// icons haben leider keine namen, es sei denn, sie kommen aus einen theme
|
||||
//key = key.arg( icon().name() );
|
||||
//key = key.arg( icon().cacheKey() );
|
||||
|
10
src/main.cpp
10
src/main.cpp
@@ -54,7 +54,15 @@ int main(int argc, char *argv[])
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QIcon icon;
|
||||
/*
|
||||
// Signal für einzelne QStandardItem-Änderungen
|
||||
connect(model, &QStandardItemModel::itemChanged,
|
||||
this, [](QStandardItem *changedItem){
|
||||
QVariant state = changedItem->data(Qt::CheckStateRole);
|
||||
qDebug() << "Neuer Check-State:" << state.toInt();
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
//app.setStyle("fusion");
|
||||
XQMainWindow window;
|
||||
|
@@ -192,16 +192,7 @@ void XQViewModel::onActionTriggered(QAction* action)
|
||||
|
||||
}
|
||||
|
||||
|
||||
//! führt die 'redo' action des gegebenen commnds aus.
|
||||
|
||||
void XQViewModel::onCommandRedo( XQCommand& command )
|
||||
{
|
||||
QMap<XQCommand::CmdType,std::function<void(XQCommand&)>> s_RedoMap;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
/*
|
||||
switch (command.commandType())
|
||||
{
|
||||
case XQCommand::cmdToggleSection:
|
||||
@@ -225,6 +216,28 @@ void XQViewModel::onCommandRedo( XQCommand& command )
|
||||
default:
|
||||
qDebug() << " --- onCommandRedo: default: not handled: " << command.toString();
|
||||
}
|
||||
*/
|
||||
|
||||
//! führt die 'redo' action des gegebenen commnds aus.
|
||||
|
||||
void XQViewModel::onCommandRedo( XQCommand& command )
|
||||
{
|
||||
static MemCallMap redoCalls
|
||||
{
|
||||
{ XQCommand::cmdToggleSection, &XQViewModel::cmdToggleSection },
|
||||
{ XQCommand::cmdCut, &XQViewModel::cmdCut },
|
||||
{ XQCommand::cmdPaste, &XQViewModel::cmdPaste },
|
||||
{ XQCommand::cmdNew, &XQViewModel::cmdNew },
|
||||
{ XQCommand::cmdDelete, &XQViewModel::cmdDelete }
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
MemCall memCall = redoCalls[command.commandType()];
|
||||
if( memCall )
|
||||
(this->*memCall)( command );
|
||||
else
|
||||
qDebug() << " --- onCommandRedo: default: not handled: " << command.toString();
|
||||
}
|
||||
catch( XQException& exception )
|
||||
{
|
||||
@@ -233,12 +246,7 @@ void XQViewModel::onCommandRedo( XQCommand& command )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! führt die 'undo' action des gegebenen commnds aus.
|
||||
|
||||
void XQViewModel::onCommandUndo( XQCommand& command )
|
||||
{
|
||||
qDebug() << " --- onCommandUndo: count: " << XQNode::s_Count;
|
||||
/*
|
||||
try
|
||||
{
|
||||
switch (command.commandType())
|
||||
@@ -273,13 +281,35 @@ void XQViewModel::onCommandUndo( XQCommand& command )
|
||||
default:
|
||||
qDebug() << " --- onCommandUndo: default: not handled: " << command.toString();
|
||||
}
|
||||
*/
|
||||
//! führt die 'undo' action des gegebenen commnds aus.
|
||||
|
||||
void XQViewModel::onCommandUndo( XQCommand& command )
|
||||
{
|
||||
qDebug() << " --- onCommandUndo: count: " << XQNode::s_Count;
|
||||
|
||||
static MemCallMap undoCalls
|
||||
{
|
||||
{ XQCommand::cmdToggleSection, &XQViewModel::cmdToggleSection },
|
||||
{ XQCommand::cmdCut, &XQViewModel::cmdCutUndo },
|
||||
{ XQCommand::cmdPaste, &XQViewModel::cmdPasteUndo },
|
||||
{ XQCommand::cmdNew, &XQViewModel::cmdNewUndo },
|
||||
{ XQCommand::cmdDelete, &XQViewModel::cmdDeleteUndo },
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
MemCall memCall = undoCalls[command.commandType()];
|
||||
if( memCall )
|
||||
(this->*memCall)( command );
|
||||
else
|
||||
qDebug() << " --- onCommandUndo: default: not handled: " << command.toString();
|
||||
}
|
||||
catch( XQException& exception )
|
||||
{
|
||||
qDebug() << exception.what();
|
||||
QMessageBox::critical( nullptr, "Failure", QString("Failure: %1").arg(exception.what()) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// undo-/redo-able stuff
|
||||
@@ -461,8 +491,9 @@ void XQViewModel::cmdNewUndo( XQCommand& command )
|
||||
|
||||
//! schaltet eine section sichtbar oder unsichtbar.
|
||||
|
||||
void XQViewModel::cmdToggleSection( const QModelIndex& index )
|
||||
void XQViewModel::cmdToggleSection( XQCommand& command )
|
||||
{
|
||||
const QModelIndex& index = command.originIndex();
|
||||
Q_ASSERT(index.isValid());
|
||||
|
||||
int fstRow = _sections.firstRow( index );
|
||||
|
@@ -58,7 +58,7 @@ public:
|
||||
|
||||
// undo-/redo-able stuff
|
||||
|
||||
virtual void cmdToggleSection( const QModelIndex& index );
|
||||
virtual void cmdToggleSection( XQCommand& command );
|
||||
virtual void cmdCut( XQCommand& command );
|
||||
virtual void cmdCutUndo( XQCommand& command );
|
||||
virtual void cmdPaste( XQCommand& command );
|
||||
@@ -111,6 +111,9 @@ protected:
|
||||
|
||||
protected:
|
||||
|
||||
using MemCall = void (XQViewModel::*)(XQCommand&);
|
||||
using MemCallMap = QMap<XQCommand::CmdType,MemCall>;
|
||||
|
||||
// das eine reference auf ein globales singleton
|
||||
XQItemFactory& _itemFactory;
|
||||
XQSimpleClipBoard _clipBoard;
|
||||
|
@@ -8,12 +8,13 @@
|
||||
|
||||
<ItemTypes>
|
||||
<TreeParentType RenderStyle="PlainStyle" ItemFlags="IsEnabled|IsDropEnabled" Icon="DirIcon" />
|
||||
<TreeChildType RenderStyle="PlainStyle" ItemFlags="IsCheckable|IsEnabled|IsDragEnabled|IsSelectable|IsDropEnabled"/>
|
||||
<HeaderType RenderStyle="HeaderStyle" ItemFlags="IsCheckable|IsEnabled" Icon="DirIcon"/>
|
||||
<TreeChildType RenderStyle="PlainStyle" ItemFlags="IsUserCheckable|IsEnabled|IsDragEnabled|IsSelectable|IsDropEnabled"/>
|
||||
<HeaderType RenderStyle="HeaderStyle" ItemFlags="IsUserCheckable|IsEnabled" Icon="DirIcon"/>
|
||||
<HiddenType RenderStyle="HiddenStyle"/>
|
||||
<StaticType RenderStyle="PlainStyle"/>
|
||||
<PlainType RenderStyle="PlainStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable"/>
|
||||
<ValueType RenderStyle="FormattedStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable" Icon="DirIcon" UnitType="Coulomb"/>
|
||||
<ValueType RenderStyle="FormattedStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable" Icon="CommandLink" UnitType="Coulomb"/>
|
||||
<CheckableType RenderStyle="FormattedStyle" ItemFlags="IsUserCheckable|IsEnabled|IsEditable|IsSelectable" Icon="CommandLink" UnitType="###"/>
|
||||
<PercentageType RenderStyle="ProgressBarStyle" ItemFlags="IsEnabled|IsSelectable"/>
|
||||
<ChoiceType RenderStyle="ComboBoxStyle" ItemFlags="IsEnabled|IsSelectable|IsEditable" FixedChoices="la|le|lo|lu"/>
|
||||
<IntValueType RenderStyle="SpinBoxStyle" ItemFlags="IsEnabled|IsSelectable"/>
|
||||
@@ -71,7 +72,7 @@
|
||||
<Manufacturer ItemType="ValueType"/>
|
||||
<!-- 'UnitType' überschreibt den default wert im ItemType und erzeugt damit einen neuen ItemType-->
|
||||
<WattPeak ItemType="ValueType" UnitType="Wp" Icon="DesktopIcon"/>
|
||||
<Width ItemType="ValueType" UnitType="m"/>
|
||||
<Width ItemType="CheckableType" Icon="VistaShield" UnitType="m"/>
|
||||
<Height ItemType="ValueType" UnitType="m"/>
|
||||
<Weight ItemType="ValueType" UnitType="kg"/>
|
||||
<MaxVolt ItemType="ValueType" UnitType="V"/>
|
||||
@@ -79,6 +80,47 @@
|
||||
</Data>
|
||||
</Section>
|
||||
|
||||
<Section ContentType="Inverter">
|
||||
<Header Marker="Inverter">
|
||||
<InverterID Caption="Inverter" ItemType="HeaderType" />
|
||||
<InverterName Caption="Name" ItemType="HeaderType" />
|
||||
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" />
|
||||
<MaxPowerInput Caption="max. Input" ItemType="HeaderType" />
|
||||
<MaxPowerOutput Caption="max Output" ItemType="HeaderType" />
|
||||
<NumStrings Caption="Strings" ItemType="HeaderType" />
|
||||
<Weight Caption="Weight" ItemType="HeaderType" />
|
||||
</Header>
|
||||
<Data>
|
||||
<InverterID Caption="Inverter" ItemType="ValueType" />
|
||||
<InverterName Caption="Name" ItemType="ValueType" />
|
||||
<Manufacturer Caption="Manufacturer" ItemType="ValueType" />
|
||||
<MaxPowerInput Caption="max. Input" ItemType="ValueType" ItemType="ChoiceType" ChoiceDataSource="MaxPowerInputChoice" UnitType="W"/>
|
||||
<MaxPowerOutput Caption="max Output" ItemType="ValueType" UnitType="W"/>
|
||||
<NumStrings Caption="Strings" ItemType="ValueType" />
|
||||
<Weight Caption="Weight" ItemType="ValueType" UnitType="kg"/>
|
||||
</Data>
|
||||
</Section>
|
||||
|
||||
<Section ContentType="Battery">
|
||||
<Header Marker="Battery">
|
||||
<BatteryID Caption="Name" ItemType="HeaderType" />
|
||||
<BatteryName Caption="Battery" ItemType="HeaderType" />
|
||||
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" />
|
||||
<Capacity Caption="Capacity" ItemType="HeaderType"/>
|
||||
<Yield Caption="Yield" ItemType="HeaderType" />
|
||||
<MaxCurrent Caption="max. Current" ItemType="HeaderType" />
|
||||
<MaxVolt Caption="max. Volt" ItemType="HeaderType" />
|
||||
</Header>
|
||||
<Data>
|
||||
<BatteryID Caption="Battery" ItemType="ValueType" />
|
||||
<BatteryName Caption="Name" ItemType="ValueType" />
|
||||
<Manufacturer Caption="Manufacturer" ItemType="ValueType" />
|
||||
<Capacity Caption="Capacity" ItemType="ValueType" UnitType="Wh"/>
|
||||
<Yield Caption="Yield" ItemType="ValueType" ItemType="PercentageType" UnitType="%"/>
|
||||
<MaxCurrent Caption="max. Current" ItemType="ValueType" UnitType="A"/>
|
||||
<MaxVolt Caption="max. Volt" ItemType="ValueType" UnitType="V"/>
|
||||
</Data>
|
||||
</Section>
|
||||
|
||||
|
||||
</DocumentDetailsModel>
|
||||
|
Reference in New Issue
Block a user