* \brief Save the current state of the tree view * (expanded items and the currently selected item) as XML */
| 967 | * (expanded items and the currently selected item) as XML |
| 968 | */ |
| 969 | void ProjectExplorer::save(QXmlStreamWriter* writer) const { |
| 970 | const auto* model = static_cast<AspectTreeModel*>(m_treeView->model()); |
| 971 | const auto& selectedRows = m_treeView->selectionModel()->selectedRows(); |
| 972 | |
| 973 | writer->writeStartElement(QStringLiteral("state")); |
| 974 | |
| 975 | // check whether the project node itself is expanded or selected or current |
| 976 | const auto& index = m_treeView->model()->index(0, 0); |
| 977 | if (m_treeView->isExpanded(index)) { |
| 978 | writer->writeStartElement(QStringLiteral("expanded")); |
| 979 | writer->writeAttribute(QStringLiteral("path"), m_project->path()); |
| 980 | writer->writeEndElement(); |
| 981 | } |
| 982 | |
| 983 | if (selectedRows.indexOf(index) != -1) { |
| 984 | writer->writeStartElement(QStringLiteral("selected")); |
| 985 | writer->writeAttribute(QStringLiteral("path"), m_project->path()); |
| 986 | writer->writeEndElement(); |
| 987 | } |
| 988 | |
| 989 | if (index == m_treeView->currentIndex()) { |
| 990 | writer->writeStartElement(QStringLiteral("current")); |
| 991 | writer->writeAttribute(QStringLiteral("path"), m_project->path()); |
| 992 | writer->writeEndElement(); |
| 993 | } |
| 994 | |
| 995 | // traverse the children nodes |
| 996 | const auto& children = m_project->children<AbstractAspect>(AbstractAspect::ChildIndexFlag::Recursive); |
| 997 | for (const auto* aspect : children) { |
| 998 | const QString& path = aspect->path(); |
| 999 | const auto* part = dynamic_cast<const AbstractPart*>(aspect); |
| 1000 | |
| 1001 | if (part && part->hasMdiSubWindow()) { |
| 1002 | writer->writeStartElement(QStringLiteral("view")); |
| 1003 | const auto& geometry = part->dockWidget()->geometry(); |
| 1004 | writer->writeAttribute(QStringLiteral("path"), path); |
| 1005 | writer->writeAttribute(QStringLiteral("state"), QString::number(part->view()->windowState())); |
| 1006 | writer->writeAttribute(QStringLiteral("x"), QString::number(geometry.x())); |
| 1007 | writer->writeAttribute(QStringLiteral("y"), QString::number(geometry.y())); |
| 1008 | writer->writeAttribute(QStringLiteral("width"), QString::number(geometry.width())); |
| 1009 | writer->writeAttribute(QStringLiteral("height"), QString::number(geometry.height())); |
| 1010 | writer->writeEndElement(); |
| 1011 | } |
| 1012 | |
| 1013 | const auto& index = model->modelIndexOfAspect(aspect); |
| 1014 | if (model->rowCount(index) > 0 && m_treeView->isExpanded(index)) { |
| 1015 | writer->writeStartElement(QStringLiteral("expanded")); |
| 1016 | writer->writeAttribute(QStringLiteral("path"), path); |
| 1017 | writer->writeEndElement(); |
| 1018 | } |
| 1019 | |
| 1020 | if (selectedRows.indexOf(index) != -1) { |
| 1021 | writer->writeStartElement(QStringLiteral("selected")); |
| 1022 | writer->writeAttribute(QStringLiteral("path"), path); |
| 1023 | writer->writeEndElement(); |
| 1024 | } |
| 1025 | |
| 1026 | if (index == m_treeView->currentIndex()) { |
nothing calls this directly
no test coverage detected