swift
viewbase.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_GUI_VIEWBASE_H
7 #define SWIFT_GUI_VIEWBASE_H
8 
9 #include <memory>
10 
11 #include <QAbstractItemView>
12 #include <QFlags>
13 #include <QHeaderView>
14 #include <QJsonDocument>
15 #include <QJsonObject>
16 #include <QMap>
17 #include <QModelIndexList>
18 #include <QObject>
19 #include <QString>
20 #include <QTableView>
21 #include <Qt>
22 #include <QtGlobal>
23 
25 #include "gui/menus/menuaction.h"
26 #include "gui/models/modelfilter.h"
30 #include "gui/swiftguiexport.h"
31 #include "misc/directories.h"
33 #include "misc/propertyindex.h"
35 #include "misc/statusmessage.h"
36 #include "misc/variant.h"
37 
38 class QDragEnterEvent;
39 class QDragLeaveEvent;
40 class QDragMoveEvent;
41 class QFont;
42 class QItemSelectionModel;
43 class QMimeData;
44 class QModelIndex;
45 class QPaintEvent;
46 class QPoint;
47 class QShowEvent;
48 class QTabWidget;
49 
50 namespace swift::misc
51 {
52  class CWorker;
53 }
54 namespace swift::gui
55 {
56  class CDockWidgetInfoArea;
57  class CLoadIndicator;
58 
59  namespace menus
60  {
61  class IMenuDelegate;
62  class CFontMenu;
63  } // namespace menus
64 
65  namespace models
66  {
67  class CColumns;
68  }
69 
70  namespace filters
71  {
72  class CFilterDialog;
73  class CFilterWidget;
74  } // namespace filters
75 
76  namespace components
77  {
78  class CTextEditDialog;
79  }
80 
81  namespace views
82  {
87  {
88  Q_OBJECT
89 
91  Q_PROPERTY(bool isShowingLoadIndicator READ isShowingLoadIndicator NOTIFY loadIndicatorVisibilityChanged)
92 
93  friend class CViewBaseItemDelegate;
94  friend class CViewBaseProxyStyle;
95 
96  public:
100  {
101  ResizingAuto,
106  ResizingOff
107  };
108 
111  {
112  Interactive,
113  Content
114  };
115 
117  enum MenuFlag
118  {
119  MenuNone = 0,
120  MenuClear = 1 << 0,
121  MenuRemoveSelectedRows = 1 << 1,
122  MenuRefresh = 1 << 2,
123  MenuBackend = 1 << 3,
124  MenuDisplayAutomatically = 1 << 4,
125  MenuDisplayAutomaticallyAndRefresh = MenuDisplayAutomatically | MenuRefresh,
126  MenuFilter = 1 << 5,
127  MenuMaterializeFilter = 1 << 6,
128  MenuSave = 1 << 7,
129  MenuLoad = 1 << 8,
130  MenuToggleSelectionMode = 1 << 9,
131  MenuOrderable = 1 << 10,
132  MenuCopy = 1 << 11,
133  MenuPaste = 1 << 12,
134  MenuCut = 1 << 13,
135  MenuFont = 1 << 14,
136  MenuLoadAndSave = MenuLoad | MenuSave,
137  MenuDefault = MenuToggleSelectionMode | MenuDisplayAutomaticallyAndRefresh | MenuFont | MenuClear,
138  MenuDefaultNoClear = MenuToggleSelectionMode | MenuDisplayAutomaticallyAndRefresh | MenuFont,
139  MenuDefaultDbViews = MenuToggleSelectionMode | MenuBackend | MenuFont,
140  // special menus, should be in derived classes, but enums cannot be inherited
141  // maybe shifted in the future to elsewhere
142  MenuHighlightStashed = 1 << 15,
143  MenuCanStashModels = 1 << 16,
144  MenuDisableModelsTemp = 1 << 17,
145  MenuStashing = MenuHighlightStashed | MenuCanStashModels,
146  };
147  Q_DECLARE_FLAGS(Menu, MenuFlag)
148 
149 
150  static constexpr int ASyncRowsCountThreshold = 50;
151 
153  static constexpr int ResizeSubsetThreshold = 250;
154 
157  static constexpr int ResizeRowsToContentThreshold = 20;
158 
160  virtual void clear() = 0;
161 
163  virtual bool isEmpty() const = 0;
164 
166  virtual int rowCount() const = 0;
167 
169  virtual bool isOrderable() const = 0;
170 
172  virtual bool setSorting(const swift::misc::CPropertyIndex &propertyIndex,
173  Qt::SortOrder order = Qt::AscendingOrder) = 0;
174 
176  virtual void sortByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex,
177  Qt::SortOrder order = Qt::AscendingOrder) = 0;
178 
180  virtual void setNoSorting() = 0;
181 
183  virtual swift::misc::CPropertyIndex getSortProperty() const = 0;
184 
186  virtual int getSortColumn() const = 0;
187 
189  virtual bool hasValidSortColumn() const = 0;
190 
192  virtual bool endsWithEmptyColumn() const = 0;
193 
195  virtual Qt::SortOrder getSortOrder() const = 0;
196 
198  virtual void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile = false) = 0;
199 
201  virtual bool isDropAllowed() const = 0;
202 
204  virtual bool acceptDrop(const QMimeData *mimeData) const = 0;
205 
207  virtual bool setParentDockWidgetInfoArea(swift::gui::CDockWidgetInfoArea *parentDockableWidget) override;
208 
210  ResizeMode getResizeMode() const { return m_resizeMode; }
211 
213  void setResizeMode(ResizeMode mode) { m_resizeMode = mode; }
214 
216  void setAutoResizeFrequency(int updateEveryNthTime) { m_resizeAutoNthTime = updateEveryNthTime; }
217 
219  bool displayAutomatically() const { return m_displayAutomatically; }
220 
222  void setDisplayAutomatically(bool automatically) { m_displayAutomatically = automatically; }
223 
225  const QFont &getHorizontalHeaderFont() const
226  {
227  Q_ASSERT(this->horizontalHeader());
228  return this->horizontalHeader()->font();
229  }
230 
232  int getHorizontalHeaderFontHeight() const;
233 
235  bool hasSelection() const;
236 
238  QModelIndexList selectedRows() const;
239 
241  virtual QModelIndexList unselectedRows() const;
242 
244  int selectRows(const QSet<int> &rows);
245 
247  int selectedRowCount() const;
248 
250  int unselectedRowCount() const;
251 
253  bool hasSingleSelectedRow() const;
254 
256  bool hasMultipleSelectedRows() const;
257 
259  bool allowsMultipleSelectedRows() const;
260 
262  bool isCurrentlyAllowingMultipleRowSelections() const;
263 
265  void setFilterDialog(filters::CFilterDialog *filterDialog);
266 
268  QWidget *getFilterWidget() const { return m_filterWidget; }
269 
271  void setFilterWidget(filters::CFilterWidget *filterWidget);
272 
274  menus::IMenuDelegate *setCustomMenu(menus::IMenuDelegate *menu, bool nestPreviousMenu = true);
275 
277  void enableLoadIndicator(bool enable);
278 
280  bool isShowingLoadIndicator() const;
281 
283  void acceptClickSelection(bool accept) { m_acceptClickSelection = accept; }
284 
286  void acceptDoubleClickSelection(bool accept) { m_acceptDoubleClickSelection = accept; }
287 
289  void acceptRowSelection(bool accept) { m_acceptRowSelection = accept; }
290 
292  void menuRemoveItems(Menu menusToRemove);
293 
295  void menuAddItems(Menu menusToAdd);
296 
298  void setMenu(Menu menuItems) { m_menus = menuItems; }
299 
301  Menu getMenu() const { return m_menus; }
302 
304  virtual void setSelectionModel(QItemSelectionModel *model) override;
305 
307  QWidget *mainApplicationWindowWidget() const;
308 
310  swift::misc::CStatusMessage showFileLoadDialog(const QString &directory = {});
311 
313  swift::misc::CStatusMessage showFileSaveDialog(bool selectedOnly, const QString &directory = {});
314 
316  void setSaveFileName(const QString &saveName) { m_saveFileName = saveName; }
317 
319  bool allowCacheFileFormatJson() const { return m_allowCacheFileJson; }
320 
322  void setAllowCacheFileFormatJson(bool allow) { m_allowCacheFileJson = allow; }
323 
327  void setForceColumnsToMaxSize(bool force) { this->setWordWrap(!force); }
328 
330  void setHorizontalHeaderSectionResizeMode(QHeaderView::ResizeMode mode);
331 
334  {
335  m_dirSettingsIndex = directoryIndex;
336  }
337 
338  signals:
341 
344 
346  void loadIndicatorVisibilityChanged(bool visible);
347 
350 
352  void modelDataChanged(int count, bool withFilter);
353 
355  void modelDataChangedDigest(int count, bool withFilter);
356 
358  void modelChanged();
359 
361  void objectChanged(const swift::misc::CVariant &object, const swift::misc::CPropertyIndex &changedIndex);
362 
365 
368 
371 
373  void objectsDeleted(const swift::misc::CVariant &objectContainer);
374 
377 
378  public slots:
380  virtual void resizeToContents();
381 
383  virtual void fullResizeToContents();
384 
386  virtual void presizeOrFullResizeToContents() = 0;
387 
389  void rowsResizeModeToInteractive();
390 
393  void rowsResizeModeToContent();
394 
396  void rowsResizeModeBasedOnThreshold(int elements);
397 
402  int showLoadIndicator(int containerSizeDependent = -1,
403  std::chrono::milliseconds timeout = std::chrono::milliseconds { 0 },
404  bool processEvents = true);
405 
407  int showLoadIndicatorWithTimeout(std::chrono::milliseconds timeout = std::chrono::milliseconds { 0 },
408  bool processEvents = true);
409 
411  void onModelChanged();
412 
414  void hideLoadIndicator(int loadingId = -1);
415 
417  void hideLoadIndicatorForced() { this->hideLoadIndicator(); }
418 
420  virtual int removeSelectedRows() = 0;
421 
423  virtual void clearHighlighting() = 0;
424 
426  virtual void materializeFilter() = 0;
427 
428  protected:
430  CViewBaseNonTemplate(QWidget *parent);
431 
433  virtual ~CViewBaseNonTemplate() override;
434 
438  virtual void customMenu(menus::CMenuActions &menuActions);
439 
443  virtual void resizeEvent(QResizeEvent *event) override;
444 
446  virtual void dragEnterEvent(QDragEnterEvent *event) override;
447 
449  virtual void dragMoveEvent(QDragMoveEvent *event) override;
450 
452  virtual void dragLeaveEvent(QDragLeaveEvent *event) override;
453 
455  virtual void dropEvent(QDropEvent *event) override;
457 
461 
466  virtual int performUpdateContainer(const swift::misc::CVariant &variant, bool sort, bool resize) = 0;
467 
469  virtual bool reachedResizeThreshold(int containerSize = -1) const = 0;
470 
472  virtual bool isResizeConditionMet(int containerSize = -1) const;
473 
475  int getPresizeRandomElementsSize(int containerSize = -1) const;
476 
478  void centerLoadIndicator();
479 
481  void init();
482 
484  QString getFileDialogFileName(bool load) const;
485 
487  menus::CMenuActions initMenuActions(MenuFlag menu);
488 
490  virtual void updateSortIndicator() = 0;
491 
493  virtual void mouseOverCallback(const QModelIndex &index, bool mouseOver) = 0;
494 
496  virtual void drawDropIndicator(bool indicator) = 0;
497 
499  void saveJsonAction();
500 
502  void saveSelectedJsonAction();
503 
505  virtual void displayJsonPopup() = 0;
506 
508  virtual void displaySelectedJsonPopup() = 0;
509 
511  void loadJsonAction();
512 
514  virtual swift::misc::CStatusMessage loadJsonFile(const QString &filePath) = 0;
515 
517  void displayFilterDialog();
518 
520  void settingsChanged();
521 
523  void selectAll() override;
524 
527  void setMultiSelection();
528  void setExtendedSelection();
529  void setSingleSelection();
531 
534  virtual void rememberLastJsonDirectory(const QString &selectedFileOrDir);
535 
538  virtual QString getRememberedLastJsonDirectory() const;
539 
542  virtual void copy() = 0;
543  virtual void cut() = 0;
544  virtual void paste() = 0;
546 
548  virtual void onClicked(const QModelIndex &index) = 0;
549 
551  virtual void onDoubleClicked(const QModelIndex &index) = 0;
552 
554  virtual void onRowSelected(const QModelIndex &index) = 0;
555 
557  virtual swift::misc::CStatusMessage loadJson(const QString &directory = {}) = 0;
558 
560  virtual swift::misc::CStatusMessage saveJson(bool selectedOnly = false, const QString &directory = {}) = 0;
561 
563  void triggerReload();
564 
566  void triggerReloadFromBackend();
567 
569  virtual void removeFilter() = 0;
570 
572  void showVerticalHeader();
573 
575  virtual bool filterDialogFinished(int status) = 0;
576 
578  virtual bool filterWidgetChangedFilter(bool enabled) = 0;
579 
581  components::CTextEditDialog *textEditDialog();
582 
583  ResizeMode m_resizeMode = PresizeSubset;
584  RowsResizeMode m_rowResizeMode = Interactive;
585  SelectionMode m_originalSelectionMode = this->selectionMode();
586  int m_resizeCount = 0;
587  int m_skipResizeThreshold = 40;
588  int m_resizeAutoNthTime = 1;
589  std::chrono::milliseconds m_loadIndicatorTimeoutDefault { 30 * 1000 };
590  bool m_forceStretchLastColumnWhenResized =
591  true;
592  bool m_showingLoadIndicator = false;
593  bool m_enabledLoadIndicator = false;
594  bool m_acceptClickSelection = false;
595  bool m_acceptRowSelection = false;
596  bool m_acceptDoubleClickSelection = false;
597  bool m_displayAutomatically = true;
598  bool m_enableDeleteSelectedRows = false;
599  bool m_dropIndicator = false;
600  bool m_forceColumnsToMaxSize = true;
601  bool m_allowCacheFileJson = true;
602  QWidget *m_filterWidget = nullptr;
603  Menu m_menus = MenuDefault;
604  menus::IMenuDelegate *m_menu = nullptr;
605  menus::CFontMenu *m_fontMenu = nullptr;
606  CLoadIndicator *m_loadIndicator = nullptr;
607  components::CTextEditDialog *m_textEditDialog = nullptr;
609  QString m_saveFileName;
610  swift::misc::CDirectories::ColumnIndex m_dirSettingsIndex = swift::misc::CDirectories::
611  IndexDirLastViewJsonOrDefault;
614  this
615  };
618  };
619 
620  private:
622  void removeSelectedRowsChecked();
623 
625  void toggleAutoDisplay();
626 
628  void customMenuRequested(const QPoint &pos);
629 
631  void onLoadIndicatorTimedOut();
632 
634  void toggleResizeMode(bool checked);
635 
637  void toggleWordWrap(bool checked);
638 
641  void setFilterWidgetImpl(QWidget *filterWidget);
642  };
643  Q_DECLARE_OPERATORS_FOR_FLAGS(swift::gui::views::CViewBaseNonTemplate::Menu)
644 
645 
646  template <class T>
647  class CViewBase : public CViewBaseNonTemplate, public models::ISelectionModel<typename T::ContainerType>
648  {
649  // I cannot use Q_OBJECT here, because: Template classes are not supported by Q_OBJECT
650  // and I cannot declare slots as SLOT because I have no Q_OBJECT macro
651 
652  public:
654  using ModelClass = T;
655 
657  using ContainerType = typename T::ContainerType;
658 
660  using ObjectType = typename T::ObjectType;
661 
663  virtual ~CViewBase()
664  {
665  if (m_model) { m_model->markDestroyed(); }
666  }
667 
670 
672  const ModelClass *derivedModel() const { return m_model; }
673 
675  const models::CColumns &getColumns() const { return this->derivedModel()->getColumns(); }
676 
679  int updateContainer(const ContainerType &container, bool sort = true, bool resize = true);
680 
683  bool resize = true);
684 
686  void updateContainerMaybeAsync(const ContainerType &container, bool sort = true, bool resize = true);
687 
689  void insert(const ObjectType &value, bool resize = true);
690 
692  void insert(const ContainerType &container, bool resize = true);
693 
695  void push_back(const ObjectType &value, bool resize = true);
696 
698  void push_back(const ContainerType &container, bool resize = true);
699 
701  const ObjectType &at(const QModelIndex &index) const;
702 
704  const ContainerType &container() const;
705 
707  QList<int> rowsOf(const ContainerType &container) const;
708 
710  int rowOf(const ObjectType &obj) const;
711 
713  const ContainerType &containerOrFilteredContainer(bool *filtered = nullptr) const;
714 
717 
719  virtual void selectObjects(const ContainerType &selectedObjects) override;
720 
722  virtual ContainerType selectedObjects() const override;
723 
725  virtual ContainerType unselectedObjects() const override;
727 
730 
732  int updateSelected(const swift::misc::CVariant &variant, const swift::misc::CPropertyIndex &index);
733 
736 
738  ObjectType selectedObject() const;
739 
741  template <class K0, class V0, class... KeysValues>
742  int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
743  {
744  if (this->rowCount() < 1) { return 0; }
745  ContainerType cp(container());
746  int r = cp.removeIf(k0, v0, keysValues...);
747  if (r < 1) { return 0; }
748  this->updateContainerMaybeAsync(cp);
749  return r;
750  }
751 
753  template <class K1, class V1>
754  void replaceOrAdd(K1 key1, V1 value1, const ObjectType &replacement)
755  {
756  ContainerType cp(container());
757  cp.replaceOrAdd(key1, value1, replacement);
758  this->updateContainerMaybeAsync(cp);
759  }
760 
763 
765  virtual int removeSelectedRows() override;
766 
768  virtual void presizeOrFullResizeToContents() override;
769 
771  virtual void clearHighlighting() override;
772 
774  virtual void materializeFilter() override;
776 
779 
781  virtual void clear() override;
782 
784  virtual int rowCount() const override;
785 
787  virtual bool isEmpty() const override;
788 
790  virtual bool isOrderable() const override;
791 
793  virtual void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile = false) override;
794 
796  virtual bool isDropAllowed() const override;
797 
799  virtual void dropEvent(QDropEvent *event) override;
800 
802  virtual bool acceptDrop(const QMimeData *mimeData) const override;
803 
805  virtual bool setSorting(const swift::misc::CPropertyIndex &propertyIndex,
806  Qt::SortOrder order = Qt::AscendingOrder) override;
807 
809  virtual void sortByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex,
810  Qt::SortOrder order = Qt::AscendingOrder) override;
811 
813  virtual void setNoSorting() override { m_model->setNoSorting(); }
814 
816  virtual swift::misc::CPropertyIndex getSortProperty() const override { return m_model->getSortProperty(); }
817 
819  virtual int getSortColumn() const override { return m_model->getSortColumn(); }
820 
822  virtual bool hasValidSortColumn() const override { return m_model->hasValidSortColumn(); }
823 
825  virtual bool endsWithEmptyColumn() const override { return m_model->endsWithEmptyColumn(); }
826 
828  virtual Qt::SortOrder getSortOrder() const override { return m_model->getSortOrder(); }
830 
832  void sort();
833 
835  void resort();
836 
838  int columnCount() const;
839 
841  QJsonObject toJson(bool selectedOnly = false) const;
842 
844  QString toJsonString(QJsonDocument::JsonFormat format = QJsonDocument::Indented,
845  bool selectedOnly = false) const;
846 
848  virtual void setObjectName(const QString &name);
849 
851  void takeFilterOwnership(std::unique_ptr<models::IModelFilter<ContainerType>> &filter);
852 
854  bool hasFilter() const;
855 
857  void addContainerTypesAsDropTypes(bool objectType = true, bool containerType = true);
858 
860  void initAsOrderable();
861 
863  void setDropActions(Qt::DropActions dropActions)
864  {
865  Q_ASSERT(m_model);
866  m_model->setDropActions(dropActions);
867  }
868 
870  void setTabWidgetViewText(QTabWidget *tw, int index);
871 
875 
876  protected:
877  ModelClass *m_model = nullptr;
878 
880  CViewBase(QWidget *parent, ModelClass *model = nullptr);
881 
883  void setSortIndicator();
884 
886  void standardInit(ModelClass *model = nullptr);
887 
890 
892  virtual bool reachedResizeThreshold(int containrerSize = -1) const override;
893 
895  virtual void performModeBasedResizeToContent() override;
896 
898  virtual int performUpdateContainer(const swift::misc::CVariant &variant, bool sort, bool resize) override;
899 
901  virtual void updateSortIndicator() override;
902 
904  virtual void mouseOverCallback(const QModelIndex &index, bool mouseOver) override;
905 
907  virtual void drawDropIndicator(bool indicator) override;
908 
910  virtual void copy() override;
911 
913  virtual void cut() override;
914 
916  virtual void paste() override;
917 
919  virtual void displayJsonPopup() override { this->displayContainerAsJsonPopup(false); }
920 
922  virtual void displaySelectedJsonPopup() override { this->displayContainerAsJsonPopup(true); }
923 
925  virtual bool filterDialogFinished(int status) override;
926 
928  virtual bool filterWidgetChangedFilter(bool enabled) override;
929 
931  virtual void removeFilter() override;
933 
936 
939 
942  virtual void jsonLoadedAndModelUpdated(const ContainerType &data);
943 
945  virtual void customMenu(menus::CMenuActions &menuActions) override;
946 
948  virtual swift::misc::CStatusMessage loadJsonFile(const QString &fileName) override;
949 
951  virtual void displayContainerAsJsonPopup(bool selectedOnly);
952 
955 
957  virtual void onClicked(const QModelIndex &index) override;
958 
960  virtual void onDoubleClicked(const QModelIndex &index) override;
961 
963  virtual void onRowSelected(const QModelIndex &index) override;
964 
966  virtual swift::misc::CStatusMessage loadJson(const QString &directory = {}) override;
967 
969  virtual swift::misc::CStatusMessage saveJson(bool selectedOnly = false,
970  const QString &directory = {}) override;
972  };
973  } // namespace views
974 } // namespace swift::gui
975 #endif // SWIFT_GUI_VIEWBASE_H
Specialized class for dock widgets serving as info area.
Helper class: If a component is residing in an dockable widget. This class provides access to its inf...
The QProgressIndicator class lets an application display a progress indicator to show that a lengthy ...
Definition: loadindicator.h:31
Using this class provides a QTableView with the overlay functionality already integrated.
Base for filter dialog.
Definition: filterdialog.h:20
Base for filter dialog.
Definition: filterwidget.h:21
Standard font (size, style) menus. Can be used as nested menu or via getActions added manually.
Definition: fontmenus.h:21
Bunch of CMenuAction objects.
Definition: menuaction.h:384
Interface to implement a custom menu.
Definition: menudelegate.h:21
Header data for a table.
Definition: columns.h:160
Model filter interface.
Definition: modelfilter.h:21
Allow to get and select objects.
Base class for views.
Definition: viewbase.h:648
void sort()
Sort if columns or order changed.
Definition: viewbase.cpp:469
virtual ContainerType unselectedObjects() const
Unselected objects.
Definition: viewbase.cpp:250
virtual bool filterDialogFinished(int status)
Filter dialog finished.
Definition: viewbase.cpp:845
int rowOf(const ObjectType &obj) const
The row of the given object.
Definition: viewbase.cpp:219
virtual void cut()
Clipboard cut/copy/paste.
Definition: viewbase.cpp:817
virtual int performUpdateContainer(const swift::misc::CVariant &variant, bool sort, bool resize)
Helper method with template free signature.
Definition: viewbase.cpp:620
void standardInit(ModelClass *model=nullptr)
Standard initialization.
Definition: viewbase.cpp:572
virtual swift::misc::CStatusMessage loadJsonFile(const QString &fileName)
Method creating the menu.
Definition: viewbase.cpp:693
void initAsOrderable()
Init so items can be ordered, includes enabling drag and drop.
Definition: viewbase.cpp:529
virtual bool acceptDrop(const QMimeData *mimeData) const
Accept drop data?
Definition: viewbase.cpp:448
QList< int > rowsOf(const ContainerType &container) const
The rows of the given objects.
Definition: viewbase.cpp:207
virtual void removeFilter()
Remove filter.
Definition: viewbase.cpp:510
virtual void onRowSelected(const QModelIndex &index)
Row selected.
Definition: viewbase.cpp:894
void setTabWidgetViewText(QTabWidget *tw, int index)
Set a tab widget text based on row count, filter etc.
Definition: viewbase.cpp:539
virtual swift::misc::CStatusMessage loadJson(const QString &directory={})
Load JSON.
Definition: viewbase.cpp:780
virtual void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile=false)
Allow to drag and/or drop value objects.
Definition: viewbase.cpp:414
virtual void clearHighlighting()
Clear any highlighted objects.
Definition: viewbase.cpp:360
virtual bool isEmpty() const
Empty?
Definition: viewbase.cpp:400
void updateContainerMaybeAsync(const ContainerType &container, bool sort=true, bool resize=true)
Based on size call sync / async update.
Definition: viewbase.cpp:117
void insert(const ObjectType &value, bool resize=true)
Insert.
Definition: viewbase.cpp:129
virtual ContainerType selectedObjects() const
Selected objects.
Definition: viewbase.cpp:240
virtual void displayJsonPopup()
Display JSON data.
Definition: viewbase.h:919
virtual swift::misc::CStatusMessage saveJson(bool selectedOnly=false, const QString &directory={})
Save JSON.
Definition: viewbase.cpp:789
ModelClass * derivedModel()
Model.
Definition: viewbase.h:669
ModelClass * m_model
corresponding model
Definition: viewbase.h:877
void setSortIndicator()
Set the search indicator based on model.
Definition: viewbase.cpp:562
virtual int rowCount() const
Elements in container.
Definition: viewbase.cpp:386
const ObjectType & at(const QModelIndex &index) const
Value object at.
Definition: viewbase.cpp:193
void setDropActions(Qt::DropActions dropActions)
Drop actions.
Definition: viewbase.h:863
virtual void clear()
Clear data.
Definition: viewbase.cpp:378
virtual bool hasValidSortColumn() const
Has valid sort column?
Definition: viewbase.h:822
typename T::ObjectType ObjectType
Model container element type.
Definition: viewbase.h:660
virtual void sortByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)
Sort by index.
Definition: viewbase.cpp:463
void takeFilterOwnership(std::unique_ptr< models::IModelFilter< ContainerType >> &filter)
Set filter and take ownership, any previously set filter will be destroyed.
Definition: viewbase.cpp:504
virtual bool filterWidgetChangedFilter(bool enabled)
Filter changed in filter widget.
Definition: viewbase.cpp:852
virtual void setObjectName(const QString &name)
Set own name and the model's name.
Definition: viewbase.cpp:495
void push_back(const ObjectType &value, bool resize=true)
Push back.
Definition: viewbase.cpp:161
int columnCount() const
Column count.
Definition: viewbase.cpp:393
virtual swift::misc::CStatusMessage validateLoadedJsonData(const ContainerType &data) const
Verify JSON data loaded in swift::gui::views::CViewBaseNonTemplate::loadJson.
Definition: viewbase.cpp:666
virtual ~CViewBase()
Destructor.
Definition: viewbase.h:663
virtual bool reachedResizeThreshold(int containrerSize=-1) const
Skip resizing because of size?
Definition: viewbase.cpp:601
QString toJsonString(QJsonDocument::JsonFormat format=QJsonDocument::Indented, bool selectedOnly=false) const
Convert to JSON string.
Definition: viewbase.cpp:488
virtual swift::misc::CStatusMessage modifyLoadedJsonData(ContainerType &data) const
Modify JSON data loaded in swift::gui::views::CViewBaseNonTemplate::loadJson.
Definition: viewbase.cpp:658
virtual void selectObjects(const ContainerType &selectedObjects)
Select.
Definition: viewbase.cpp:652
const models::CColumns & getColumns() const
The columns.
Definition: viewbase.h:675
virtual void onDoubleClicked(const QModelIndex &index)
Index double clicked.
Definition: viewbase.cpp:886
void setPercentageColumnWidths()
Set the widths based on the column percentages.
Definition: viewbase.cpp:549
CViewBase(QWidget *parent, ModelClass *model=nullptr)
Constructor.
Definition: viewbase.cpp:31
virtual void displayContainerAsJsonPopup(bool selectedOnly)
Display the container as JSON popup.
Definition: viewbase.cpp:769
virtual void performModeBasedResizeToContent()
Perform resizing (no presizing) / non slot method for template.
Definition: viewbase.cpp:608
bool hasFilter() const
Has filter set?
Definition: viewbase.cpp:516
virtual int removeSelectedRows()
Remove selected rows.
Definition: viewbase.cpp:314
virtual bool isDropAllowed() const
Drop allowed?
Definition: viewbase.cpp:427
swift::misc::CWorker * updateContainerAsync(const ContainerType &container, bool sort=true, bool resize=true)
Update whole container in background.
Definition: viewbase.cpp:92
void resort()
Resort ("forced sorting")
Definition: viewbase.cpp:475
virtual void onClicked(const QModelIndex &index)
Remove filter.
Definition: viewbase.cpp:878
virtual void setNoSorting()
Disable sorting.
Definition: viewbase.h:813
virtual void jsonLoadedAndModelUpdated(const ContainerType &data)
In swift::gui::views::CViewBaseNonTemplate::loadJson the view has been updated because of loaded JSON...
Definition: viewbase.cpp:674
virtual swift::misc::CPropertyIndex getSortProperty() const
Sorted by property.
Definition: viewbase.h:816
ObjectType selectedObject() const
Selected object (or default)
Definition: viewbase.cpp:307
const ContainerType & container() const
Access to container.
Definition: viewbase.cpp:200
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
Remove elements matching some particular key/value pair(s).
Definition: viewbase.h:742
virtual bool endsWithEmptyColumn() const
Using void column at the end?
Definition: viewbase.h:825
typename T::ContainerType ContainerType
Model container type.
Definition: viewbase.h:657
virtual void displaySelectedJsonPopup()
Display JSON data.
Definition: viewbase.h:922
QJsonObject toJson(bool selectedOnly=false) const
Convert to JSON.
Definition: viewbase.cpp:481
void replaceOrAdd(K1 key1, V1 value1, const ObjectType &replacement)
Replace elements matching the given element. If there is no match, push the new element on the end.
Definition: viewbase.h:754
virtual void materializeFilter()
Materialize filter.
Definition: viewbase.cpp:367
virtual void presizeOrFullResizeToContents()
Depending on CViewBaseNonTemplate::ResizeSubsetThreshold presize or fully resize.
Definition: viewbase.cpp:342
const ContainerType & containerOrFilteredContainer(bool *filtered=nullptr) const
Full container or cached filtered container as approproiate.
Definition: viewbase.cpp:233
virtual int getSortColumn() const
Get sort column property index.
Definition: viewbase.h:819
virtual bool setSorting(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)
Sorting.
Definition: viewbase.cpp:456
virtual void mouseOverCallback(const QModelIndex &index, bool mouseOver)
From delegate indicating we are in mouse over state.
Definition: viewbase.cpp:638
virtual void drawDropIndicator(bool indicator)
Draw drop indicator.
Definition: viewbase.cpp:646
virtual void copy()
Clipboard cut/copy/paste.
Definition: viewbase.cpp:804
const ModelClass * derivedModel() const
Model.
Definition: viewbase.h:672
int updateSelected(const swift::misc::CVariant &variant, const swift::misc::CPropertyIndex &index)
Update selected objects.
Definition: viewbase.cpp:300
virtual void updateSortIndicator()
Set the sort indicator to the current sort column.
Definition: viewbase.cpp:627
void addContainerTypesAsDropTypes(bool objectType=true, bool containerType=true)
Add the object and container type as accepted drop types CDropBase::addAcceptedMetaTypeId.
Definition: viewbase.cpp:522
virtual void customMenu(menus::CMenuActions &menuActions)
Method creating the menu.
Definition: viewbase.cpp:680
virtual Qt::SortOrder getSortOrder() const
Get sort order.
Definition: viewbase.h:828
virtual void dropEvent(QDropEvent *event)
Definition: viewbase.cpp:434
ObjectType firstSelectedOrDefaultObject() const
First selected, the only one, or default.
Definition: viewbase.cpp:260
int updateContainer(const ContainerType &container, bool sort=true, bool resize=true)
Update whole container.
Definition: viewbase.cpp:38
virtual bool isOrderable() const
Is the corresponding model orderable, swift::misc::models::CListModelBaseNonTemplate::isOrderable.
Definition: viewbase.cpp:407
virtual void paste()
Clipboard cut/copy/paste.
Definition: viewbase.cpp:825
Non templated base class, allows Q_OBJECT and signals / slots to be used.
Definition: viewbase.h:87
virtual bool filterWidgetChangedFilter(bool enabled)=0
Filter changed in filter widget.
virtual void drawDropIndicator(bool indicator)=0
Draw drop indicator.
void setAllowCacheFileFormatJson(bool allow)
Enable/disable cache file format to be loaded as JSON.
Definition: viewbase.h:322
virtual bool reachedResizeThreshold(int containerSize=-1) const =0
Skip resizing because of size?
void hideLoadIndicatorForced()
Parameterless version of hideLoadIndicator.
Definition: viewbase.h:417
ResizeMode
Resize mode, when to resize rows / columns.
Definition: viewbase.h:100
@ PresizeSubset
use a subset of the data to resize
Definition: viewbase.h:104
virtual int removeSelectedRows()=0
Remove selected rows.
virtual void mouseOverCallback(const QModelIndex &index, bool mouseOver)=0
From delegate indicating we are in mouse over state.
void acceptDoubleClickSelection(bool accept)
Accept double click selection.
Definition: viewbase.h:286
void requestNewBackendData()
Load data from backend (where it makes sense)
virtual int performUpdateContainer(const swift::misc::CVariant &variant, bool sort, bool resize)=0
Helper method with template free signature.
virtual void removeFilter()=0
Remove filter.
virtual void onDoubleClicked(const QModelIndex &index)=0
Index double clicked.
virtual void displaySelectedJsonPopup()=0
Display JSON data.
virtual void clearHighlighting()=0
Clear any highlighted objects.
virtual void onClicked(const QModelIndex &index)=0
Index clicked.
bool allowCacheFileFormatJson() const
Allow cache file JSON to be loaded.
Definition: viewbase.h:319
QWidget * getFilterWidget() const
Filter widget if any.
Definition: viewbase.h:268
RowsResizeMode
How rows are resized, makes sense when.
Definition: viewbase.h:111
void loadIndicatorVisibilityChanged(bool visible)
Load indicator's visibility has been changed.
void setSaveFileName(const QString &saveName)
Save file name (optional)
Definition: viewbase.h:316
void modelChanged()
Model bas been changed (means data in view have been changed)
void setSettingsDirectoryIndex(swift::misc::CDirectories::ColumnIndex directoryIndex)
Index of the directory we "remember".
Definition: viewbase.h:333
virtual swift::misc::CStatusMessage loadJson(const QString &directory={})=0
Load JSON.
void requestUpdate()
Ask for new data from currently loaded data.
void setResizeMode(ResizeMode mode)
Set resize mode.
Definition: viewbase.h:213
virtual swift::misc::CStatusMessage loadJsonFile(const QString &filePath)=0
Load JSON file.
void setDisplayAutomatically(bool automatically)
Display automatically (when models are loaded)
Definition: viewbase.h:222
void objectChanged(const swift::misc::CVariant &object, const swift::misc::CPropertyIndex &changedIndex)
Single object was changed in model.
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 jsonLoadCompleted(const swift::misc::CStatusMessage &msg)
JSON data load from disk completed, the swift::misc::CStatusMessage represents the success.
QMap< MenuFlag, menus::CMenuActions > m_menuFlagActions
initialized actions for menu flag (enum)
Definition: viewbase.h:608
virtual void onRowSelected(const QModelIndex &index)=0
Row selected.
virtual bool filterDialogFinished(int status)=0
Filter dialog finished.
QString m_saveFileName
save file name (JSON)
Definition: viewbase.h:609
void objectSelected(const swift::misc::CVariant &object)
Object has been selected.
void modelDataChangedDigest(int count, bool withFilter)
Model data changed,.
virtual void presizeOrFullResizeToContents()=0
Depending on CViewBaseNonTemplate::ResizeSubsetThreshold presize or fully resize.
virtual void updateSortIndicator()=0
Set the sort indicator to the current sort column.
void setAutoResizeFrequency(int updateEveryNthTime)
In.
Definition: viewbase.h:216
virtual swift::misc::CStatusMessage saveJson(bool selectedOnly=false, const QString &directory={})=0
Save JSON.
void setMenu(Menu menuItems)
Set menu items.
Definition: viewbase.h:298
void asyncUpdateFinished()
Asynchronous update finished.
void setForceColumnsToMaxSize(bool force)
Force that columns are extended to full viewport width. Workaround as of https://stackoverflow....
Definition: viewbase.h:327
void settingsChanged()
Settings have been changed.
void modelDataChanged(int count, bool withFilter)
Model data changed.
virtual void paste()=0
Clipboard cut/copy/paste.
virtual void copy()=0
Clipboard cut/copy/paste.
void objectsDeleted(const swift::misc::CVariant &objectContainer)
Objects deleted from model.
void acceptClickSelection(bool accept)
Accept click selection.
Definition: viewbase.h:283
void acceptRowSelection(bool accept)
Accept row selection.
Definition: viewbase.h:289
void objectDoubleClicked(const swift::misc::CVariant &object)
Object has been double clicked.
bool displayAutomatically() const
Display automatically (when models are loaded)
Definition: viewbase.h:219
const QFont & getHorizontalHeaderFont() const
Header (horizontal) font.
Definition: viewbase.h:225
virtual void cut()=0
Clipboard cut/copy/paste.
void objectClicked(const swift::misc::CVariant &object)
Object has been clicked.
Proxy for style of our views.
ColumnIndex
Properties by index.
Definition: directories.h:29
Specialized value object compliant map for variants, based on indexes.
Class template for accessing a specific value in the CSettingsCache.
Streamable status message, e.g.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
Class for doing some arbitrary parcel of work in its own thread.
Definition: worker.h:188
GUI related classes.
Free functions in swift::misc.
#define SWIFT_GUI_EXPORT
Export a class or function from the library.