swift
Loading...
Searching...
No Matches
viewcallsignobjects.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QAction>
7#include <QHBoxLayout>
8#include <QIntValidator>
9#include <QLabel>
10#include <QLineEdit>
11#include <QWidgetAction>
12
16#include "misc/icons.h"
17
18using namespace swift::misc;
19using namespace swift::misc::aviation;
20using namespace swift::gui;
21using namespace swift::gui::models;
22
23namespace swift::gui::views
24{
25 template <class T>
30
31 template <class T>
33 {
34 const CCallsignSet cs({ callsign });
35 this->selectCallsigns(cs);
36 }
37
38 template <class T>
40 {
41 if (callsigns.isEmpty())
42 {
43 return;
44 }
45 this->clearSelection();
46 int r = -1;
47 QSet<int> rows;
49 {
50 r++;
51 if (callsigns.contains(obj.getCallsign()))
52 {
53 rows.insert(r);
54 }
55 }
56 this->selectRows(rows);
57 }
59 template <class T>
61 {
62 if (!this->hasSelection())
63 {
64 return {};
65 }
66 const ContainerType selected(this->selectedObjects());
67 return selected.getCallsigns();
68 }
69
70 template <class T>
72 {
73 if (callsign.isEmpty())
74 {
75 return 0;
76 }
77 const CCallsignSet set({ callsign });
78 return this->removeCallsigns(set);
79 }
80
81 template <class T>
83 {
84 if (callsigns.isEmpty())
85 {
86 return 0;
87 }
88 if (this->isEmpty())
89 {
90 return 0;
91 }
92
93 ContainerType newObjects(this->container());
94 int delta = newObjects.removeByCallsigns(callsigns);
95 if (delta > 0)
96 {
97 this->updateContainerMaybeAsync(newObjects);
98 }
99 return delta;
100 }
101
102 template <class T>
104 {
105 if (container.isEmpty())
106 {
107 return 0;
108 }
109 ContainerType copy(this->container());
110 const int c = copy.replaceOrAddObjectsByCallsign(container);
111 if (c == 0)
112 {
113 return 0;
114 }
116 return c;
117 }
118
119 template <class T>
121 {
123 const int c = copy.replaceOrAddObjectByCallsign(object);
124 if (c == 0)
125 {
126 return 0;
127 }
129 return c;
130 }
131
132 template <class T>
134 {
135 if (!selectedObjects.isEmpty())
136 {
137 this->selectCallsigns(selectedObjects.getCallsigns());
138 }
139 }
140
144
145} // namespace swift::gui::views
bool isEmpty() const
Empty?
Definition viewbase.cpp:481
void updateContainerMaybeAsync(const ContainerType &container, bool sort=true, bool resize=true)
Based on size call sync / async update.
Definition viewbase.cpp:120
ContainerType selectedObjects() const
Selected objects.
Definition viewbase.cpp:267
CViewBase(QWidget *parent, ModelClass *model=nullptr)
Constructor.
Definition viewbase.cpp:31
const ContainerType & container() const
Access to container.
Definition viewbase.cpp:221
const ContainerType & containerOrFilteredContainer(bool *filtered=nullptr) const
Full container or cached filtered container as approproiate.
Definition viewbase.cpp:260
void copy()
Clipboard cut/copy/paste.
Definition viewbase.cpp:922
bool hasSelection() const
Selection (selected rows).
Base class for views with DB objects.
void selectCallsigns(const swift::misc::aviation::CCallsignSet &callsigns)
Select given callsigns.
typename swift::gui::models::CAtcStationListModel::ObjectType ObjectType
typename T::ContainerType ContainerType
Model container type.
int removeCallsign(const swift::misc::aviation::CCallsign &callsign)
Remove callsign.
int replaceOrAddObjectByCallsign(const ObjectType &object)
Update or insert data (based on callsign).
int removeCallsigns(const swift::misc::aviation::CCallsignSet &callsigns)
Remove callsigns.
CViewWithCallsignObjects(QWidget *parent=nullptr)
Constructor.
int replaceOrAddObjectsByCallsign(const ContainerType &container)
Update or insert data (based on callsign).
swift::misc::aviation::CCallsignSet selectedCallsigns() const
Get selected callsigns.
void selectObjects(const ContainerType &selectedObjects)
Reselect by callsigns.
void selectCallsign(const swift::misc::aviation::CCallsign &callsign)
Select callsign.
bool isEmpty() const
Synonym for empty.
Definition collection.h:197
bool contains(const T &object) const
Return true if there is an element equal to given object. Uses the most efficient implementation avai...
Definition range.h:109
Value object encapsulating information of a callsign.
Definition callsign.h:30
bool isEmpty() const
Is empty?
Definition callsign.h:63
Value object for a set of callsigns.
Definition callsignset.h:26
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
GUI related classes.
Free functions in swift::misc.
QObject * parent() const const
QSet< T >::iterator insert(QSet< T >::const_iterator it, const T &value)