Skip to content

Commit d45f2fa

Browse files
committed
#2074 note-relations: allow circular note relations
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 340df8a commit d45f2fa

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# QOwnNotes Changelog
22

3+
## 25.3.2
4+
- In the **note relation panel** notes can now have **circular relations**
5+
between each other, no new note items will be drawn for notes that are already
6+
in the scene (for [#2074](https://github.com/pbek/QOwnNotes/issues/2074))
7+
38
## 25.3.1
49
- In the **note relation panel** the gathering of note relations will now be done
510
in a **different thread** (for [#2074](https://github.com/pbek/QOwnNotes/issues/2074))

Diff for: src/widgets/noterelationscene.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ void NoteRelationScene::drawForNote(const Note &note) {
169169
// Allow drawing again and clear the scene
170170
setAllowDrawing();
171171
m_connections.clear();
172+
m_noteItems.clear();
172173
clear();
173174

174175
// This runs the gathering of note relations in a different thread
@@ -183,6 +184,8 @@ void NoteRelationScene::drawForNote(const Note &note) {
183184
QSqlDatabase db = DatabaseService::createSharedMemoryDatabase(connectionName);
184185

185186
auto rootNoteItem = createNoteItem(QPointF(100, 100), note);
187+
m_noteItems[note.getId()] = rootNoteItem;
188+
186189
createLinkedNoteItems(noteList, connectionName, note, rootNoteItem);
187190

188191
// Update all connections
@@ -243,9 +246,16 @@ void NoteRelationScene::createLinkedNoteItems(const QVector<Note> &noteList,
243246
// Calculate position in a circle around the root note item
244247
QPointF notePos = calculateRadialPosition(rootCenter, index, linkedNotes.size(), radius);
245248
const Note &linkedNote = it.key();
249+
int linkedNoteId = linkedNote.getId();
250+
251+
// Check if note item already exists
252+
NoteItem *linkedNoteItem = m_noteItems[linkedNoteId];
246253

247-
// Create note item at calculated position
248-
NoteItem *linkedNoteItem = createNoteItem(notePos, linkedNote, level);
254+
if (linkedNoteItem == nullptr) {
255+
// Create note item at calculated position
256+
linkedNoteItem = createNoteItem(notePos, linkedNote, level);
257+
m_noteItems[linkedNoteId] = linkedNoteItem;
258+
}
249259

250260
// Create connection between root and this note
251261
createConnection(rootNoteItem, linkedNoteItem);

Diff for: src/widgets/noterelationscene.h

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class NoteRelationScene : public QGraphicsScene {
7575
QGraphicsLineItem *m_tempLine;
7676
NoteItem *m_startItem;
7777
std::vector<ConnectionLine *> m_connections;
78+
QHash<int, NoteItem *> m_noteItems;
7879
QFuture<void> m_drawFuture;
7980
static QPointF calculateRadialPosition(QPointF center, int index, int total, qreal radius);
8081
void createLinkedNoteItems(const QVector<Note> &noteList, const QString &connectionName,

0 commit comments

Comments
 (0)