8 #include <QIntValidator>
11 #include <QWidgetAction>
13 #include "gui/menus/menuaction.h"
33 using namespace swift::gui::menus;
47 return this->container().latestObject();
53 return this->container().oldestObject();
59 const QSet<KeyType> set({ key });
60 return this->selectDbKeys(set) > 0;
66 if (keys.isEmpty()) {
return 0; }
67 this->clearSelection();
73 if (!obj.hasValidDbKey()) {
continue; }
74 if (keys.contains(obj.getDbKey())) { rows.insert(r); }
76 return this->selectRows(rows);
82 if (!this->hasSelection()) {
return QSet<KeyType>(); }
84 return selected.toDbKeySet();
90 if (keys.isEmpty()) {
return 0; }
91 if (this->isEmpty()) {
return 0; }
94 int delta = newObjects.removeObjectsWithKeys(keys);
95 if (delta > 0) { this->updateContainerMaybeAsync(newObjects); }
102 if (container.isEmpty()) {
return 0; }
104 int c = copy.replaceOrAddObjectsByKey(container);
105 if (c == 0) {
return 0; }
106 this->updateContainerMaybeAsync(copy);
113 if (selectedObjects.isEmpty()) {
return; }
114 this->selectDbKeys(selectedObjects.toDbKeySet());
136 const int maxOrder = this->rowCount() - 1;
138 if (m_menuActions.isEmpty())
141 m_menuActions = QList<QAction *>({
nullptr,
nullptr,
nullptr,
nullptr });
143 if (!m_menuActions[0])
145 m_frame =
new QFrame(
this);
146 QHBoxLayout *layout =
new QHBoxLayout(m_frame);
147 layout->setContentsMargins(2, 2, 2, 2);
148 m_frame->setLayout(layout);
149 m_leOrder =
new QLineEdit(m_frame);
150 QLabel *icon =
new QLabel(m_frame);
152 layout->addWidget(icon);
153 QLabel *label =
new QLabel(m_frame);
154 label->setText(
"Order:");
155 layout->addWidget(label);
156 layout->addWidget(m_leOrder);
157 m_validator =
new QIntValidator(0, maxOrder,
this);
158 m_leOrder->setValidator(m_validator);
159 QWidgetAction *orderAction =
new QWidgetAction(
this);
160 orderAction->setDefaultWidget(m_frame);
161 QObject::connect(m_leOrder, &QLineEdit::returnPressed,
this,
163 m_menuActions[0] = orderAction;
167 m_validator->setRange(0, maxOrder);
168 m_leOrder->setPlaceholderText(
"New order 0-" + QString::number(maxOrder));
170 menuActions.
addAction(m_menuActions[0], CMenuAction::pathViewOrder());
172 menuActions.
addAction(CIcons::arrowMediumNorth16(),
"To top", CMenuAction::pathViewOrder(),
175 menuActions.
addAction(CIcons::arrowMediumSouth16(),
"To bottom", CMenuAction::pathViewOrder(),
178 menuActions.
addAction(CIcons::arrowMediumWest16(),
"Freeze current order", CMenuAction::pathViewOrder(),
187 if (selectedObjects.isEmpty()) {
return; }
188 this->selectDbKeys(selectedObjects.toDbKeySet());
194 if (this->isEmpty()) {
return; }
196 if (objs.isEmpty()) {
return; }
197 this->m_model->moveItems(objs, order);
203 this->moveSelectedItems(0);
209 int c = this->model()->rowCount() - 1;
210 if (c >= 0) { this->moveSelectedItems(c); }
216 if (this->isEmpty()) {
return; }
217 QLineEdit *le = qobject_cast<QLineEdit *>(QObject::sender());
218 if (!le || le->text().isEmpty()) {
return; }
219 const int order = le->text().toInt();
220 this->moveSelectedItems(order);
227 objects.freezeOrder();
228 this->updateContainerAsync(objects,
false);
Base class for views with DB objects also orderable (based on swift::misc::IOrderableList )
virtual void customMenu(swift::gui::menus::CMenuActions &menuActions)
Method creating the menu.
virtual void selectObjects(const ContainerType &selectedObjects)
Select by DB keys.
COrderableViewWithDbObjects(QWidget *parent=nullptr)
Constructor.
void orderToLineEdit()
Order to line edit.
void orderToTop()
Order to top.
void freezeCurrentOrder()
Current order set as order.
void moveSelectedItems(int order)
Move selected items.
void orderToBottom()
Order to bottom.
typename T::ObjectType ObjectType
Model container element type.
typename T::ContainerType ContainerType
Model container type.
virtual void customMenu(menus::CMenuActions &menuActions)
Method creating the menu.
bool m_enabledLoadIndicator
loading indicator enabled/disabled
@ MenuOrderable
items can be ordered (if container is swift::misc::IOrderableList
Base class for views with DB objects.
int removeDbKeys(const QSet< KeyType > &keys)
Remove keys.
typename T::ObjectType ObjectType
Model container element type.
typename T::KeyType KeyType
Model DB key type.
ObjectType oldestObject() const
Get oldets object.
int replaceOrAddObjectsByKey(const ContainerType &container)
Update or insert data (based on DB key)
virtual void selectObjects(const ContainerType &selectedObjects)
Select by DB keys.
bool selectDbKey(const KeyType &key)
Select given DB key.
int selectDbKeys(const QSet< KeyType > &keys)
Select given DB keys.
ObjectType latestObject() const
Get latest object.
QSet< KeyType > selectedDbKeys() const
Get selected DB keys.
virtual void customMenu(swift::gui::menus::CMenuActions &menuActions)
Method creating the menu.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.