swift
Loading...
Searching...
No Matches
viewbasenontemplate.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#include <algorithm>
5
6#include <QAction>
7#include <QApplication>
8#include <QMetaMethod>
9#include <QShortcut>
10
11#include "config/buildconfig.h"
16#include "gui/guiapplication.h"
17#include "gui/guiutility.h"
18#include "gui/loadindicator.h"
19#include "gui/menus/fontmenus.h"
20#include "gui/menus/menudelegate.h"
21#include "gui/shortcut.h"
22#include "gui/views/viewbase.h"
23#include "misc/logmessage.h"
24
25using namespace swift::config;
26using namespace swift::misc;
27using namespace swift::gui;
28using namespace swift::gui::menus;
29using namespace swift::gui::models;
30using namespace swift::gui::filters;
31using namespace swift::gui::settings;
32using namespace swift::gui::components;
33
34namespace swift::gui::views
35{
37 {
39 connect(this, &QWidget::customContextMenuRequested, this, &CViewBaseNonTemplate::customMenuRequested);
43
44 // setting resize mode rowsResizeModeToContent() causes extremly slow views
45 // default, see: m_rowResizeMode
46
47 // scroll modes
50 this->setWordWrap(false);
52
53 // shortcuts
54 auto *filter = new QShortcut(CShortcut::keyDisplayFilter(), this);
56 Q_ASSERT_X(s, Q_FUNC_INFO, "Shortcut");
57 filter->setObjectName("Filter shortcut for " + this->objectName());
58 filter->setContext(Qt::WidgetShortcut);
59
62 Q_ASSERT_X(s, Q_FUNC_INFO, "Shortcut");
63 clearSelection->setObjectName("Clear selection shortcut for " + this->objectName());
65
66 auto *saveJson = new QShortcut(CShortcut::keySaveViews(), this);
68 Q_ASSERT_X(s, Q_FUNC_INFO, "Shortcut");
69 saveJson->setObjectName("Save JSON for " + this->objectName());
70 saveJson->setContext(Qt::WidgetShortcut);
71
72 auto *deleteRow = new QShortcut(CShortcut::keyDelete(), this);
73 s = connect(deleteRow, &QShortcut::activated, this, &CViewBaseNonTemplate::removeSelectedRowsChecked);
74 Q_ASSERT_X(s, Q_FUNC_INFO, "Shortcut");
75 deleteRow->setObjectName("Remove selected rows for " + this->objectName());
76 deleteRow->setContext(Qt::WidgetShortcut);
77
78 auto *copy = new QShortcut(CShortcut::keyCopy(), this);
80 Q_ASSERT_X(s, Q_FUNC_INFO, "Shortcut");
81 copy->setObjectName("Copy selection shortcut for " + this->objectName());
82 copy->setContext(Qt::WidgetShortcut);
83
84 auto *resize = new QShortcut(CShortcut::keyResizeView(), this);
86 Q_ASSERT_X(s, Q_FUNC_INFO, "Shortcut");
87 resize->setObjectName("Resize view shortcut for " + this->objectName());
88 resize->setContext(Qt::WidgetShortcut);
89 }
90
92
94 {
95 // further init could go here
96 const bool c = CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea(parentDockableWidget);
97 return c;
98 }
99
101
102 void CViewBaseNonTemplate::setFilterWidgetImpl(QWidget *filterWidget)
103 {
104 if (filterWidget == m_filterWidget)
105 {
106 return;
107 }
108
109 // dialog or filter widget
110 if (m_filterWidget)
111 {
114 if (m_filterWidget->parent() == this)
115 {
117 }
118 m_filterWidget = nullptr;
119 }
120
121 if (filterWidget)
122 {
124 m_filterWidget = filterWidget;
125 }
126 }
127
129 {
130 if (filterDialog == m_filterWidget)
131 {
132 return;
133 }
134 this->setFilterWidgetImpl(filterDialog);
135 if (filterDialog)
136 {
137 const bool s =
139 Q_ASSERT_X(s, Q_FUNC_INFO, "filter dialog connect");
140 Q_UNUSED(s);
141 }
142 }
143
145 {
146 if (filterWidget == m_filterWidget)
147 {
148 return;
149 }
150 this->setFilterWidgetImpl(filterWidget);
151 if (filterWidget)
152 {
153 bool s = connect(filterWidget, &CFilterWidget::changeFilter, this,
155 Q_ASSERT_X(s, Q_FUNC_INFO, "filter connect changeFilter");
158 Q_ASSERT_X(s, Q_FUNC_INFO, "filter connect modelDataChanged");
159 Q_UNUSED(s);
160 }
161 }
162
164
169
183
185
187 {
188 return this->loadJson(directory);
189 }
190
192 {
193 return this->saveJson(selectedOnly, directory);
194 }
195
200
202 {
203 if (menu && nestPreviousMenu)
204 {
205 // new menu with nesting
207 m_menu = menu;
208 }
209 else if (!menu && nestPreviousMenu)
210 {
211 // nested new menu
212 m_menu = m_menu->getNestedDelegate();
213 }
214 else
215 {
216 // no nesting
217 m_menu = menu;
218 }
219 return menu;
220 }
221
223 {
224 if (m_menuFlagActions.contains(menu))
225 {
226 return m_menuFlagActions.value(menu);
227 }
228
229 CMenuActions ma;
230 switch (menu)
231 {
232 case MenuRefresh:
233 {
235 if (!this->isSignalConnected(requestSignal)) break;
238 break;
239 }
240 case MenuBackend:
241 {
242 static const QMetaMethod requestSignal =
244 if (!this->isSignalConnected(requestSignal)) break;
245 ma.addAction(CIcons::refresh16(), "Reload from backend", CMenuAction::pathViewUpdates(),
247 break;
248 }
250 {
251 QAction *a =
252 ma.addAction(CIcons::appMappings16(), "Automatically display (when loaded)",
253 CMenuAction::pathViewUpdates(), { this, &CViewBaseNonTemplate::toggleAutoDisplay });
254 a->setCheckable(true);
256 break;
257 }
259 {
260 ma.addAction(CIcons::delete16(), "Remove selected rows", CMenuAction::pathViewAddRemove(),
261 { this, &CViewBaseNonTemplate::removeSelectedRowsChecked }, CShortcut::keyDelete());
262 break;
263 }
264 case MenuClear:
265 {
267 { this, &CViewBaseNonTemplate::clear });
268 break;
269 }
270 case MenuFilter:
271 {
272 if (m_filterWidget)
273 {
274 const bool dialog = qobject_cast<QDialog *>(m_filterWidget);
275 if (dialog)
282 }
283 break;
284 }
286 {
287 ma.addAction(CIcons::tableRelationship16(), "Materialize filtered data", CMenuAction::pathViewFilter(),
289 break;
290 }
291 case MenuLoad:
292 {
293 ma.addAction(CIcons::disk16(), "Load from file ", CMenuAction::pathViewLoadSave(),
295 break;
296 }
297 case MenuSave:
298 {
303 if (this->hasSelection())
304 {
305 ma.addAction(CIcons::disk16(), "Save selected data in file", CMenuAction::pathViewLoadSave(),
307 break;
308 }
309 break;
310 }
311 case MenuCut:
312 {
313 if (!QApplication::clipboard()) break;
316 break;
317 }
318 case MenuPaste:
319 {
320 if (!QApplication::clipboard()) break;
323 break;
324 }
325 case MenuCopy:
326 {
327 if (!QApplication::clipboard()) break;
330 break;
331 }
332 default: break;
333 }
334 m_menuFlagActions.insert(menu, ma);
335 return ma;
336 }
337
339 {
340 if (!this->allowsMultipleSelectedRows())
341 {
342 return;
343 }
344 const CGeneralGuiSettings settings = m_guiSettings.getThreadLocal();
345 m_originalSelectionMode = settings.getPreferredSelection();
347 {
348 this->setSelectionMode(settings.getPreferredSelection());
349 }
350 }
351
353 {
354 if (selectedFileOrDir.isEmpty())
355 {
356 return;
357 }
358 const QString dir = CDirectories::fileNameToDirectory(selectedFileOrDir);
359 QDir d(dir);
360 if (!d.exists())
361 {
362 return;
363 }
364
365 // existing dir
366 CDirectories directories = m_dirSettings.get();
368 const CStatusMessage msg = m_dirSettings.setAndSave(directories);
370 }
371
373 {
374 const CDirectories directories = m_dirSettings.get();
375 return directories.propertyByIndex(m_dirSettingsIndex).toString();
376 }
377
386
388 {
389 // delegate?
390 if (m_menu)
391 {
392 m_menu->customMenu(menuActions);
393 }
394
395 // standard view menus
396 if (m_menus.testFlag(MenuRefresh))
397 {
398 menuActions.addActions(this->initMenuActions(MenuRefresh));
399 }
400 if (m_menus.testFlag(MenuBackend))
401 {
402 menuActions.addActions(this->initMenuActions(MenuBackend));
403 }
404
405 if (m_menus.testFlag(MenuClear))
406 {
407 menuActions.addActions(this->initMenuActions(MenuClear));
408 }
409 if (m_menus.testFlag(MenuDisplayAutomatically))
410 {
411 // here I expect only one action
414 }
415 if (m_menus.testFlag(MenuRemoveSelectedRows))
416 {
417 if (this->hasSelection())
418 {
420 }
421 }
422
423 if (m_menus.testFlag(MenuCopy))
424 {
425 menuActions.addActions(this->initMenuActions(MenuCopy));
426 }
427 if (m_menus.testFlag(MenuCut))
428 {
429 menuActions.addActions(this->initMenuActions(MenuCut));
430 }
431 if (m_menus.testFlag(MenuPaste))
432 {
433 menuActions.addActions(this->initMenuActions(MenuPaste));
434 }
435 if (m_menus.testFlag(MenuFont) && m_fontMenu)
436 {
437 menuActions.addActions(m_fontMenu->getActions(), CMenuAction::pathFont());
438 }
439
440 if (m_menus.testFlag(MenuFilter) && m_filterWidget)
441 {
442 menuActions.addActions(this->initMenuActions(MenuFilter));
443 if (m_menus.testFlag(MenuMaterializeFilter))
444 {
446 }
447 }
448
449 // selection menus, not in menu action list because it depends on current selection
450 const SelectionMode sm = this->selectionMode();
451 if (sm == MultiSelection || sm == ExtendedSelection)
452 {
453 menuActions.addAction("Select all", CMenuAction::pathViewSelection(), nullptr,
455 }
456 if (sm != NoSelection)
457 {
461 }
464 {
465 if (sm != MultiSelection)
466 {
467 menuActions.addAction("Switch to multi selection", CMenuAction::pathViewSelection(), nullptr,
469 }
470
471 if (sm != ExtendedSelection)
472 {
473 menuActions.addAction("Switch to extended selection", CMenuAction::pathViewSelection(), nullptr,
475 }
476
477 if (sm != SingleSelection)
478 {
479 menuActions.addAction("Switch to single selection", CMenuAction::pathViewSelection(), nullptr,
481 }
482 }
483
484 // load/save
485 if (m_menus.testFlag(MenuLoad))
486 {
487 menuActions.addActions(this->initMenuActions(MenuLoad));
488 }
489 if (m_menus.testFlag(MenuSave) && !isEmpty())
490 {
491 menuActions.addActions(this->initMenuActions(MenuSave));
492 }
493
494 // resizing
495 menuActions.addAction(
498
499 // resize to content might decrease performance,
500 // so I only allow changing to "content resizing" if size matches
501 // const bool enabled = !this->reachedResizeThreshold();
502 const bool enabled = true;
503 const bool autoResize = (m_resizeMode == ResizingAuto);
504
505 // when not set to auto, then lets set how we want to resize rows
506 // for auto this is too slow
507 // const bool ww = this->wordWrap();
508 QAction *resizeRowsAction =
509 menuActions.addAction(CIcons::resizeVertical16(), "Resize rows to content", CMenuAction::pathViewResize(),
511 resizeRowsAction->setEnabled(
512 true); // as changing from word wraap to none word wrap can leave to high columns, we always enable this
513
522
523 // export actions, display in text edit
525 {
526 menuActions.addAction(CIcons::tableSheet16(), "Display as JSON", CMenuAction::pathViewLoadSave(),
528 if (this->hasSelection())
529 {
530 menuActions.addAction(CIcons::tableSheet16(), "Display selected as JSON",
533 ;
534 }
535 }
536
537 QAction *actionInteractiveResize =
538 menuActions.addAction(CIcons::viewTile(), "Resize (auto)", CMenuAction::pathViewResize(), nullptr);
539 actionInteractiveResize->setObjectName(this->objectName().append("ActionResizing"));
540 actionInteractiveResize->setCheckable(true);
541 actionInteractiveResize->setChecked(autoResize);
542 actionInteractiveResize->setEnabled(enabled);
543 connect(actionInteractiveResize, &QAction::toggled, this, &CViewBaseNonTemplate::toggleResizeMode);
544
545 QAction *actionWordWrap = menuActions.addAction(CIcons::viewMultiColumn(), "Word wrap (multiline)",
546 CMenuAction::pathViewResize(), nullptr);
547 actionWordWrap->setObjectName(this->objectName().append("ActionResizing"));
548 actionWordWrap->setCheckable(true);
549 actionWordWrap->setChecked(this->wordWrap());
550 actionWordWrap->setEnabled(true);
551 connect(actionWordWrap, &QAction::toggled, this, &CViewBaseNonTemplate::toggleWordWrap);
552 }
553
555 {
556 if (this->isShowingLoadIndicator())
557 {
558 // re-center
559 this->centerLoadIndicator();
560 }
562 }
563
565 {
566 const QFontMetrics m(this->getHorizontalHeaderFont());
567 const int h = m.height();
568 return h;
569 }
570
572
574 {
575 // make sure this is ordered by row and wee keep the same order as in unselectedRows
576 // if we'd know for sure the indexes are always sorted we can remove the sorting here
577 // Qt docu selectedIndexes: Returns a list of all selected model item indexes. The list contains no duplicates,
578 // and is not sorted.
579 QModelIndexList indexes = this->selectionModel()->selectedRows();
580 std::sort(indexes.begin(), indexes.end());
581 return indexes;
582 }
583
585 {
586 const QModelIndexList selected = this->selectedRows();
587 QModelIndexList unselected;
588 const int rows = this->rowCount();
589 for (int r = 0; r < rows; r++)
590 {
591 const QModelIndex mi = this->model()->index(r, 0);
592 if (selected.contains(mi))
593 {
594 continue;
595 }
596 unselected.push_back(mi);
597 }
598 return unselected;
599 }
600
602 {
603 if (!this->selectionModel())
604 {
605 return 0;
606 }
607
608 // multiple times faster than multiple this->selectRow()
609 this->clearSelection();
610 QItemSelection selectedItems;
611 const int columns = this->model()->columnCount() - 1;
612 for (int r : rows)
613 {
614 selectedItems.select(this->model()->index(r, 0), this->model()->index(r, columns));
615 }
616 this->selectionModel()->select(selectedItems, QItemSelectionModel::Select);
617 return selectedItems.size();
618 }
619
621 {
622 if (!this->hasSelection())
623 {
624 return 0;
625 }
626 return this->selectedRows().count();
627 }
628
630
632
634
639
645
647 {
650 const int fh = qRound(1.5 * this->getHorizontalHeaderFontHeight());
651 this->verticalHeader()->setDefaultSectionSize(fh); // for height
652 this->verticalHeader()->setMinimumSectionSize(fh); // for height
653
654 switch (m_rowResizeMode)
655 {
656 case Interactive: this->rowsResizeModeToInteractive(); break;
657 case Content: this->rowsResizeModeToContent(); break;
658 default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong resize mode"); break;
659 }
660
661 // call this deferred, otherwise the values are overridden with any values
662 // from the UI builder
663 const QPointer<CViewBaseNonTemplate> guard(this);
664 QTimer::singleShot(500, this, [=, this]() {
665 if (!guard)
666 {
667 return;
668 }
670 });
671 }
672
674 {
675 // some logic to find a useful default name
676 if (load)
677 {
680 }
681
682 // Save file path
683 const QString dir = m_dirSettings.get().propertyByIndex(m_dirSettingsIndex).toString();
685 if (name.isEmpty())
686 {
687 // create a name
688 if (this->getDockWidgetInfoArea())
689 {
690 name = this->getDockWidgetInfoArea()->windowTitle();
691 }
692 else
693 {
694 name = this->metaObject()->className();
695 }
696 }
698 {
699 name += CFileUtils::jsonAppendix();
700 }
701 return CFileUtils::appendFilePaths(dir, name);
702 }
703
704 void CViewBaseNonTemplate::menuRemoveItems(Menu menusToRemove) { m_menus &= (~menusToRemove); }
705
707 {
708 m_menus |= menusToAdd;
709 if (menusToAdd.testFlag(MenuRemoveSelectedRows))
710 {
712 }
713 }
714
716 {
717 if (!m_menus.testFlag(MenuFilter))
718 {
719 return;
720 }
721 if (!m_filterWidget)
722 {
723 return;
724 }
725 m_filterWidget->show();
726 }
727
729 {
730 if (!m_menus.testFlag(MenuLoad))
731 {
732 return;
733 }
734 const CStatusMessage m = this->loadJson();
735 if (!m.isEmpty())
736 {
738 }
739 }
740
742 {
743 if (this->isEmpty())
744 {
745 return;
746 }
747 if (!m_menus.testFlag(MenuSave))
748 {
749 return;
750 }
751 const CStatusMessage m = this->saveJson(false);
752 if (!m.isEmpty())
753 {
755 }
756 }
757
759 {
760 if (this->isEmpty())
761 {
762 return;
763 }
764 if (!m_menus.testFlag(MenuSave))
765 {
766 return;
767 }
768 const CStatusMessage m = this->saveJson(true);
769 if (!m.isEmpty())
770 {
772 }
773 }
774
780
786
788
790 {
791 const int height = this->verticalHeader()->minimumSectionSize();
793 Q_ASSERT_X(verticalHeader, Q_FUNC_INFO, "Missing vertical header");
794 verticalHeader->setSectionResizeMode(QHeaderView::Interactive);
795 verticalHeader->setDefaultSectionSize(height);
796 m_rowResizeMode = Interactive;
797 this->showVerticalHeader();
798 }
799
801 {
803 verticalHeader->setVisible(this->wordWrap() && m_resizeMode != ResizingAuto && m_rowResizeMode == Interactive);
804 verticalHeader->setFixedWidth(16);
805 }
806
815
817 {
818 if (elements > ResizeRowsToContentThreshold)
819 {
821 }
822 else
823 {
825 }
826 }
827
828 int CViewBaseNonTemplate::showLoadIndicator(int containerSizeDependent, std::chrono::milliseconds timeout,
829 bool processEvents)
830 {
831 using namespace std::chrono_literals;
833 {
834 return -1;
835 }
837 {
838 return -1;
839 }
840
841 if (this->hasDockWidgetArea())
842 {
843 if (!this->isVisibleWidget())
844 {
845 return -1;
846 }
847 }
848
849 if (containerSizeDependent >= 0)
850 {
851 // really with indicator?
852 if (containerSizeDependent < ResizeSubsetThreshold)
853 {
854 return -1;
855 }
856 }
859
860 if (!m_loadIndicator)
861 {
862 m_loadIndicator = new CLoadIndicator(64, 64, this);
863 connect(m_loadIndicator, &CLoadIndicator::timedOut, this, &CViewBaseNonTemplate::onLoadIndicatorTimedOut);
864 }
865 this->centerLoadIndicator();
866 return m_loadIndicator->startAnimation(timeout > 0ms ? timeout : m_loadIndicatorTimeoutDefault, processEvents);
867 }
868
869 int CViewBaseNonTemplate::showLoadIndicatorWithTimeout(std::chrono::milliseconds timeout, bool processEvents)
870 {
871 return this->showLoadIndicator(-1, timeout, processEvents);
872 }
873
875 {
876 if (!m_loadIndicator)
877 {
878 return;
879 }
880 const QPoint middle = this->viewport()->geometry().center();
881 m_loadIndicator->centerLoadIndicator(middle);
882 }
883
885 {
887 {
888 return;
889 }
892 if (!m_loadIndicator)
893 {
894 return;
895 }
896 m_loadIndicator->stopAnimation(loadingId);
897 }
898
899 bool CViewBaseNonTemplate::isResizeConditionMet(int containerSize) const
900 {
902 {
903 return true;
904 }
906 {
907 return false;
908 }
910 {
911 return false;
912 }
914 {
915 return m_resizeCount < 1;
916 }
918 {
919 if (reachedResizeThreshold(containerSize))
920 {
921 return false;
922 }
923 if (m_resizeAutoNthTime < 2)
924 {
925 return true;
926 }
927 return (m_resizeCount % m_resizeAutoNthTime) == 0;
928 }
929 return false;
930 }
931
933 {
936 // Not working anymore and NOT needed ??? anymore, seems like
937 // resize to maximum magic trick from: http://stackoverflow.com/q/3433664/356726
938 this->setVisible(false);
939 const QRect vpOriginal = this->viewport()->geometry();
940 if (m_forceColumnsToMaxSize)
941 {
942 // vpNew.setWidth(std::numeric_limits<qint32>::max()); // largest finite value
943 QGuiApplication::screens();
944 const QRect screenGeometry = sGui->currentScreen()->geometry();
945 QRect vpNew = vpOriginal;
946 vpNew.setWidth(screenGeometry.width());
947 this->viewport()->setGeometry(vpNew);
948 }
949 **/
950
951 // useless if mode is Interactive
952 if (m_rowResizeMode == Content)
953 {
954 this->resizeRowsToContents(); // rows
955 }
957
958 // re-stretch
960 {
961 // toggling forces the stretch, otherwise not working
964 }
965
966 // const int cols = this->colorCount();
967 // if (this->endsWithEmptyColumn()) { this->setColumnWidth(cols - 1, 10); }
968 // gives a weird NO METRICS warning
969
970 this->resizeColumnsToContents(); // columns
971
978 }
979
980 void CViewBaseNonTemplate::customMenuRequested(const QPoint &pos)
981 {
982 QMenu menu;
983 CMenuActions menuActions;
984 this->customMenu(menuActions);
985 if (menuActions.isEmpty())
986 {
987 return;
988 }
989 menuActions.toQMenu(menu, true);
990
991 // Nested dock widget menu
992 const CDockWidgetInfoArea *dockWidget = this->getDockWidgetInfoArea();
993 if (dockWidget)
994 {
995 if (!menu.isEmpty())
996 {
997 menu.addSeparator();
998 }
999 const QString mm = QStringLiteral("Dock widget '%1'").arg(dockWidget->windowTitleOrBackup());
1000 QMenu *dockWidgetSubMenu = menu.addMenu(CIcons::text16(), mm);
1001 dockWidget->addToContextMenu(dockWidgetSubMenu);
1002 }
1003
1004 const QPoint globalPos = this->mapToGlobal(pos);
1005 menu.exec(globalPos);
1006 }
1007
1008 void CViewBaseNonTemplate::onLoadIndicatorTimedOut() { m_showingLoadIndicator = false; }
1009
1010 void CViewBaseNonTemplate::toggleResizeMode(bool checked)
1011 {
1014 {
1015 // make sure not use this one here
1017 }
1018 else
1019 {
1020 this->showVerticalHeader();
1021 }
1022 }
1023
1024 void CViewBaseNonTemplate::toggleWordWrap(bool checked)
1025 {
1026 if (this->wordWrap() == checked)
1027 {
1028 return;
1029 }
1030 if (checked)
1031 {
1032 // menuAddItems()
1033 }
1034 this->setWordWrap(checked);
1035 this->showVerticalHeader(); // can be slow
1036 }
1037
1038 void CViewBaseNonTemplate::toggleAutoDisplay()
1039 {
1041 if (!a)
1042 {
1043 return;
1044 }
1045 Q_ASSERT_X(a->isCheckable(), Q_FUNC_INFO, "object not checkable");
1046 m_displayAutomatically = a->isChecked();
1047 }
1048
1050 {
1051 // FIXME: Workaround to implement the logic on our own because the default selectAll() implementation does not
1052 // seem to work
1053 this->clearSelection();
1054 QItemSelection selectedItems;
1055 const int columns = this->model()->columnCount() - 1;
1056 const int rows = this->model()->rowCount() - 1;
1057 selectedItems.select(this->model()->index(0, 0), this->model()->index(rows, columns));
1058 this->selectionModel()->select(selectedItems, QItemSelectionModel::Select);
1059 }
1060
1062
1064 {
1065 if (this->allowsMultipleSelectedRows())
1066 {
1068 }
1069 }
1070
1072 {
1073 if (this->allowsMultipleSelectedRows())
1074 {
1076 }
1077 }
1078
1079 void CViewBaseNonTemplate::removeSelectedRowsChecked()
1080 {
1082 {
1083 return;
1084 }
1085 this->removeSelectedRows();
1086 }
1087
1089 {
1090 if (!event || !this->acceptDrop(event->mimeData()))
1091 {
1092 return;
1093 }
1095 event->acceptProposedAction();
1096 }
1097
1099 {
1100 if (!event || !this->acceptDrop(event->mimeData()))
1101 {
1102 return;
1103 }
1104 event->acceptProposedAction();
1105 }
1106
1108 {
1109 if (!event)
1110 {
1111 return;
1112 }
1113 event->accept();
1114 }
1115
1117 {
1118 if (!event)
1119 {
1120 return;
1121 }
1123 }
1124
1126 {
1127 containerSize = containerSize >= 0 ? containerSize : this->rowCount();
1128 const int presizeRandomElements = containerSize > 1000 ? containerSize / 100 : containerSize / 40;
1129 return presizeRandomElements;
1130 }
1131} // namespace swift::gui::views
static bool isLocalDeveloperDebugBuild()
Local build for developers.
QString windowTitleOrBackup() const
If current window title is empty, use backup.
Specialized class for dock widgets serving as info area.
void addToContextMenu(QMenu *contextMenu) const
Contribute to menu.
CDockWidgetInfoArea * getDockWidgetInfoArea() const
Corresponding dockable widget in info area.
virtual bool setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget)
Corresponding dockable widget in info area.
static QWidget * mainApplicationWidget()
Main application window widget.
The QProgressIndicator class lets an application display a progress indicator to show that a lengthy ...
void timedOut()
Timed out.
COverlayMessagesTableView(QWidget *parent=nullptr)
Constructor.
static const QKeySequence & keyDelete()
Delete, e.g. selected rows.
Definition shortcut.cpp:61
static const QKeySequence & keySelectAll()
For selecting all.
Definition shortcut.cpp:30
static const QKeySequence & keyResizeView()
Resize view.
Definition shortcut.cpp:42
static const QKeySequence & keyDisplayFilter()
Display filter.
Definition shortcut.cpp:36
static const QKeySequence & keyClearSelection()
For deselecting all.
Definition shortcut.cpp:24
static const QKeySequence & keyCopy()
Copy.
Definition shortcut.cpp:73
static QString toParenthesisString(const QKeySequence &sequence)
As string for menus etc. Looks like "(CTRL + R)".
Definition shortcut.cpp:97
static const QKeySequence & keySaveViews()
Save in views.
Definition shortcut.cpp:54
Base for filter dialog.
Base for filter dialog.
void changeFilter(bool enable)
Change the filter by enabling or disabling it.
virtual void onRowCountChanged(int count, bool withFilter)=0
Row count has been changed.
static const QString & pathViewLoadSave()
View load/save.
Definition menuaction.h:337
static const QString & pathViewSelection()
View selection mode.
Definition menuaction.h:288
static const QString & pathViewCutPaste()
View cut and paste.
Definition menuaction.h:344
static const QString & pathViewResize()
View resizing.
Definition menuaction.h:302
static const QString & pathFont()
Font menus (font size etc.).
Definition menuaction.h:200
static const QString & pathViewFilter()
View filter.
Definition menuaction.h:323
static const QString & pathViewAddRemove()
Select add remove.
Definition menuaction.h:281
static const QString & pathViewUpdates()
View update.
Definition menuaction.h:330
Bunch of CMenuAction objects.
Definition menuaction.h:384
CMenuActions addActions(const CMenuActions &actions)
Add menu actions, returns last valid QAction.
void toQMenu(QMenu &menu, bool separateGroups) const
Insert the sorted actions to the menu.
CMenuAction addAction(const CMenuAction &menuAction)
Add menu action.
CMenuAction first() const
First action.
Definition menuaction.h:485
Interface to implement a custom menu.
void setNestedDelegate(IMenuDelegate *nestedDelegate)
Set nested delegate.
QAbstractItemView::SelectionMode getPreferredSelection() const
Preferred selection.
virtual bool filterWidgetChangedFilter(bool enabled)=0
Filter changed in filter widget.
QString getFileDialogFileName(bool load) const
Default file for load/save operations.
QWidget * m_filterWidget
filter widget or dialog
Definition viewbase.h:602
void menuAddItems(Menu menusToAdd)
Add given menu items.
void setSelectionModel(QItemSelectionModel *model)
components::CTextEditDialog * textEditDialog()
Init text edit dialog if required and return pointer to it.
static constexpr int ResizeSubsetThreshold
When to use pre-sizing with random elements.
Definition viewbase.h:153
void rowsResizeModeToInteractive()
Init as interactive, as this allows manually resizing.
bool m_forceStretchLastColumnWhenResized
a small table might (few columns) fail stretching, force again
Definition viewbase.h:590
void hideLoadIndicator(int loadingId=-1)
Hide loading indicator.
void setHorizontalHeaderSectionResizeMode(QHeaderView::ResizeMode mode)
Resize mode.
virtual bool reachedResizeThreshold(int containerSize=-1) const =0
Skip resizing because of size?
swift::misc::CDirectories::ColumnIndex m_dirSettingsIndex
allows to set more specialized directories //!< remember last JSON directory, having this member allo...
Definition viewbase.h:610
menus::IMenuDelegate * setCustomMenu(menus::IMenuDelegate *menu, bool nestPreviousMenu=true)
Set custom menu if applicable.
Menu m_menus
Default menu settings.
Definition viewbase.h:603
@ PresizeSubset
use a subset of the data to resize
Definition viewbase.h:104
@ ResizingAuto
resizing when below threshold,
Definition viewbase.h:101
int selectedRowCount() const
Number of selected rows.
virtual void resizeToContents()
Resize to contents, strategy depends on container size.
SelectionMode m_originalSelectionMode
Selection mode set.
Definition viewbase.h:585
void triggerReload()
Trigger reload from backend by signal requestUpdate();.
bool isCurrentlyAllowingMultipleRowSelections() const
Is the current selection mode allow multiple selection.
virtual int removeSelectedRows()=0
Remove selected rows.
int getPresizeRandomElementsSize(int containerSize=-1) const
Calculate presize count.
bool allowsMultipleSelectedRows() const
Allows to select multiple rows.
void requestNewBackendData()
Load data from backend (where it makes sense).
virtual void removeFilter()=0
Remove filter.
virtual QString getRememberedLastJsonDirectory() const
JSON directory.
virtual void onDoubleClicked(const QModelIndex &index)=0
Index double clicked.
virtual void displaySelectedJsonPopup()=0
Display JSON data.
virtual void onClicked(const QModelIndex &index)=0
Index clicked.
virtual bool acceptDrop(const QMimeData *mimeData) const =0
Accept drop data?
void loadIndicatorVisibilityChanged(bool visible)
Load indicator's visibility has been changed.
int getHorizontalHeaderFontHeight() const
Horizontal font height.
bool m_displayAutomatically
display directly when loaded
Definition viewbase.h:597
QModelIndexList selectedRows() const
Selected rows if any.
void loadJsonAction()
Load JSON for action/menu, void return signatur.
void menuRemoveItems(Menu menusToRemove)
Remove given menu items.
virtual void rememberLastJsonDirectory(const QString &selectedFileOrDir)
JSON directory.
virtual swift::misc::CStatusMessage loadJson(const QString &directory={})=0
Load JSON.
CLoadIndicator * m_loadIndicator
load indicator if needed
Definition viewbase.h:606
virtual QModelIndexList unselectedRows() const
Unselected (not selected) rows if any.
RowsResizeMode m_rowResizeMode
row resize mode for row height
Definition viewbase.h:584
void requestUpdate()
Ask for new data from currently loaded data.
bool m_enabledLoadIndicator
loading indicator enabled/disabled
Definition viewbase.h:593
int showLoadIndicatorWithTimeout(std::chrono::milliseconds timeout=std::chrono::milliseconds { 0 }, bool processEvents=true)
Show loading indicator which can time out.
const QFont & getHorizontalHeaderFont() const
Header (horizontal) font.
Definition viewbase.h:225
void saveJsonAction()
Save JSON for action/menu, void return signatur.
void saveSelectedJsonAction()
Save JSON for action/menu, void return signatur.
QWidget * mainApplicationWindowWidget() const
Main application window widget if any.
virtual void displayJsonPopup()=0
Display JSON data.
virtual void performModeBasedResizeToContent()=0
Perform resizing (no presizing) / non slot method for template.
virtual void materializeFilter()=0
Materialize filter.
void setFilterWidget(filters::CFilterWidget *filterWidget)
Set filter widget.
swift::misc::CStatusMessage showFileLoadDialog(const QString &directory={})
Show file load dialog.
void onModelChanged()
Underlying model changed.
int m_resizeAutoNthTime
with ResizeAuto, resize every n-th time
Definition viewbase.h:588
virtual void fullResizeToContents()
Full resizing to content, might be slow.
void setMultiSelection()
Change selection modes.
QMap< MenuFlag, menus::CMenuActions > m_menuFlagActions
initialized actions for menu flag (enum)
Definition viewbase.h:608
std::chrono::milliseconds m_loadIndicatorTimeoutDefault
default time for timeout
Definition viewbase.h:589
virtual void clear()=0
Clear data.
virtual void onRowSelected(const QModelIndex &index)=0
Row selected.
void rowsResizeModeToContent()
Resize mode to content.
virtual bool filterDialogFinished(int status)=0
Filter dialog finished.
QString m_saveFileName
save file name (JSON)
Definition viewbase.h:609
menus::CFontMenu * m_fontMenu
font menu if applicable
Definition viewbase.h:605
void centerLoadIndicator()
Center / re-center load indicator.
virtual bool isResizeConditionMet(int containerSize=-1) const
Resize or skip resize?
bool hasSingleSelectedRow() const
Single selected row.
bool hasMultipleSelectedRows() const
Multiple selected rows.
swift::misc::CSettingReadOnly< settings::TGeneralGui > m_guiSettings
general GUI settings
Definition viewbase.h:616
virtual bool isEmpty() const =0
Empty?
int showLoadIndicator(int containerSizeDependent=-1, std::chrono::milliseconds timeout=std::chrono::milliseconds { 0 }, bool processEvents=true)
Show loading indicator.
int m_resizeCount
flag / counter, how many resize activities
Definition viewbase.h:586
virtual void presizeOrFullResizeToContents()=0
Depending on CViewBaseNonTemplate::ResizeSubsetThreshold presize or fully resize.
virtual void customMenu(menus::CMenuActions &menuActions)
Method creating the menu.
swift::misc::CStatusMessage showFileSaveDialog(bool selectedOnly, const QString &directory={})
Show file save dialog.
virtual void updateSortIndicator()=0
Set the sort indicator to the current sort column.
virtual swift::misc::CStatusMessage saveJson(bool selectedOnly=false, const QString &directory={})=0
Save JSON.
void rowsResizeModeBasedOnThreshold(int elements)
Set content/interactive mode based on ResizeRowsToContentThreshold.
void enableLoadIndicator(bool enable)
Enable loading indicator.
static constexpr int ResizeRowsToContentThreshold
When to use rows resizing (which is slow).
Definition viewbase.h:157
bool isShowingLoadIndicator
Load indicator property allows using in stylesheet.
Definition viewbase.h:91
void settingsChanged()
Settings have been changed.
void setExtendedSelection()
Change selection modes.
void modelDataChanged(int count, bool withFilter)
Model data changed.
bool m_showingLoadIndicator
showing loading indicator
Definition viewbase.h:592
int selectRows(const QSet< int > &rows)
Select given rows.
bool setParentDockWidgetInfoArea(swift::gui::CDockWidgetInfoArea *parentDockableWidget)
Corresponding dockable widget in info area.
virtual void paste()=0
Clipboard cut/copy/paste.
void displayFilterDialog()
Display the filter dialog.
menus::IMenuDelegate * m_menu
custom menu if any
Definition viewbase.h:604
swift::misc::CSetting< swift::misc::settings::TDirectorySettings > m_dirSettings
directory for load/save
Definition viewbase.h:613
void setSingleSelection()
Change selection modes.
menus::CMenuActions initMenuActions(MenuFlag menu)
Init menu actions.
virtual void copy()=0
Clipboard cut/copy/paste.
void setFilterDialog(filters::CFilterDialog *filterDialog)
Filter dialog.
components::CTextEditDialog * m_textEditDialog
text edit dialog
Definition viewbase.h:607
void triggerReloadFromBackend()
Trigger reload from backend by signal requestNewBackendData().
int unselectedRowCount() const
Unselected row count.
@ MenuDisplayAutomatically
allow to switch display automatically
Definition viewbase.h:124
@ MenuClear
allow clearing the view via menu
Definition viewbase.h:120
@ MenuFont
font related menu (size)
Definition viewbase.h:135
@ MenuRefresh
allow refreshing the view via menu
Definition viewbase.h:122
@ MenuCopy
copy (for copy/paste)
Definition viewbase.h:132
@ MenuBackend
allow to request data from backend
Definition viewbase.h:123
@ MenuRemoveSelectedRows
allow to remove selected rows
Definition viewbase.h:121
@ MenuPaste
paste (for copy/paste)
Definition viewbase.h:133
@ MenuMaterializeFilter
materialize filter (filtered data become model data)
Definition viewbase.h:127
@ MenuToggleSelectionMode
allow to toggle selection mode
Definition viewbase.h:130
bool hasSelection() const
Selection (selected rows).
virtual int rowCount() const =0
Elements in container.
bool displayAutomatically() const
Display automatically (when models are loaded).
Definition viewbase.h:219
bool m_enableDeleteSelectedRows
selected rows can be deleted
Definition viewbase.h:598
CViewBaseNonTemplate(QWidget *parent)
Constructor.
virtual void cut()=0
Clipboard cut/copy/paste.
Directories (swift data directories).
Definition directories.h:25
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
static QString fileNameToDirectory(const QString &fileName)
Convert to directory.
static const QString & jsonAppendix()
Our JSON file name appendix.
Definition fileutils.cpp:28
static const QString & jsonWildcardAppendix()
JSON wildcard + appendix.
Definition fileutils.cpp:34
static QString appendFilePaths(const QString &path1, const QString &path2)
Append file paths.
static const QPixmap & viewMultiColumn()
View multicolumn.
static const QPixmap & text16()
Text.
static const QPixmap & paste16()
Paste.
static const QPixmap & resizeVertical16()
Resize vertically.
static const QPixmap & cut16()
Cut.
static const QPixmap & refresh16()
Refresh.
static const QPixmap & appMappings16()
Application mappings.
static const QPixmap & resize16()
Resize.
static const QPixmap & viewTile()
View tile.
static const QPixmap & copy16()
Copy.
static const QPixmap & disk16()
Disk.
static const QPixmap & delete16()
Delete.
static const QPixmap & filter16()
Filter.
static const QPixmap & tableSheet16()
Table sheet.
static const QPixmap & tableRelationship16()
Radar.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
bool isEmpty() const
Message empty.
Streamable status message, e.g.
static CVariant fromValue(T &&value)
Construct a variant from a value.
Definition variant.h:139
High level reusable GUI components.
Filter to search data sets.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
GUI related classes.
Free functions in swift::misc.
virtual int columnCount(const QModelIndex &parent) const const=0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual int rowCount(const QModelIndex &parent) const const=0
void clicked(const QModelIndex &index)
void doubleClicked(const QModelIndex &index)
virtual bool event(QEvent *event) override
void setHorizontalScrollMode(QAbstractItemView::ScrollMode mode)
QAbstractItemModel * model() const const
void setSelectionMode(QAbstractItemView::SelectionMode mode)
QItemSelectionModel * selectionModel() const const
void setTextElideMode(Qt::TextElideMode mode)
void setVerticalScrollMode(QAbstractItemView::ScrollMode mode)
QWidget * viewport() const const
void setCheckable(bool)
void setChecked(bool)
void setEnabled(bool)
void toggled(bool checked)
void finished(int result)
bool exists() const const
const QMimeData * mimeData() const const
int height() const const
QClipboard * clipboard()
void setDefaultSectionSize(int size)
void setMinimumSectionSize(int size)
void setSectionResizeMode(QHeaderView::ResizeMode mode)
virtual void setVisible(bool v) override
void setSortIndicatorShown(bool show)
void setStretchLastSection(bool stretch)
void select(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
bool hasSelection() const const
virtual void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
QModelIndexList selectedRows(int column) const const
qsizetype size() const const
QAction * addMenu(QMenu *menu)
QAction * addSeparator()
QAction * exec()
bool isEmpty() const const
QMetaMethod fromSignal(PointerToMemberFunction signal)
const char * className() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
bool disconnect(const QMetaObject::Connection &connection)
bool isSignalConnected(const QMetaMethod &signal) const const
virtual const QMetaObject * metaObject() const const
QObject * parent() const const
T qobject_cast(QObject *object)
QObject * sender() const const
void setObjectName(QAnyStringView name)
void activated()
QString arg(Args &&... args) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
CaseInsensitive
QueuedConnection
CustomContextMenu
WidgetShortcut
ElideNone
virtual void dropEvent(QDropEvent *event) override
QHeaderView * horizontalHeader() const const
void resizeColumnsToContents()
void resizeRowsToContents()
virtual void setSelectionModel(QItemSelectionModel *selectionModel) override
QHeaderView * verticalHeader() const const
void setWordWrap(bool on)
QString toString() const const
QWidget(QWidget *parent, Qt::WindowFlags f)
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
void customContextMenuRequested(const QPoint &pos)
QPoint mapToGlobal(const QPoint &pos) const const
virtual void resizeEvent(QResizeEvent *event)
void setBackgroundRole(QPalette::ColorRole role)
void resize(const QSize &)