Files
xtree.ng/src/application/xqchildmodel.cpp

121 lines
3.7 KiB
C++
Raw Normal View History

2025-08-22 22:57:06 +02:00
/***************************************************************************
source::worx xtree
Copyright © 2024-2025 c.holzheuer
christoph.holzheuer@gmail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
***************************************************************************/
#include <znode_factory.h>
#include <xqchildmodel.h>
#include <xqselectionmodel.h>
#include <xqitemdelegate.h>
#include <xqappdata.h>
#include <xqtreetable.h>
#include <xqitemfactory.h>
//! default konstruktor.
XQChildModel::XQChildModel( QObject *parent )
: XQViewModel{parent}
{
}
//! erzegt den sichtbaren inhalt des models aus einem root-datenknoten.
2025-08-23 14:37:36 +02:00
void XQChildModel::addModelData( const XQNodePtr& contentRoot )
2025-08-22 22:57:06 +02:00
{
// __fix: set object name ??
qDebug() << " --- create Model Data: " << contentRoot->to_string();
// Die Datenbasis als shared_ptr sichern
_contentRoot = contentRoot;
// Wir gehen über alle Einträge, die auch unterschiedliche Typen
// haben können, hier: <Panel>. <Battery> ...
for (const auto& contentEntry : _contentRoot->children())
{
// Das ist hier der Typ des Eintrags: Panel, Battery ...
QString key = contentEntry->tag_name();
// 'silent failure' hier der Datenbaum kann auch Knoten enthalten
// die nicht für uns gedacht sind.
if (!_sections.hasValidSection(key))
continue;
2025-09-05 11:49:36 +02:00
const XQModelSection& section = _sections.sectionByKey( key );
2025-08-22 22:57:06 +02:00
section.setContentRootNode( contentEntry->parent() );
int newRow = _sections.lastRow(section);
2025-08-22 23:07:56 +02:00
XQNodePtr sheetNode = section.sheetRootNode();
2025-08-27 14:06:31 +02:00
XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry );
2025-08-22 22:57:06 +02:00
// als Baum?
//section.headerItem().appendRow( list );
insertRow( newRow, list);
} // for
}
2025-09-02 16:58:56 +02:00
//! Erzeugt eine model-section und fügt den zugehörigen header ein.
2025-08-23 14:37:36 +02:00
void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& contentEntry )
{
2025-09-05 11:49:36 +02:00
const XQModelSection& section = _sections.sectionByKey( key );
2025-08-23 14:37:36 +02:00
if(section.isValid() )
{
section.setContentRootNode( contentEntry->parent() );
int newRow = _sections.lastRow(section);
XQNodePtr sheetNode = section.sheetRootNode();
2025-08-27 14:06:31 +02:00
XQItemList list = _itemFactory.makeRow( sheetNode, nullptr );
2025-08-23 14:37:36 +02:00
insertRow( newRow, list);
}
}
2025-08-22 22:57:06 +02:00
2025-09-02 16:58:56 +02:00
//! erzeugt ein adhoc-contextmenu, je nachdem welche aktionen gerade möglich sind.
2025-08-22 22:57:06 +02:00
void XQChildModel::initContextMenu()
{
2025-09-04 13:52:23 +02:00
_sections.dump();
2025-08-22 22:57:06 +02:00
// __fixme! add a menu title
_contextMenu->clear();
const QModelIndex& curIdx = _treeTable->currentIndex();
bool hasSel = curIdx.isValid() && _treeTable->selectionModel()->hasSelection();
bool canPaste = _clipBoard.canPaste( curIdx );
_contextMenu->addAction( "icn11Dummy", "Undo", XQCommand::cmdUndo, _undoStack->canUndo() );
_contextMenu->addAction( "icn17Dummy", "Redo", XQCommand::cmdRedo, _undoStack->canRedo() );
_contextMenu->addAction( "icn58Dummy", "Cut", XQCommand::cmdCut, hasSel );
_contextMenu->addAction( "icn61Dummy", "Paste", XQCommand::cmdPaste, canPaste );
_contextMenu->addAction( "icn55Dummy", "Copy", XQCommand::cmdCopy, hasSel );
//_contextMenu->addAction( "icn35Dummy", "Move", XQCommand::cmdMove, hasSel );
_contextMenu->addAction( "icn70Dummy", "New", XQCommand::cmdNew, hasSel );
_contextMenu->addAction( "icn50Dummy", "Delete", XQCommand::cmdDelete, hasSel );
// __fixme! set 'toggle section <name>' entry
//contextMenu.actions().first()->setText("<name>");
2025-09-04 13:52:23 +02:00
_contextMenu->addAction( "icn29Dummy", "Hide Section", XQCommand::cmdToggleSection, true );
2025-08-22 22:57:06 +02:00
}