Skip to content

Commit

Permalink
Cosmetic changes in QuickContainerModel.
Browse files Browse the repository at this point in the history
Refactor topology sample.
Finally fix bug cneben#81

Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Jun 1, 2020
1 parent 2328b99 commit 9211bda
Show file tree
Hide file tree
Showing 25 changed files with 304 additions and 319 deletions.
2 changes: 1 addition & 1 deletion GTpo/src/gtpo/edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class edge : public config_t::edge_base,
explicit edge( const weak_node_t& src, const weak_node_t& dst ) :
config_t::edge_base{}, _src{ src }, _dst{ dst } { }
virtual ~edge() {
if ( _graph != nullptr )
if (_graph != nullptr)
std::cerr << "gtpo::edge<>::~edge(): Warning: an edge has been deleted before beeing " <<
"removed from the graph." << std::endl;
_graph = nullptr;
Expand Down
16 changes: 9 additions & 7 deletions GTpo/src/gtpo/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ void graph<config_t>::clear() noexcept
{
// Note 20160104: First edges, then nodes (it helps maintaining topology if
// womething went wrong during destruction
for ( auto& edge: _edges ) // Do not maintain topology during edge deletion
edge->_graph = nullptr;
_edges_search.clear();
_edges.clear();
for ( auto& node: _nodes ) // Do not maintain topology during node deletion
node->_graph = nullptr;
_root_nodes.clear(); // Remove weak_ptr containers first
_nodes_search.clear();
_nodes.clear();

for ( auto& edge: _edges ) // Do not maintain topology during edge deletion
edge->_graph = nullptr;
_edges_search.clear();
_edges.clear();

// Clearing groups and behaviours (Not: group->_graph is resetted with nodes)
_groups.clear();
behaviourable_base::clear();
Expand All @@ -76,11 +77,11 @@ auto graph<config_t>::create_node( ) -> weak_node_t
template < class config_t >
auto graph<config_t>::insert_node( shared_node_t node ) -> weak_node_t
{
assert_throw( node != nullptr, "gtpo::graph<>::insert_node(): Error: Trying to insert a nullptr node in graph." );
assert_throw(node != nullptr, "gtpo::graph<>::insert_node(): Error: Trying to insert a nullptr node in graph.");
weak_node_t weak_node;
try {
weak_node = node;
node->set_graph( this );
node->set_graph(this);
config_t::template container_adapter< shared_nodes_t >::insert( node, _nodes );
config_t::template container_adapter< weak_nodes_t_search >::insert( weak_node, _nodes_search );
config_t::template container_adapter< weak_nodes_t >::insert( weak_node, _root_nodes );
Expand Down Expand Up @@ -197,8 +198,9 @@ auto graph<config_t>::insert_edge( shared_edge_t edge ) -> weak_edge_t
edge->get_dst().expired() )
throw gtpo::bad_topology_error( "gtpo::graph<>::insert_edge(): Error: Either source and/or destination nodes are expired." );
edge->set_graph( this );
weak_edge_t weak_edge = edge;
config_t::template container_adapter<shared_edges_t>::insert( edge, _edges );
config_t::template container_adapter<weak_edges_search_t>::insert( edge, _edges_search );
config_t::template container_adapter<weak_edges_search_t>::insert( weak_edge, _edges_search );
try {
source->add_out_edge( edge );
auto destination = edge->get_dst().lock();
Expand Down
25 changes: 10 additions & 15 deletions QuickContainers/include/qcmContainerModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,11 @@ class ContainerModel : public QAbstractListModel

public:
enum PropertiesRoles {
ItemDataRole = Qt::UserRole + 1,
ItemLabelRole
ItemDataRole = Qt::UserRole + 1
};
protected:
virtual QHash< int, QByteArray > roleNames( ) const override {
QHash< int, QByteArray > roles;
roles[ItemDataRole] = "itemData";
roles[ItemLabelRole] = "itemLabel";
return roles;
virtual QHash<int, QByteArray> roleNames() const override {
return { {static_cast<int>(ItemDataRole), "itemData"} };
}
//@}
//-------------------------------------------------------------------------
Expand Down Expand Up @@ -281,13 +277,12 @@ class ContainerModelImpl : public qcm::ContainerModel
return ( parent.isValid() ? 0 : static_cast<int>(_container.size()) );
}
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override {
if ( index.row() >= 0 &&
index.row() < static_cast<int>(_container.size()) ) {
if ( role == Qt::DisplayRole ||
role == ContainerModel::ItemLabelRole )
return dataDisplayRole( index.row(), typename ItemDispatcher<T>::type{} );
else if ( role == ContainerModel::ItemDataRole )
return dataItemRole( index.row(), typename ItemDispatcher<T>::type{} );
if (index.row() >= 0 &&
index.row() < static_cast<int>(_container.size())) {
if (role == Qt::DisplayRole)
return dataDisplayRole(index.row(), typename ItemDispatcher<T>::type{});
else if (role == ContainerModel::ItemDataRole)
return dataItemRole(index.row(), typename ItemDispatcher<T>::type{});
}
return QVariant{};
}
Expand Down Expand Up @@ -369,7 +364,7 @@ class ContainerModelImpl : public qcm::ContainerModel
inline auto dataItemRole( int, ItemDispatcherBase::ptr_type ) const -> QVariant { /* empty */ return QVariant{}; }
inline auto dataItemRole( int row, ItemDispatcherBase::ptr_qobject_type ) const -> QVariant {
T item = qobject_cast<T>(at( row ));
if ( item != nullptr )
if (item != nullptr)
QQmlEngine::setObjectOwnership( item, QQmlEngine::CppOwnership );
return QVariant::fromValue< T >( item );
}
Expand Down
20 changes: 10 additions & 10 deletions quickqanava.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ test-cpp.subdir = samples/cpp
#test-40k.subdir = samples/40k
#test-40k.depends = quickqanava

SUBDIRS += test-resizer
SUBDIRS += test-navigable
SUBDIRS += test-nodes
SUBDIRS += test-edges
SUBDIRS += test-connector
SUBDIRS += test-groups
SUBDIRS += test-selection
SUBDIRS += test-style
#SUBDIRS += test-resizer
#SUBDIRS += test-navigable
#SUBDIRS += test-nodes
#SUBDIRS += test-edges
#SUBDIRS += test-connector
#SUBDIRS += test-groups
#SUBDIRS += test-selection
#SUBDIRS += test-style
SUBDIRS += test-topology
SUBDIRS += test-dataflow
SUBDIRS += test-cpp
#SUBDIRS += test-dataflow
#SUBDIRS += test-cpp

#SUBDIRS += test-40k

Expand Down
12 changes: 7 additions & 5 deletions samples/nodes/nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ int main( int argc, char** argv )
{
QGuiApplication app(argc, argv);
QQuickStyle::setStyle("Material");
QQmlApplicationEngine engine;
engine.addPluginPath(QStringLiteral("../../src")); // Necessary only for development when plugin is not installed to QTDIR/qml
QuickQanava::initialize(&engine);
engine.load(QUrl("qrc:/nodes.qml"));
return app.exec();
QQmlApplicationEngine* engine = new QQmlApplicationEngine();
engine->addPluginPath(QStringLiteral("../../src")); // Necessary only for development when plugin is not installed to QTDIR/qml
QuickQanava::initialize(engine);
engine->load(QUrl("qrc:/nodes.qml"));
const auto status = app.exec();
delete engine;
return status;
}
//-----------------------------------------------------------------------------

Expand Down
110 changes: 110 additions & 0 deletions samples/topology/EdgesList.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright (c) 2020, 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.
*/

import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.1

import QuickQanava 2.0 as Qan
import TopologySample 1.0 as Qan
import "qrc:/QuickQanava" as Qan

ListView {
id: edgesList

// PUBLIC /////////////////////////////////////////////////////////////////
model: undefined

// PRIVATE ////////////////////////////////////////////////////////////////
clip: true
spacing: 4
focus: true
flickableDirection: Flickable.VerticalFlick
highlight: Rectangle {
x: 0
y: edgesList.currentItem != null ? edgesList.currentItem.y : 0
width: edgesList.width
height: edgesList.currentItem != null ? edgesList.currentItem.height : 100
color: Material.accent
opacity: 0.7
radius: 3
Behavior on y {
SpringAnimation {
duration: 200
spring: 2
damping: 0.1
}
}
}
delegate: Item {
id: edgeDelegate
width: ListView.view.width
height: edgeLayout.implicitHeight
ColumnLayout {
anchors.fill: parent
id: edgeLayout
/*property string srcLabel: ""
property string dstLabel: ""
property var edgeItemData: itemData
onEdgeItemDataChanged: {
if (itemData && itemData.item) {
if (itemData.item.sourceItem
&& itemData.item.sourceItem.node)
srcLabel = itemData.item.sourceItem.node.label
if (itemData.item.destinationItem
&& itemData.item.destinationItem.node)
dstLabel = itemData.item.destinationItem.node.label
else if (itemData.item.destinationItem
&& itemData.item.destinationItem.node)
dstLabel = itemData.item.destinationEdge.edge.label
} else {
srcLabel = ""
dstLabel = ""
}
}*/
readonly property string srcLabel: itemData && itemData.item &&
itemData.item.sourceItem && itemData.item.sourceItem.node ? itemData.item.sourceItem.node.label : ""
readonly property string dstLabel: itemData && itemData.item &&
itemData.item.destinationItem && itemData.item.destinationItem.node ? itemData.item.destinationItem.node.label : ""
Label {
text: "Label: " + itemData.label
}
Label {
text: " Src: " + parent.srcLabel
}
Label {
text: " Dst: " + parent.dstLabel
}
}
MouseArea {
anchors.fill: parent
onClicked: {
edgeDelegate.ListView.view.currentIndex = index
}
}
} // Item: delegate
} // ListView: edgeList
2 changes: 1 addition & 1 deletion samples/topology/FaceNode.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2017, Benoit AUTHEMAN All rights reserved.
Copyright (c) 2020, 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:
Expand Down
7 changes: 2 additions & 5 deletions samples/topology/qanFaceNode.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2017, Benoit AUTHEMAN All rights reserved.
Copyright (c) 2020, 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:
Expand Down Expand Up @@ -39,10 +39,7 @@
namespace qan { // ::qan

FaceNode::FaceNode(QQuickItem* parent) :
qan::Node{parent}
{

}
qan::Node{parent} { }

QQmlComponent* FaceNode::delegate(QQmlEngine& engine) noexcept
{
Expand Down
22 changes: 12 additions & 10 deletions samples/topology/qanFaceNode.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2017, Benoit AUTHEMAN All rights reserved.
Copyright (c) 2020, 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:
Expand Down Expand Up @@ -46,18 +46,18 @@ class FaceNode : public qan::Node
{
Q_OBJECT
public:
explicit FaceNode( QQuickItem* parent = nullptr );
explicit FaceNode(QQuickItem* parent = nullptr);
virtual ~FaceNode() override = default;
private:
Q_DISABLE_COPY( FaceNode )
Q_DISABLE_COPY(FaceNode)
public:
Q_PROPERTY( QUrl image READ getImage WRITE setImage NOTIFY imageChanged )
const QUrl& getImage() const noexcept { return _image; }
void setImage(QUrl image) noexcept;
Q_PROPERTY(QUrl image READ getImage WRITE setImage NOTIFY imageChanged)
const QUrl& getImage() const noexcept { return _image; }
void setImage(QUrl image) noexcept;
private:
QUrl _image;
QUrl _image;
signals:
void imageChanged();
void imageChanged();

/*! \name Node Static Factories *///---------------------------------------
//@{
Expand All @@ -71,11 +71,13 @@ class FaceGraph : public qan::Graph
{
Q_OBJECT
public:
explicit FaceGraph( QQuickItem* parent = nullptr ) noexcept : qan::Graph(parent) { }
explicit FaceGraph(QQuickItem* parent = nullptr) noexcept :
qan::Graph(parent) { }

public:
Q_INVOKABLE qan::Node* insertFaceNode() {
return insertNode<FaceNode>(nullptr);
auto node = insertNode<FaceNode>(nullptr);
return node;
}
};

Expand Down
Loading

0 comments on commit 9211bda

Please sign in to comment.