finally, fixed hiding of headers.

This commit is contained in:
2025-09-06 14:07:25 +02:00
parent a9dacca684
commit 89c671295f
6 changed files with 79 additions and 49 deletions

View File

@@ -126,7 +126,7 @@ void XQMainWindow::initMainWindow()
// #2. load demo data // #2. load demo data
loadDocument( c_DocumentFileName1 ); loadDocument( c_DocumentFileName1 );
//loadDocumentQML( c_DocumentFileName2 ); //loadDocumentQML( c_DocumentFileName2 );
loadDocument( c_DocumentFileName2 ); //loadDocument( c_DocumentFileName2 );
qDebug() << " --- all here: " << XQNode::s_Count; qDebug() << " --- all here: " << XQNode::s_Count;
@@ -311,7 +311,7 @@ void XQMainWindow::onChildViewTabClicked( int idx )
void XQMainWindow::onSectionCreated( const XQModelSection& section ) void XQMainWindow::onSectionCreated( const XQModelSection& section )
{ {
qDebug() << " --- XXX section created: " << section.contentType() << ":" << section.sheetRootNode()->to_string(); //qDebug() << " --- XXX section created: " << section.contentType() << ":" << section.sheetRootNode()->to_string();
if( _currentProjectItem ) if( _currentProjectItem )
{ {
_mainModel.addSectionItem( section, _currentProjectItem ); _mainModel.addSectionItem( section, _currentProjectItem );

View File

@@ -108,7 +108,7 @@ void XQCommand::setOriginIndex( const QModelIndex& origin )
void XQCommand::saveNodes( const QModelIndexList& list ) void XQCommand::saveNodes( const QModelIndexList& list )
{ {
clear(); clear();
// über jede zeil // über jede zeile
for( auto entry : list ) for( auto entry : list )
{ {
// knoten holen // knoten holen

View File

@@ -19,7 +19,7 @@
//! der datenknoten. //! der datenknoten.
XQModelSection::XQModelSection(const QModelIndex& modelIndex, XQNodePtr sheetNode) XQModelSection::XQModelSection(const QModelIndex& modelIndex, XQNodePtr sheetNode)
: _modelIndex{ modelIndex }, _sectionRootNode{ sheetNode } : _modelIndex{ modelIndex }, _sectionSheetRootNode{ sheetNode }
{ {
} }
@@ -29,7 +29,7 @@ XQModelSection::XQModelSection(const QModelIndex& modelIndex, XQNodePtr sheetNod
bool XQModelSection::operator==(const XQModelSection& other) const bool XQModelSection::operator==(const XQModelSection& other) const
{ {
return _modelIndex == other._modelIndex && _sectionRootNode == other._sectionRootNode; return _modelIndex == other._modelIndex && _sectionSheetRootNode == other._sectionSheetRootNode;
} }
@@ -37,7 +37,7 @@ bool XQModelSection::operator==(const XQModelSection& other) const
bool XQModelSection::isValid() const bool XQModelSection::isValid() const
{ {
return _modelIndex.isValid() && _sectionRootNode; return _modelIndex.isValid() && _sectionSheetRootNode;
} }
QModelIndex XQModelSection::startIndex() const QModelIndex XQModelSection::startIndex() const
@@ -47,7 +47,7 @@ QModelIndex XQModelSection::startIndex() const
XQNodePtr XQModelSection::sectionRootNode() const XQNodePtr XQModelSection::sectionRootNode() const
{ {
return _sectionRootNode; return _sectionSheetRootNode;
} }
//! Gibt den sheet-node zurück, das ist die model-beschreibung, //! Gibt den sheet-node zurück, das ist die model-beschreibung,
@@ -60,7 +60,7 @@ XQNodePtr XQModelSection::sectionRootNode() const
XQNodePtr XQModelSection::sheetRootNode() const XQNodePtr XQModelSection::sheetRootNode() const
{ {
return _sectionRootNode->find_child_by_tag_name( c_ModelSheet ); return _sectionSheetRootNode->find_child_by_tag_name( c_ModelSheet );
} }
@@ -90,7 +90,8 @@ int XQModelSection::XQModelSection::firstRow() const
const QString& XQModelSection::contentType() const const QString& XQModelSection::contentType() const
{ {
return _sectionRootNode->attribute( c_ContentType ); //qDebug() << " ---AUA & AUS!";
return _sectionSheetRootNode->attribute( c_ContentType );
} }
@@ -116,8 +117,7 @@ const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey
if( hasValidSection( sectionKey ) ) if( hasValidSection( sectionKey ) )
return _sections.at(sectionKey); return _sections.at(sectionKey);
static const XQModelSection s_DummySection; throw XQException( "No section for key: ", sectionKey);
return s_DummySection;
} }
@@ -127,21 +127,31 @@ const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey
const XQModelSection& XQSectionManager::sectionByRow(int itemRow ) const const XQModelSection& XQSectionManager::sectionByRow(int itemRow ) const
{ {
/*
for( const XQModelSection& section : _sections )
{
qDebug() << " --- sectionByRow: " <<section.startIndex().data().toString() << ": " << lastRow(section);
}
*/
// wir gehen rückwärts, weil wir da nur einen vergleich brauchen
// und uns den test mit lastRow() sparen können.
int i = _sections.size() - 1; int i = _sections.size() - 1;
for (; i >= 0; --i) for (; i >= 0; --i)
{ {
if ( _sections.at(i).startIndex().row() < itemRow ) if ( _sections.at(i).startIndex().row() <= itemRow )
return _sections.at(i); return _sections.at(i);
} }
static XQModelSection s_DummySection; throw XQException( "No section for item row: ", QString::number(itemRow));
return s_DummySection;
} }
const XQModelSection& XQSectionManager::createSection(const QString& sectionKey, const QModelIndex& modelIndex, XQNodePtr sheetNode) const XQModelSection& XQSectionManager::createSection(const QModelIndex& modelIndex, XQNodePtr sheetNode)
{ {
// 6. jetzt können wir auch die sction erzeugen const QString& sectionKey = sheetNode->attribute(c_ContentType);
qDebug() << " --- create Section: " << sectionKey << ": " << modelIndex.data().toString();
XQModelSection section(modelIndex, sheetNode ); XQModelSection section(modelIndex, sheetNode );
_sections.addAtKey( sectionKey, section); _sections.addAtKey( sectionKey, section);
return sectionByKey(sectionKey); return sectionByKey(sectionKey);
@@ -151,20 +161,9 @@ const XQModelSection& XQSectionManager::createSection(const QString& sectionKey,
//! ermittelt die zeile unterhalb des gegebenen modelindex, //! ermittelt die zeile unterhalb des gegebenen modelindex,
//! zum einfügen neuer items ebendort. //! zum einfügen neuer items ebendort.
/*
int XQSectionManager::lastRow(const QModelIndex& idx) const
{
return lastRow(sectionByRow(idx.row()));
}
//! ermittelt die zeile unterhalb der gegebenen section,
//! zum einfügen neuer items ebendort.
*/
int XQSectionManager::lastRow(const XQModelSection& section ) const int XQSectionManager::lastRow(const XQModelSection& section ) const
{ {
qDebug() << " -- last row in section: " << section.startIndex().data().toString() << " --> " << section.startIndex().row(); //qDebug() << " -- last row in section: " << section.startIndex().data().toString() << " --> " << section.startIndex().row();
// row() der section unterhalb dieser // row() der section unterhalb dieser
// __fix? index mit speichern? // __fix? index mit speichern?
int index = _sections.indexOf(section); int index = _sections.indexOf(section);

View File

@@ -51,7 +51,7 @@ protected:
QPersistentModelIndex _modelIndex; QPersistentModelIndex _modelIndex;
mutable XQNodePtr _sectionRootNode{}; mutable XQNodePtr _sectionSheetRootNode{};
mutable XQNodePtr _contentRootNode{}; mutable XQNodePtr _contentRootNode{};
}; };
@@ -77,7 +77,7 @@ public:
const XQModelSection& sectionByKey( const QString& sectionKey ) const; const XQModelSection& sectionByKey( const QString& sectionKey ) const;
const XQModelSection& sectionByRow( int row ) const; const XQModelSection& sectionByRow( int row ) const;
const XQModelSection& createSection(const QString& sectionKey, const QModelIndex& modelIndex, XQNodePtr sheetNode); const XQModelSection& createSection(const QModelIndex& modelIndex, XQNodePtr sheetNode);
int lastRow(const XQModelSection& section ) const; int lastRow(const XQModelSection& section ) const;
XQSectionRange sectionRange(const XQModelSection &section) const; XQSectionRange sectionRange(const XQModelSection &section) const;

View File

@@ -165,9 +165,8 @@ void XQViewModel::addSection(const XQItemList& list, const XQNodePtr& sheetNode
// 5. das erzeugt dann auch valide indices // 5. das erzeugt dann auch valide indices
appendRow(list); appendRow(list);
const QString &sectionKey = sheetNode->attribute(c_ContentType); // 6. jetzt können wir auch die section erzeugen
// 6. jetzt können wir auch die sction erzeugen const XQModelSection& section = _sections.createSection( list[0]->index(), sheetNode );
const XQModelSection& section = _sections.createSection( sectionKey, list[0]->index(), sheetNode );
// ... und es der welt mitteilen. // ... und es der welt mitteilen.
emit sectionCreated( section ); emit sectionCreated( section );
@@ -187,18 +186,17 @@ void XQViewModel::onToggleSection(const QString& sectionKey )
void XQViewModel::toggleSection( const XQModelSection& section ) void XQViewModel::toggleSection( const XQModelSection& section )
{ {
qDebug() << " --- toggleSection: " << section.contentType();
if( section.isValid() && _treeTable ) if( section.isValid() && _treeTable )
{ {
XQSectionRange pos = _sections.sectionRange(section);
//int fstRow = _sections.firstRow(index);
//int lstRow = _sections.lastRow(index);
_treeTable->toggleRowsHidden(pos.firstRow, pos.lastRow );
qDebug() << " --- toggleSection: " << section.contentType(); qDebug() << " --- toggleSection: " << section.contentType();
XQSectionRange pos = _sections.sectionRange(section);
_treeTable->toggleRowsHidden(pos.firstRow, pos.lastRow );
// hier nicht!? // hier nicht!?
emit sectionToggled(section); //emit sectionToggled(section);
}
else
{
qDebug() << " --- toggleSection: FAIL!";
} }
} }
@@ -217,7 +215,7 @@ void XQViewModel::onItemChanged(XQItem* item )
void XQViewModel::onActionTriggered(QAction* action) void XQViewModel::onActionTriggered(QAction* action)
{ {
qDebug() << " --- onActionTriggered: count:" << XQNode::s_Count; qDebug() << " --- onActionTriggered: count:" << action->text() <<": " << XQNode::s_Count;
// all selected indices // all selected indices
QModelIndexList selectionList = treeTable()->selectionModel()->selectedRows(); QModelIndexList selectionList = treeTable()->selectionModel()->selectedRows();
@@ -226,6 +224,7 @@ void XQViewModel::onActionTriggered(QAction* action)
switch( cmdType ) switch( cmdType )
{ {
// just handle undo ... // just handle undo ...
case XQCommand::cmdUndo : case XQCommand::cmdUndo :
return _undoStack->undo(); return _undoStack->undo();
@@ -250,14 +249,15 @@ void XQViewModel::onActionTriggered(QAction* action)
// we create a command // we create a command
XQCommand* command = new XQCommand( cmdType, this ); XQCommand* command = new XQCommand( cmdType, this );
QModelIndex currentIndex = treeTable()->currentIndex();
command->setOriginIndex(currentIndex);
// store the row positions of the selected indices // store the row positions of the selected indices
command->saveNodes( selectionList ); command->saveNodes( selectionList );
command->setOriginIndex( treeTable()->currentIndex() );
// execute command // execute command
_undoStack->push( command ); _undoStack->push( command );
} }
@@ -455,7 +455,7 @@ void XQViewModel::cmdDeleteUndo( const XQCommand& command )
{ {
for (const auto& entry : command) for (const auto& entry : command)
{ {
qDebug() << " --- delete UNDo: " << entry.contentNode->to_string(); qDebug() << " --- delete UNDo: " << entry.contentNode->friendly_name();
} }
} }
@@ -506,7 +506,8 @@ void XQViewModel::cmdToggleSection( const XQCommand& command )
{ {
const QModelIndex& index = command.originIndex(); const QModelIndex& index = command.originIndex();
Q_ASSERT(index.isValid()); Q_ASSERT(index.isValid());
toggleSection( _sections.sectionByRow(index.row()) ); const XQModelSection& section = _sections.sectionByRow(index.row());
toggleSection( section );
} }

View File

@@ -89,6 +89,7 @@ public:
} }
inline bool isEmpty() const inline bool isEmpty() const
{ {
return (_data.size()==0); return (_data.size()==0);
@@ -156,14 +157,14 @@ public:
T& operator[]( const QString& key ) T& operator[]( const QString& key )
{ {
if( key.isEmpty() || !contains(key) ) if( key.isEmpty() || !contains(key) )
throw XQException("maprow operator[]: key empty || not found: " + key); throw XQException("XQMaptor operator[]: key empty || not found: " + key);
return _data[ _index[key] ]; return _data[ _index[key] ];
} }
const T& operator[]( const QString& key ) const const T& operator[]( const QString& key ) const
{ {
if (key.isEmpty() || !contains(key)) if (key.isEmpty() || !contains(key))
throw XQException("maprow operator[]: key empty || not found: " + key); throw XQException("XQMaptor operator[]: key empty || not found: " + key);
return _data[_index[key]]; return _data[_index[key]];
} }
@@ -177,6 +178,35 @@ public:
return (*this)[key]; return (*this)[key];
} }
const T& last() const
{
if(_data.isEmpty())
throw XQException( "XQMaptor last: is empty!" );
return _data.last();
}
const T& first() const
{
if(_data.isEmpty())
throw XQException( "XQMaptor first: is empty!" );
return _data.first();
}
T& last()
{
if(_data.isEmpty())
throw XQException( "XQMaptor last: is empty!" );
return _data.last();
}
T& first()
{
if(_data.isEmpty())
throw XQException( "XQMaptor first: is empty!" );
return _data.first();
}
virtual int add( const T& item ) virtual int add( const T& item )
{ {
_data.push_back( item ); _data.push_back( item );
@@ -186,7 +216,7 @@ public:
virtual void addAtIndex( int index, const T& item ) virtual void addAtIndex( int index, const T& item )
{ {
if(contains(index)) if(contains(index))
throw XQException( "QStringrow::add: index out of range!" ); throw XQException( "XQMaptor add at index: index out of range!" );
_data[index] = item; _data[index] = item;
} }