summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraph_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/graphicsview/qgraph_p.h')
-rw-r--r--src/widgets/graphicsview/qgraph_p.h98
1 files changed, 50 insertions, 48 deletions
diff --git a/src/widgets/graphicsview/qgraph_p.h b/src/widgets/graphicsview/qgraph_p.h
index c63c2c6f8e..14f7122d5c 100644
--- a/src/widgets/graphicsview/qgraph_p.h
+++ b/src/widgets/graphicsview/qgraph_p.h
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -50,6 +56,8 @@
#include <QtCore/QString>
#include <QtCore/QDebug>
+#include <functional> // for std::less
+
#include <float.h>
QT_BEGIN_NAMESPACE
@@ -67,9 +75,7 @@ public:
row = g->m_graph.constBegin();
//test if the graph is empty
if (row != g->m_graph.constEnd())
- {
- column = (*row)->constBegin();
- }
+ column = row->cbegin();
} else {
row = g->m_graph.constEnd();
}
@@ -95,16 +101,15 @@ public:
return row != o.row || column != o.column;
}
}
- inline const_iterator& operator=(const const_iterator &o) const { row = o.row; column = o.column; return *this;}
// prefix
const_iterator &operator++() {
if (row != g->m_graph.constEnd()) {
++column;
- if (column == (*row)->constEnd()) {
+ if (column == row->cend()) {
++row;
if (row != g->m_graph.constEnd()) {
- column = (*row)->constBegin();
+ column = row->cbegin();
}
}
}
@@ -113,7 +118,7 @@ public:
private:
const Graph *g;
- typename QHash<Vertex *, QHash<Vertex *, EdgeData *> * >::const_iterator row;
+ typename QHash<Vertex *, QHash<Vertex *, EdgeData *> >::const_iterator row;
typename QHash<Vertex *, EdgeData *>::const_iterator column;
};
@@ -133,8 +138,13 @@ public:
*
*/
EdgeData *edgeData(Vertex* first, Vertex* second) {
- QHash<Vertex *, EdgeData *> *row = m_graph.value(first);
- return row ? row->value(second) : 0;
+ const auto it = m_graph.constFind(first);
+ if (it == m_graph.cend())
+ return nullptr;
+ const auto jt = it->constFind(second);
+ if (jt == it->cend())
+ return nullptr;
+ return *jt;
}
void createEdge(Vertex *first, Vertex *second, EdgeData *data)
@@ -186,11 +196,11 @@ public:
QList<Vertex *> adjacentVertices(Vertex *vertex) const
{
- QHash<Vertex *, EdgeData *> *row = m_graph.value(vertex);
- QList<Vertex *> l;
- if (row)
- l = row->keys();
- return l;
+ const auto it = m_graph.constFind(vertex);
+ if (it == m_graph.cend())
+ return QList<Vertex *>();
+ else
+ return it->keys();
}
QSet<Vertex*> vertices() const {
@@ -201,15 +211,14 @@ public:
return setOfVertices;
}
- QList<QPair<Vertex*, Vertex*> > connections() const {
- QList<QPair<Vertex*, Vertex*> > conns;
+ QVector<QPair<Vertex*, Vertex*> > connections() const {
+ QVector<QPair<Vertex*, Vertex*> > conns;
for (const_iterator it = constBegin(); it != constEnd(); ++it) {
Vertex *from = it.from();
Vertex *to = it.to();
// do not return (from,to) *and* (to,from)
- if (from < to) {
+ if (std::less<Vertex*>()(from, to))
conns.append(qMakePair(from, to));
- }
}
return conns;
}
@@ -222,9 +231,8 @@ public:
QSet<Vertex *> setOfVertices = vertices();
for (typename QSet<Vertex*>::const_iterator it = setOfVertices.begin(); it != setOfVertices.end(); ++it) {
Vertex *v = *it;
- QList<Vertex*> adjacents = adjacentVertices(v);
- for (int i = 0; i < adjacents.count(); ++i) {
- Vertex *v1 = adjacents.at(i);
+ const QList<Vertex*> adjacents = adjacentVertices(v);
+ for (auto *v1 : adjacents) {
EdgeData *data = edgeData(v, v1);
bool forward = data->from == v;
if (forward) {
@@ -248,29 +256,23 @@ public:
protected:
void createDirectedEdge(Vertex *from, Vertex *to, EdgeData *data)
{
- QHash<Vertex *, EdgeData *> *adjacentToFirst = m_graph.value(from);
- if (!adjacentToFirst) {
- adjacentToFirst = new QHash<Vertex *, EdgeData *>();
- m_graph.insert(from, adjacentToFirst);
- }
- adjacentToFirst->insert(to, data);
+ m_graph[from][to] = data;
}
void removeDirectedEdge(Vertex *from, Vertex *to)
{
- QHash<Vertex *, EdgeData *> *adjacentToFirst = m_graph.value(from);
- Q_ASSERT(adjacentToFirst);
+ const auto it = m_graph.find(from);
+ Q_ASSERT(it != m_graph.end());
- adjacentToFirst->remove(to);
- if (adjacentToFirst->isEmpty()) {
+ it->remove(to);
+ if (it->isEmpty()) {
//nobody point to 'from' so we can remove it from the graph
- m_graph.remove(from);
- delete adjacentToFirst;
+ m_graph.erase(it);
}
}
private:
- QHash<Vertex *, QHash<Vertex *, EdgeData *> *> m_graph;
+ QHash<Vertex *, QHash<Vertex *, EdgeData *> > m_graph;
};
QT_END_NAMESPACE