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 <xqmodelsectionlist.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! kontstruktor. übergibt den start-index und einen model-knoten mit der beschreibung
|
|
|
|
|
//! der datenknoten.
|
|
|
|
|
|
|
|
|
|
XQModelSection::XQModelSection(const QModelIndex& modelIndex, XQNodePtr sheetNode)
|
|
|
|
|
: _modelIndex{ modelIndex }, _sectionRootNode{ sheetNode }
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! elementvergleich.
|
|
|
|
|
|
|
|
|
|
bool XQModelSection::operator==(const XQModelSection& other) const
|
|
|
|
|
{
|
|
|
|
|
return _modelIndex == other._modelIndex && _sectionRootNode == other._sectionRootNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! true wenn der start-index valide und ein model-knoten vorhanden.
|
|
|
|
|
|
|
|
|
|
bool XQModelSection::isValid() const
|
|
|
|
|
{
|
|
|
|
|
return _modelIndex.isValid() && _sectionRootNode;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 17:45:06 +02:00
|
|
|
QModelIndex XQModelSection::persistentModelIndex() const
|
2025-08-22 22:57:06 +02:00
|
|
|
{
|
2025-08-26 17:45:06 +02:00
|
|
|
return _modelIndex.operator QModelIndex();
|
2025-08-22 22:57:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XQNodePtr XQModelSection::sectionRootNode() const
|
|
|
|
|
{
|
|
|
|
|
return _sectionRootNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! Gibt den sheet-node zurück, das ist die model-beschreibung,
|
|
|
|
|
//! siehe modelsheet.xml:
|
|
|
|
|
//! <section>
|
|
|
|
|
//! <header>
|
|
|
|
|
//! <data> <- dort
|
|
|
|
|
|
|
|
|
|
//! __fix! das versteht doch kein mensch!
|
|
|
|
|
|
|
|
|
|
XQNodePtr XQModelSection::sheetRootNode() const
|
|
|
|
|
{
|
|
|
|
|
return _sectionRootNode->find_child_by_tag_name( c_ModelSheet );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! Gibt den content root node zurück, das ist der
|
|
|
|
|
//! zeiger auf die realen inhalte.
|
|
|
|
|
|
|
|
|
|
XQNodePtr XQModelSection::contentRootNode() const
|
|
|
|
|
{
|
|
|
|
|
return _contentRootNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void XQModelSection::setContentRootNode( const XQNodePtr contentRootNode )
|
|
|
|
|
{
|
|
|
|
|
_contentRootNode = contentRootNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! gibt die zeile des start-index zurück.
|
|
|
|
|
|
|
|
|
|
int XQModelSection::XQModelSection::row() const
|
|
|
|
|
{
|
|
|
|
|
return _modelIndex.row();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! gibt den 'content type' zurück.
|
|
|
|
|
|
|
|
|
|
const QString& XQModelSection::contentType() const
|
|
|
|
|
{
|
|
|
|
|
return _sectionRootNode->attribute( c_ContentType );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! gibt das dieser section entsprechende header-item zurück.
|
|
|
|
|
|
|
|
|
|
XQItem& XQModelSection::XQModelSection::headerItem() const
|
|
|
|
|
{
|
|
|
|
|
return XQItem::xqItemFromIndex( _modelIndex );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! testet, ob die unter 'sectionKey' eine gültige section vorhanden ist.
|
|
|
|
|
|
|
|
|
|
bool XQModelSectionList::hasValidSection(const QString& sectionKey) const
|
|
|
|
|
{
|
|
|
|
|
if (!contains(sectionKey) )
|
|
|
|
|
return false;
|
|
|
|
|
return at(sectionKey).isValid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! gibt für einen model index die 'zuständige' section zurück.
|
|
|
|
|
|
|
|
|
|
const XQModelSection& XQModelSectionList::sectionFromIndex( const QModelIndex& index ) const
|
|
|
|
|
{
|
|
|
|
|
return sectionFromRow( index.row() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! gibt für eine zeile die 'zuständige' section zurück: der bestand an section wird
|
|
|
|
|
//! nach der passenden section durchsucht.
|
|
|
|
|
|
|
|
|
|
const XQModelSection& XQModelSectionList::sectionFromRow(int itemRow ) const
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int i = size() - 1;
|
|
|
|
|
for (; i >= 0; --i)
|
|
|
|
|
{
|
2025-08-26 17:45:06 +02:00
|
|
|
if ( at(i).persistentModelIndex().row() < itemRow )
|
2025-08-22 22:57:06 +02:00
|
|
|
return at(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static XQModelSection s_DummySection;
|
|
|
|
|
|
|
|
|
|
return s_DummySection;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! ermittelt die erste zeile einer section.
|
|
|
|
|
|
|
|
|
|
int XQModelSectionList::firstRow(const QModelIndex& idx) const
|
|
|
|
|
{
|
|
|
|
|
return sectionFromRow(idx.row() ).row();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! ermittelt die zeile unterhalb des gegebenen modelindex,
|
|
|
|
|
//! zum einfügen neuer items ebendort.
|
|
|
|
|
|
|
|
|
|
int XQModelSectionList::lastRow(const QModelIndex& idx) const
|
|
|
|
|
{
|
|
|
|
|
return lastRow(sectionFromRow(idx.row()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! ermittelt die zeile unterhalb der gegebenen section,
|
|
|
|
|
//! zum einfügen neuer items ebendort.
|
|
|
|
|
|
|
|
|
|
int XQModelSectionList::lastRow(const XQModelSection& section ) const
|
|
|
|
|
{
|
|
|
|
|
//qDebug() << " -- last row in section: " << section.modelIndex.data().toString() << " --> " << section.modelIndex.row();
|
|
|
|
|
// row() der section unterhalb dieser
|
|
|
|
|
// __fix? index mit speichern?
|
|
|
|
|
int index = indexOf(section);
|
|
|
|
|
if (index > -1)
|
|
|
|
|
{
|
|
|
|
|
// last section? return last row of model
|
|
|
|
|
if (index == size() - 1)
|
2025-08-26 17:45:06 +02:00
|
|
|
return section.persistentModelIndex().model()->rowCount();// - 1;
|
2025-08-22 22:57:06 +02:00
|
|
|
// return row above the row of the next section -> last row of given section
|
|
|
|
|
return at(index+1).row();
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! gibt alle sections aus, zum ankucken.
|
|
|
|
|
|
|
|
|
|
void XQModelSectionList::dump() const
|
|
|
|
|
{
|
|
|
|
|
qDebug() << " --- sections dump(): " <<size() << " entries.";
|
|
|
|
|
for( int i = 0; i<size(); ++i )
|
|
|
|
|
{
|
2025-08-26 17:45:06 +02:00
|
|
|
QModelIndex idx = at(i).persistentModelIndex();
|
2025-08-22 22:57:06 +02:00
|
|
|
qDebug() << " --- sections:" << i << "row: " << idx.row() << " keyOf(i): " << keyOf(i) << " indexData: "<< idx.data().toString() << " itemData: " << XQItem::xqItemFromIndex(idx).data(Qt::DisplayRole).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|