Skip to content

Commit

Permalink
#228 Draft a naive "Wetherell and Shannon" implementation. WIP.
Browse files Browse the repository at this point in the history
Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Aug 13, 2024
1 parent 3bb0216 commit 1549900
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 2 deletions.
7 changes: 5 additions & 2 deletions samples/layouts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ endif()

set(source_files
layouts.cpp
qanOrgTreeLayout.cpp
)

set (header_files)
set (header_files
qanOrgTreeLayout.h
)

add_executable(sample_layouts ${source_files} layouts.qrc)
add_executable(sample_layouts ${source_files} ${header_files} layouts.qrc)
target_include_directories(sample_layouts PUBLIC QuickQanava Qt${QT_VERSION_MAJOR}::QuickControls2)
target_link_libraries(sample_layouts
QuickQanava
Expand Down
73 changes: 73 additions & 0 deletions samples/layouts/qanOrgTreeLayout.cpp
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 [email protected]
// \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
86 changes: 86 additions & 0 deletions samples/layouts/qanOrgTreeLayout.h
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 [email protected]
// \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)

0 comments on commit 1549900

Please sign in to comment.