-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#228 Draft a naive "Wetherell and Shannon" implementation. WIP.
Signed-off-by: cneben <benoit@destrat.io>
- Loading branch information
Showing
3 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright (c) 2008-2024, Benoit AUTHEMAN All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the author or Destrat.io nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
//----------------------------------------------------------------------------- | ||
// This file is a part of the QuickQanava software library. | ||
// | ||
// \file qanOrgTreeLayout.h | ||
// \author benoit@destrat.io | ||
// \date 2024 08 13 | ||
//----------------------------------------------------------------------------- | ||
|
||
// Std headers | ||
#include <memory> | ||
|
||
// Qt headers | ||
#include <QQmlProperty> | ||
#include <QVariant> | ||
#include <QQmlEngine> | ||
#include <QQmlComponent> | ||
|
||
// QuickQanava headers | ||
#include "./qanOrgTreeLayout.h" | ||
|
||
namespace qan { // ::qan | ||
|
||
/* OrgTreeLayout Object Management *///---------------------------------------- | ||
OrgTreeLayout::OrgTreeLayout(QObject* parent) noexcept : | ||
QObject{parent} | ||
{ | ||
} | ||
|
||
OrgTreeLayout::~OrgTreeLayout() | ||
{ | ||
} | ||
|
||
void OrgTreeLayout::layout(qan::Node& root) noexcept | ||
{ | ||
// Pre-condition: root must be a tree subgraph, this is not enforced in this methodod. | ||
|
||
// Algorithm: | ||
// 1. Use BFS to generate an array of nodes "level by level". | ||
// 2. Layout the tree bottom up | ||
// 3. Shift the tree to align root to it's original position. | ||
|
||
// 1. BFS | ||
|
||
} | ||
//----------------------------------------------------------------------------- | ||
|
||
} // ::qan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright (c) 2008-2024, Benoit AUTHEMAN All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the author or Destrat.io nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
//----------------------------------------------------------------------------- | ||
// This file is a part of the QuickQanava software library. | ||
// | ||
// \file qanOrgTreeLayout.h | ||
// \author benoit@destrat.io | ||
// \date 2024 08 13 | ||
//----------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
// Qt headers | ||
#include <QString> | ||
#include <QQuickItem> | ||
#include <QQmlParserStatus> | ||
#include <QSharedPointer> | ||
#include <QAbstractListModel> | ||
|
||
// QuickQanava headers | ||
#include "../../src/qanGraph.h" | ||
|
||
|
||
namespace qan { // ::qan | ||
|
||
/*! \brief | ||
* \nosubgrouping | ||
*/ | ||
class OrgTreeLayout : public QObject | ||
{ | ||
Q_OBJECT | ||
/*! \name OrgTreeLayout Object Management *///----------------------------- | ||
//@{ | ||
public: | ||
explicit OrgTreeLayout(QObject* parent = nullptr) noexcept; | ||
virtual ~OrgTreeLayout() override; | ||
OrgTreeLayout(const OrgTreeLayout&) = delete; | ||
OrgTreeLayout& operator=(const OrgTreeLayout&) = delete; | ||
OrgTreeLayout(OrgTreeLayout&&) = delete; | ||
OrgTreeLayout& operator=(OrgTreeLayout&&) = delete; | ||
|
||
public: | ||
/*! \brief Apply an "organisational chart tree layout algorithm" to subgraph \c root. | ||
* | ||
* OrgChart layout _will preserve_ node orders. | ||
* | ||
* While the current implementation is not "space optimal" it run in O(n), n beeing the | ||
* number of nodes in root "tree subgraph". | ||
* | ||
* \note \c root must be a tree subgraph, this method will not enforce this condition, | ||
* running this algorithm on a non tree subgraph might lead to inifinite recursions or | ||
* invalid layouts. | ||
*/ | ||
Q_INVOKABLE virtual void layout(qan::Node& root) noexcept; | ||
//@} | ||
//------------------------------------------------------------------------- | ||
}; | ||
|
||
} // ::qan | ||
|
||
QML_DECLARE_TYPE(qan::OrgTreeLayout) | ||
|