swift
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 
18 using namespace swift::misc;
19 using namespace swift::misc::aviation;
20 using namespace swift::gui;
21 using namespace swift::gui::models;
22 
23 namespace swift::gui::views
24 {
25  template <class T>
27  {
28  // void
29  }
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()) { return; }
42  this->clearSelection();
43  int r = -1;
44  QSet<int> rows;
46  {
47  r++;
48  if (callsigns.contains(obj.getCallsign())) { rows.insert(r); }
49  }
50  this->selectRows(rows);
51  }
52 
53  template <class T>
55  {
56  if (!this->hasSelection()) { return CCallsignSet(); }
57  const ContainerType selected(this->selectedObjects());
58  return selected.getCallsigns();
59  }
60 
61  template <class T>
63  {
64  if (callsign.isEmpty()) { return 0; }
65  const CCallsignSet set({ callsign });
66  return this->removeCallsigns(set);
67  }
68 
69  template <class T>
71  {
72  if (callsigns.isEmpty()) { return 0; }
73  if (this->isEmpty()) { return 0; }
74 
75  ContainerType newObjects(this->container());
76  int delta = newObjects.removeByCallsigns(callsigns);
77  if (delta > 0) { this->updateContainerMaybeAsync(newObjects); }
78  return delta;
79  }
80 
81  template <class T>
83  {
84  if (container.isEmpty()) { return 0; }
85  ContainerType copy(this->container());
86  const int c = copy.replaceOrAddObjectsByCallsign(container);
87  if (c == 0) { return 0; }
88  this->updateContainerMaybeAsync(copy);
89  return c;
90  }
91 
92  template <class T>
94  {
95  ContainerType copy(this->container());
96  const int c = copy.replaceOrAddObjectByCallsign(object);
97  if (c == 0) { return 0; }
98  this->updateContainerMaybeAsync(copy);
99  return c;
100  }
101 
102  template <class T>
104  {
105  if (!selectedObjects.isEmpty()) { this->selectCallsigns(selectedObjects.getCallsigns()); }
106  }
107 
111 
112 } // namespace swift::gui::views
Base class for views.
Definition: viewbase.h:648
typename T::ObjectType ObjectType
Model container element type.
Definition: viewbase.h:660
typename T::ContainerType ContainerType
Model container type.
Definition: viewbase.h:657
Base class for views with DB objects.
void selectCallsigns(const swift::misc::aviation::CCallsignSet &callsigns)
Select given callsigns.
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.
int replaceOrAddObjectsByCallsign(const ContainerType &container)
Update or insert data (based on callsign)
swift::misc::aviation::CCallsignSet selectedCallsigns() const
Get selected callsigns.
virtual 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:191
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.