remorked sections.

This commit is contained in:
2025-09-05 21:42:40 +02:00
parent b8f0893d59
commit 3887748c1a
7 changed files with 44 additions and 67 deletions

View File

@@ -57,8 +57,7 @@ void XQChildModel::addModelData( const XQNodePtr& contentRoot )
const XQModelSection& section = _sections.sectionByKey( key ); const XQModelSection& section = _sections.sectionByKey( key );
section.setContentRootNode( contentEntry->parent() ); section.setContentRootNode( contentEntry->parent() );
// FaRZ! int newRow = _sections.lastRow(section);
//int newRow = _sections.lastRow(section);
XQNodePtr sheetNode = section.sheetRootNode(); XQNodePtr sheetNode = section.sheetRootNode();
XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry ); XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry );
@@ -80,8 +79,7 @@ void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& content
if(section.isValid() ) if(section.isValid() )
{ {
section.setContentRootNode( contentEntry->parent() ); section.setContentRootNode( contentEntry->parent() );
// FARZ! int newRow =_sections.lastRow(section);
int newRow = 1;//_sections.lastRow(section);
XQNodePtr sheetNode = section.sheetRootNode(); XQNodePtr sheetNode = section.sheetRootNode();
XQItemList list = _itemFactory.makeRow( sheetNode, nullptr ); XQItemList list = _itemFactory.makeRow( sheetNode, nullptr );
insertRow( newRow, list); insertRow( newRow, list);

View File

@@ -61,6 +61,8 @@ public:
cmdNew, cmdNew,
cmdDelete, cmdDelete,
cmdToggleSection,
cmdExtern //?? cmdExtern //??
}; };

View File

@@ -40,7 +40,7 @@ bool XQModelSection::isValid() const
return _modelIndex.isValid() && _sectionRootNode; return _modelIndex.isValid() && _sectionRootNode;
} }
QModelIndex XQModelSection::persistentModelIndex() const QModelIndex XQModelSection::startIndex() const
{ {
return _modelIndex.operator QModelIndex(); return _modelIndex.operator QModelIndex();
} }
@@ -80,7 +80,7 @@ void XQModelSection::setContentRootNode( const XQNodePtr contentRootNode ) const
//! gibt die zeile des start-index zurück. //! gibt die zeile des start-index zurück.
int XQModelSection::XQModelSection::row() const int XQModelSection::XQModelSection::firstRow() const
{ {
return _modelIndex.row(); return _modelIndex.row();
} }
@@ -111,7 +111,7 @@ bool XQSectionManager::hasValidSection(const QString& sectionKey) const
return _sections.at(sectionKey).isValid(); return _sections.at(sectionKey).isValid();
} }
const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey ) const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey ) const
{ {
if( hasValidSection( sectionKey ) ) if( hasValidSection( sectionKey ) )
return _sections.at(sectionKey); return _sections.at(sectionKey);
@@ -121,29 +121,20 @@ const XQModelSection& XQSectionManager::sectionByKey( const QString& sectionKey
} }
//! gibt für einen model index die 'zuständige' section zurück.
const XQModelSection& XQSectionManager::sectionByIndex( const QModelIndex& index ) const
{
return sectionByRow( index.row() );
}
//! gibt für eine zeile die 'zuständige' section zurück: der bestand an section wird //! gibt für eine zeile die 'zuständige' section zurück: der bestand an section wird
//! nach der passenden section durchsucht. //! nach der passenden section durchsucht.
const XQModelSection& XQSectionManager::sectionByRow(int itemRow ) const const XQModelSection& XQSectionManager::sectionByRow(int itemRow ) const
{ {
int i = _sections.size() - 1; int i = _sections.size() - 1;
for (; i >= 0; --i) for (; i >= 0; --i)
{ {
if ( _sections.at(i).persistentModelIndex().row() < itemRow ) if ( _sections.at(i).startIndex().row() < itemRow )
return _sections.at(i); return _sections.at(i);
} }
static XQModelSection s_DummySection; static XQModelSection s_DummySection;
return s_DummySection; return s_DummySection;
} }
@@ -156,14 +147,6 @@ const XQModelSection& XQSectionManager::createSection(const QString& sectionKey,
return sectionByKey(sectionKey); return sectionByKey(sectionKey);
} }
//! ermittelt die erste zeile einer section.
/*
int XQSectionManager::firstRow(const QModelIndex& idx) const
{
return sectionByRow(idx.row() ).row();
}
*/
//! 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.
@@ -177,10 +160,11 @@ int XQSectionManager::lastRow(const QModelIndex& idx) const
//! ermittelt die zeile unterhalb der gegebenen section, //! ermittelt die zeile unterhalb der gegebenen section,
//! zum einfügen neuer items ebendort. //! 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.modelIndex.data().toString() << " --> " << section.modelIndex.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);
@@ -188,23 +172,18 @@ int XQSectionManager::lastRow(const XQModelSection& section ) const
{ {
// last section? return last row of model // last section? return last row of model
if (index == _sections.size() - 1) if (index == _sections.size() - 1)
return section.persistentModelIndex().model()->rowCount();// - 1; return section.startIndex().model()->rowCount() - 1;
// return row above the row of the next section -> last row of given section // return row above the row of the next section -> last row of given section
return _sections.at(index+1).row(); return _sections.at(index+1).firstRow() - 1;
} }
return -1; return -1;
} }
*/
/*
int firstRow(const QModelIndex& idx) const;
int lastRow(const QModelIndex& idx) const;
int lastRow(const XQModelSection& section) const;
*/
XQSectionPos XQSectionManager::sectionPos() XQSectionRange XQSectionManager::sectionRange(const XQModelSection& section ) const
{ {
return XQSectionPos(); qDebug() << " ---- Section RANGE: " << section.startIndex().row() << " -> " << lastRow(section);
return XQSectionRange{ section.startIndex().row(), lastRow(section) };
} }
@@ -215,7 +194,7 @@ void XQSectionManager::dump() const
qDebug() << " --- sections dump(): " <<_sections.size() << " entries."; qDebug() << " --- sections dump(): " <<_sections.size() << " entries.";
for( int i = 0; i<_sections.size(); ++i ) for( int i = 0; i<_sections.size(); ++i )
{ {
QModelIndex idx = _sections.at(i).persistentModelIndex(); QModelIndex idx = _sections.at(i).startIndex();
qDebug() << " --- sections:" << i << "row: " << idx.row() << " keyOf(i): " << _sections.keyOf(i) << " indexData: "<< idx.data().toString() << " itemData: " << XQItem::xqItemFromIndex(idx).data(Qt::DisplayRole).toString(); qDebug() << " --- sections:" << i << "row: " << idx.row() << " keyOf(i): " << _sections.keyOf(i) << " indexData: "<< idx.data().toString() << " itemData: " << XQItem::xqItemFromIndex(idx).data(Qt::DisplayRole).toString();
} }

