/*************************************************************************** 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 #include XQModelSection::XQModelSection(const QModelIndex& aModelIndex, XQNodePtr aSheetNode) : modelIndex{ aModelIndex }, sheetRootNode{ aSheetNode } { } bool XQModelSection::operator==(const XQModelSection& other) const { return modelIndex == other.modelIndex && sheetRootNode == other.sheetRootNode; } bool XQModelSection::isValid() const { return modelIndex.isValid() && sheetRootNode; } int XQModelSection::XQModelSection::row() const { return modelIndex.row(); } XQItem& XQModelSection::XQModelSection::headerItem() const { return XQItem::xqItemFromIndex( modelIndex ); } // // // ------------------------------------------------------------------------------------------------------------------------------------------------------- // // void XQModelSections::addSectionEntry(const QModelIndex& idx, XQNodePtr sheetNode) { XQModelSection section(idx, sheetNode); addAtKey(sheetNode->tag_name(), section); } bool XQModelSections::hasValidSection(const QString& sectionKey) const { if (!contains(sectionKey) ) return false; return at(sectionKey).isValid(); } const XQModelSection& XQModelSections::sectionxqItemFromIndex( const QModelIndex& index ) const { return sectionFromRow( index.row() ); } const XQModelSection& XQModelSections::sectionFromRow(int itemRow ) const { int i = size() - 1; for (; i >= 0; --i) { if ( at(i).modelIndex.row() < itemRow ) return at(i); } static XQModelSection s_DummySection; return s_DummySection; } int XQModelSections::firstRow(const QModelIndex& idx) const { return sectionFromRow(idx.row() ).row(); } int XQModelSections::lastRow(const QModelIndex& idx) const { return lastRow(sectionFromRow(idx.row())); } int XQModelSections::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) return section.modelIndex.model()->rowCount();// - 1; // return row above the row of the next section -> last row of given section return at(index+1).row(); } return -1; } void XQModelSections::dump() const { qDebug() << " --- sections dump(): " <