View File

@@ -36,9 +36,9 @@ public:
bool operator==(const XQModelSection& other) const; bool operator==(const XQModelSection& other) const;
bool isValid() const; bool isValid() const;
int row() const; int firstRow() const;
QModelIndex persistentModelIndex() const; QModelIndex startIndex() const;
XQNodePtr sectionRootNode() const; XQNodePtr sectionRootNode() const;
XQNodePtr sheetRootNode() const; XQNodePtr sheetRootNode() const;
XQNodePtr contentRootNode() const; XQNodePtr contentRootNode() const;
@@ -59,7 +59,7 @@ protected:
Q_DECLARE_METATYPE(XQModelSection) Q_DECLARE_METATYPE(XQModelSection)
//! Erste und letzte ziele einer XQModelSection //! Erste und letzte ziele einer XQModelSection
struct XQSectionPos struct XQSectionRange
{ {
int firstRow{-1}; int firstRow{-1};
int lastRow{-1}; int lastRow{-1};
@@ -74,19 +74,12 @@ public:
bool hasValidSection(const QString& sectionKey) const; bool hasValidSection(const QString& sectionKey) const;
const XQModelSection& sectionByKey( const QString& sectionKey ); const XQModelSection& sectionByKey( const QString& sectionKey ) const;
const XQModelSection& sectionByRow( int row ) const; const XQModelSection& sectionByRow( int row ) const;
const XQModelSection& sectionByIndex( const QModelIndex& index ) const;
const XQModelSection& createSection(const QString& sectionKey, const QModelIndex& modelIndex, XQNodePtr sheetNode); const XQModelSection& createSection(const QString& sectionKey, const QModelIndex& modelIndex, XQNodePtr sheetNode);
/*
int firstRow(const QModelIndex& idx) const;
int lastRow(const QModelIndex& idx) const;
int lastRow(const XQModelSection& section ) const; int lastRow(const XQModelSection& section ) const;
*/ XQSectionRange sectionRange(const XQModelSection &section) const;
XQSectionPos sectionPos();
void dump()const; void dump()const;

View File

@@ -175,22 +175,31 @@ void XQViewModel::addSection(const XQItemList& list, const XQNodePtr& sectionNod
} }
//! SLOT, toggled die section mit dem 'sectionKey' (hier: contentType)
void XQViewModel::onToggleSection(const QString& sectionKey ) void XQViewModel::onToggleSection(const QString& sectionKey )
{ {
qDebug() << " --- onToggleSection: " << sectionKey; toggleSection( _sections.sectionByKey(sectionKey) );
if( _sections.hasValidSection( sectionKey ) && _treeTable ) }
{
//const XQModelSection& section =_sections.sectionByKey(sectionKey);
//! toggled die gegebene model section.
void XQViewModel::toggleSection( const XQModelSection& section )
{
qDebug() << " --- toggleSection: " << section.contentType();
if( section.isValid() && _treeTable )
{
XQSectionRange pos = _sections.sectionRange(section);
//int fstRow = _sections.firstRow(index); //int fstRow = _sections.firstRow(index);
//int lstRow = _sections.lastRow(index); //int lstRow = _sections.lastRow(index);
//_treeTable->toggleRowsHidden(fstRow, lstRow); //_treeTable->toggleRowsHidden(fstRow, lstRow);
// hier nicht!?
//emit sectionToggled(section); //emit sectionToggled(section);
}
} }
}
/* /*
@@ -463,7 +472,7 @@ void XQViewModel::cmdNew( const XQCommand& command )
//... //...
const XQModelSection& section = _sections.sectionByIndex( origin ); const XQModelSection& section = _sections.sectionByRow( origin.row() );
// neue, leere zeile erzeugen ... // neue, leere zeile erzeugen ...
XQItemList list =_itemFactory.makeRow( section.sheetRootNode(), newNode ); XQItemList list =_itemFactory.makeRow( section.sheetRootNode(), newNode );
@@ -489,14 +498,13 @@ void XQViewModel::cmdNewUndo( const XQCommand& command )
//! schaltet eine section sichtbar oder unsichtbar. //! schaltet eine section sichtbar oder unsichtbar.
/*
void XQViewModel::cmdToggleSection( const XQCommand& command ) 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.sectionByIndex(index) ); toggleSection( _sections.sectionByRow(index.row()) );
} }
*/
//! gibt die treetable zurück //! gibt die treetable zurück

View File

@@ -55,7 +55,7 @@ public:
virtual void initModel( const QString& modelName); virtual void initModel( const QString& modelName);
void expandNewItem(const QModelIndex& index); void expandNewItem(const QModelIndex& index);
void toggleSection( const QString& sectionKey ); void toggleSection( const XQModelSection& section );
//little helpers //little helpers
const XQItem& xqRootItem(); const XQItem& xqRootItem();
@@ -66,7 +66,7 @@ public:
// undo-/redo-able stuff // undo-/redo-able stuff
//virtual void cmdToggleSection( const XQCommand& command ); virtual void cmdToggleSection( const XQCommand& command );
virtual void cmdCut( const XQCommand& command ); virtual void cmdCut( const XQCommand& command );
virtual void cmdCutUndo( const XQCommand& command ); virtual void cmdCutUndo( const XQCommand& command );
virtual void cmdPaste( const XQCommand& command ); virtual void cmdPaste( const XQCommand& command );
@@ -91,13 +91,10 @@ public slots:
virtual void onShowContextMenu(const QPoint& point); virtual void onShowContextMenu(const QPoint& point);
virtual void onActionTriggered(QAction* action); virtual void onActionTriggered(QAction* action);
virtual void onToggleSection(const QString& sectionKey ); virtual void onToggleSection(const QString& sectionKey );
// handle XQCommands ( == UndoCommand ) // handle XQCommands ( == UndoCommand )
virtual void onCommandRedo( const XQCommand& command ); virtual void onCommandRedo( const XQCommand& command );
virtual void onCommandUndo( const XQCommand& command ); virtual void onCommandUndo( const XQCommand& command );
protected: protected:
void addSection(const XQItemList& list, const XQNodePtr& sheetNode ); void addSection(const XQItemList& list, const XQNodePtr& sheetNode );

View File

@@ -31,7 +31,7 @@ void XQContextMenu::addAction(const QString& text, XQCommand::CmdType commandTyp
QAction* newAction = new QAction(text, this); QAction* newAction = new QAction(text, this);
newAction->setData(commandType); newAction->setData(commandType);
_actionMap[commandType] = newAction; _actionMap[commandType] = newAction;
QWidget::addAction(newAction); QMenu::addAction(newAction);
setActionEnabled( commandType, enabled ); setActionEnabled( commandType, enabled );
} }
@@ -53,7 +53,7 @@ void XQContextMenu::addAction(const QIcon& icon, const QString& text, XQCommand:
QAction* newAction = new QAction(icon, text, this); QAction* newAction = new QAction(icon, text, this);
newAction->setData(commandType); newAction->setData(commandType);
_actionMap[commandType] = newAction; _actionMap[commandType] = newAction;
QWidget::addAction(newAction); QMenu::addAction(newAction);
setActionEnabled( commandType, enabled ); setActionEnabled( commandType, enabled );
} }