6#ifndef SWIFT_GUI_VIEWBASE_H
7#define SWIFT_GUI_VIEWBASE_H
11#include <QAbstractItemView>
14#include <QJsonDocument>
17#include <QModelIndexList>
25#include "gui/menus/menuaction.h"
93 friend class CViewBaseItemDelegate;
94 friend class CViewBaseProxyStyle;
147 Q_DECLARE_FLAGS(Menu, MenuFlag)
173 Qt::SortOrder order =
Qt::AscendingOrder) = 0;
177 Qt::SortOrder order =
Qt::AscendingOrder) = 0;
198 virtual
void allowDragDrop(
bool allowDrag,
bool allowDrop,
bool allowDropJsonFile = false) = 0;
232 int getHorizontalHeaderFontHeight()
const;
235 bool hasSelection()
const;
238 QModelIndexList selectedRows()
const;
241 virtual QModelIndexList unselectedRows()
const;
247 int selectedRowCount()
const;
250 int unselectedRowCount()
const;
253 bool hasSingleSelectedRow()
const;
256 bool hasMultipleSelectedRows()
const;
259 bool allowsMultipleSelectedRows()
const;
262 bool isCurrentlyAllowingMultipleRowSelections()
const;
277 void enableLoadIndicator(
bool enable);
280 bool isShowingLoadIndicator()
const;
292 void menuRemoveItems(Menu menusToRemove);
295 void menuAddItems(Menu menusToAdd);
307 QWidget *mainApplicationWindowWidget()
const;
403 std::chrono::milliseconds timeout = std::chrono::milliseconds { 0 },
404 bool processEvents =
true);
407 int showLoadIndicatorWithTimeout(std::chrono::milliseconds timeout = std::chrono::milliseconds { 0 },
408 bool processEvents =
true);
411 void onModelChanged();
414 void hideLoadIndicator(
int loadingId = -1);
563 void triggerReload();
566 void triggerReloadFromBackend();
611 IndexDirLastViewJsonOrDefault;
622 void removeSelectedRowsChecked();
625 void toggleAutoDisplay();
628 void customMenuRequested(
const QPoint &pos);
631 void onLoadIndicatorTimedOut();
634 void toggleResizeMode(
bool checked);
637 void toggleWordWrap(
bool checked);
641 void setFilterWidgetImpl(
QWidget *filterWidget);
643 Q_DECLARE_OPERATORS_FOR_FLAGS(swift::gui::views::CViewBaseNonTemplate::Menu)
744 template <
class K0,
class V0,
class... KeysValues>
745 int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
752 int r = cp.removeIf(k0, v0, keysValues...);
762 template <
class K1,
class V1>
766 cp.replaceOrAdd(key1, value1, replacement);
790 void clear()
override;
802 void allowDragDrop(
bool allowDrag,
bool allowDrop,
bool allowDropJsonFile =
false)
override;
854 bool selectedOnly =
false)
const;
875 m_model->setDropActions(dropActions);
919 void copy()
override;
925 void paste()
override;
The QProgressIndicator class lets an application display a progress indicator to show that a lengthy ...
COverlayMessagesTableView(QWidget *parent=nullptr)
Constructor.
Allow to get and select objects.
void sort()
Sort if columns or order changed.
ContainerType unselectedObjects() const
Unselected objects.
bool filterDialogFinished(int status)
Filter dialog finished.
int rowOf(const ObjectType &obj) const
The row of the given object.
void cut()
Clipboard cut/copy/paste.
int performUpdateContainer(const swift::misc::CVariant &variant, bool sort, bool resize)
Helper method with template free signature.
void standardInit(ModelClass *model=nullptr)
Standard initialization.
swift::misc::CStatusMessage loadJsonFile(const QString &fileName)
Method creating the menu.
void initAsOrderable()
Init so items can be ordered, includes enabling drag and drop.
bool acceptDrop(const QMimeData *mimeData) const
Accept drop data?
QList< int > rowsOf(const ContainerType &container) const
The rows of the given objects.
void removeFilter()
Remove filter.
void onRowSelected(const QModelIndex &index)
Row selected.
void setTabWidgetViewText(QTabWidget *tw, int index)
Set a tab widget text based on row count, filter etc.
swift::misc::CStatusMessage loadJson(const QString &directory={})
Load JSON.
void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile=false)
Allow to drag and/or drop value objects.
void clearHighlighting()
Clear any highlighted objects.
bool isEmpty() const
Empty?
const models::CColumns & getColumns() const
The columns.
void updateContainerMaybeAsync(const ContainerType &container, bool sort=true, bool resize=true)
Based on size call sync / async update.
void insert(const ObjectType &value, bool resize=true)
Insert.
ContainerType selectedObjects() const
Selected objects.
swift::misc::CStatusMessage saveJson(bool selectedOnly=false, const QString &directory={})
Save JSON.
swift::misc::CPropertyIndex getSortProperty() const
Sorted by property.
ModelClass * m_model
corresponding model
void setSortIndicator()
Set the search indicator based on model.
int rowCount() const
Elements in container.
const ObjectType & at(const QModelIndex &index) const
Value object at.
void setDropActions(Qt::DropActions dropActions)
Drop actions.
void displayJsonPopup()
Display JSON data.
typename T::ObjectType ObjectType
Model container element type.
void sortByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)
Sort by index.
bool filterWidgetChangedFilter(bool enabled)
Filter changed in filter widget.
virtual void setObjectName(const QString &name)
Set own name and the model's name.
void push_back(const ObjectType &value, bool resize=true)
Push back.
int columnCount() const
Column count.
virtual swift::misc::CStatusMessage validateLoadedJsonData(const ContainerType &data) const
Verify JSON data loaded in swift::gui::views::CViewBaseNonTemplate::loadJson.
bool reachedResizeThreshold(int containrerSize=-1) const
Skip resizing because of size?
QString toJsonString(QJsonDocument::JsonFormat format=QJsonDocument::Indented, bool selectedOnly=false) const
Convert to JSON string.
virtual swift::misc::CStatusMessage modifyLoadedJsonData(ContainerType &data) const
Modify JSON data loaded in swift::gui::views::CViewBaseNonTemplate::loadJson.
void selectObjects(const ContainerType &selectedObjects)
Select.
void onDoubleClicked(const QModelIndex &index)
Index double clicked.
void setPercentageColumnWidths()
Set the widths based on the column percentages.
void displaySelectedJsonPopup()
Display JSON data.
bool endsWithEmptyColumn() const
Using void column at the end?
CViewBase(QWidget *parent, ModelClass *model=nullptr)
Constructor.
virtual void displayContainerAsJsonPopup(bool selectedOnly)
Display the container as JSON popup.
void performModeBasedResizeToContent()
Perform resizing (no presizing) / non slot method for template.
bool hasFilter() const
Has filter set?
Qt::SortOrder getSortOrder() const
Get sort order.
int removeSelectedRows()
Remove selected rows.
bool isDropAllowed() const
Drop allowed?
swift::misc::CWorker * updateContainerAsync(const ContainerType &container, bool sort=true, bool resize=true)
Update whole container in background.
void resort()
Resort ("forced sorting").
void onClicked(const QModelIndex &index)
Remove filter.
virtual void jsonLoadedAndModelUpdated(const ContainerType &data)
In swift::gui::views::CViewBaseNonTemplate::loadJson the view has been updated because of loaded JSON...
const ModelClass * derivedModel() const
Model.
ObjectType selectedObject() const
Selected object (or default).
const ContainerType & container() const
Access to container.
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
Remove elements matching some particular key/value pair(s).
typename T::ContainerType ContainerType
Model container type.
QJsonObject toJson(bool selectedOnly=false) const
Convert to JSON.
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.
void materializeFilter()
Materialize filter.
void presizeOrFullResizeToContents()
Depending on CViewBaseNonTemplate::ResizeSubsetThreshold presize or fully resize.
int getSortColumn() const
Get sort column property index.
const ContainerType & containerOrFilteredContainer(bool *filtered=nullptr) const
Full container or cached filtered container as approproiate.
bool setSorting(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)
Sorting.
void mouseOverCallback(const QModelIndex &index, bool mouseOver)
From delegate indicating we are in mouse over state.
void takeFilterOwnership(std::unique_ptr< models::IModelFilter< ContainerType > > &filter)
Set filter and take ownership, any previously set filter will be destroyed.
void drawDropIndicator(bool indicator)
Draw drop indicator.
ModelClass * derivedModel()
Model.
void copy()
Clipboard cut/copy/paste.
int updateSelected(const swift::misc::CVariant &variant, const swift::misc::CPropertyIndex &index)
Update selected objects.
void setNoSorting()
Disable sorting.
bool hasValidSortColumn() const
Has valid sort column?
void updateSortIndicator()
Set the sort indicator to the current sort column.
void addContainerTypesAsDropTypes(bool objectType=true, bool containerType=true)
Add the object and container type as accepted drop types CDropBase::addAcceptedMetaTypeId.
void customMenu(menus::CMenuActions &menuActions)
Method creating the menu.
void dropEvent(QDropEvent *event)
ObjectType firstSelectedOrDefaultObject() const
First selected, the only one, or default.
int updateContainer(const ContainerType &container, bool sort=true, bool resize=true)
Update whole container.
bool isOrderable() const
Is the corresponding model orderable, swift::misc::models::CListModelBaseNonTemplate::isOrderable.
void paste()
Clipboard cut/copy/paste.
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
bool m_dropIndicator
drop indicator
components::CTextEditDialog * textEditDialog()
Init text edit dialog if required and return pointer to it.
virtual void drawDropIndicator(bool indicator)=0
Draw drop indicator.
static constexpr int ResizeSubsetThreshold
When to use pre-sizing with random elements.
void rowsResizeModeToInteractive()
Init as interactive, as this allows manually resizing.
bool m_acceptRowSelection
selection changed
bool m_forceStretchLastColumnWhenResized
a small table might (few columns) fail stretching, force again
void hideLoadIndicator(int loadingId=-1)
Hide loading indicator.
void setAllowCacheFileFormatJson(bool allow)
Enable/disable cache file format to be loaded as JSON.
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...
void hideLoadIndicatorForced()
Parameterless version of hideLoadIndicator.
Menu m_menus
Default menu settings.
ResizeMode
Resize mode, when to resize rows / columns.
@ PresizeSubset
use a subset of the data to resize
@ ResizingAlways
always resize
@ ResizingOnce
only one time
@ ResizingAuto
resizing when below threshold,
virtual void resizeToContents()
Resize to contents, strategy depends on container size.
SelectionMode m_originalSelectionMode
Selection mode set.
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.
int getPresizeRandomElementsSize(int containerSize=-1) const
Calculate presize count.
virtual Qt::SortOrder getSortOrder() const =0
Get sort order.
void acceptDoubleClickSelection(bool accept)
Accept double click selection.
void requestNewBackendData()
Load data from backend (where it makes sense).
ResizeMode m_resizeMode
mode
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 setNoSorting()=0
Disable sorting.
virtual QString getRememberedLastJsonDirectory() const
JSON directory.
virtual void onDoubleClicked(const QModelIndex &index)=0
Index double clicked.
void showVerticalHeader()
Vertical header.
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.
RowsResizeMode
How rows are resized, makes sense when.
virtual bool acceptDrop(const QMimeData *mimeData) const =0
Accept drop data?
void loadIndicatorVisibilityChanged(bool visible)
Load indicator's visibility has been changed.
void setSaveFileName(const QString &saveName)
Save file name (optional).
bool m_displayAutomatically
display directly when loaded
void modelChanged()
Model bas been changed (means data in view have been changed).
virtual bool hasValidSortColumn() const =0
Has valid sort column?
void loadJsonAction()
Load JSON for action/menu, void return signatur.
ResizeMode getResizeMode() const
Resize mode.
void setSettingsDirectoryIndex(swift::misc::CDirectories::ColumnIndex directoryIndex)
Index of the directory we "remember".
int m_skipResizeThreshold
when to skip resize (rows count)
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
virtual int getSortColumn() const =0
Get sort column property index.
bool m_acceptClickSelection
clicked
RowsResizeMode m_rowResizeMode
row resize mode for row height
void requestUpdate()
Ask for new data from currently loaded data.
void setResizeMode(ResizeMode mode)
Set resize mode.
virtual swift::misc::CStatusMessage loadJsonFile(const QString &filePath)=0
Load JSON file.
virtual bool endsWithEmptyColumn() const =0
Using void column at the end?
void setDisplayAutomatically(bool automatically)
Display automatically (when models are loaded).
bool m_enabledLoadIndicator
loading indicator enabled/disabled
const QFont & getHorizontalHeaderFont() const
Header (horizontal) font.
void saveJsonAction()
Save JSON for action/menu, void return signatur.
void saveSelectedJsonAction()
Save JSON for action/menu, void return signatur.
void resizeEvent(QResizeEvent *event)
void objectChanged(const swift::misc::CVariant &object, const swift::misc::CPropertyIndex &changedIndex)
Single object was changed in model.
virtual void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile=false)=0
Allow to drag and/or drop value objects.
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.
void dragEnterEvent(QDragEnterEvent *event)
int m_resizeAutoNthTime
with ResizeAuto, resize every n-th time
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)
std::chrono::milliseconds m_loadIndicatorTimeoutDefault
default time for timeout
virtual void clear()=0
Clear data.
bool m_acceptDoubleClickSelection
double clicked
virtual void sortByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)=0
Sort by index.
virtual void onRowSelected(const QModelIndex &index)=0
Row selected.
void rowsResizeModeToContent()
Resize mode to content.
void dropEvent(QDropEvent *event)
virtual bool filterDialogFinished(int status)=0
Filter dialog finished.
QString m_saveFileName
save file name (JSON)
menus::CFontMenu * m_fontMenu
font menu if applicable
void centerLoadIndicator()
Center / re-center load indicator.
virtual bool isResizeConditionMet(int containerSize=-1) const
Resize or skip resize?
virtual bool isDropAllowed() const =0
Drop allowed?
swift::misc::CSettingReadOnly< settings::TGeneralGui > m_guiSettings
general GUI settings
~CViewBaseNonTemplate()
Destructor.
void objectSelected(const swift::misc::CVariant &object)
Object has been selected.
virtual bool isEmpty() const =0
Empty?
void modelDataChangedDigest(int count, bool withFilter)
Model data changed,.
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
virtual swift::misc::CPropertyIndex getSortProperty() const =0
Sorted by property.
virtual void presizeOrFullResizeToContents()=0
Depending on CViewBaseNonTemplate::ResizeSubsetThreshold presize or fully resize.
virtual void customMenu(menus::CMenuActions &menuActions)
Method creating the menu.
static constexpr int ASyncRowsCountThreshold
When (row count) to use asynchronous updates.
bool m_allowCacheFileJson
allow Cache format JSON to be loaded
virtual void updateSortIndicator()=0
Set the sort indicator to the current sort column.
void setAutoResizeFrequency(int updateEveryNthTime)
In.
virtual swift::misc::CStatusMessage saveJson(bool selectedOnly=false, const QString &directory={})=0
Save JSON.
virtual bool setSorting(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)=0
Sorting.
void setMenu(Menu menuItems)
Set menu items.
QWidget * getFilterWidget() const
Filter widget if any.
void rowsResizeModeBasedOnThreshold(int elements)
Set content/interactive mode based on ResizeRowsToContentThreshold.
void asyncUpdateFinished()
Asynchronous update finished.
void setForceColumnsToMaxSize(bool force)
Force that columns are extended to full viewport width. Workaround as of https://stackoverflow....
static constexpr int ResizeRowsToContentThreshold
When to use rows resizing (which is slow).
bool isShowingLoadIndicator
Load indicator property allows using in stylesheet.
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
bool setParentDockWidgetInfoArea(swift::gui::CDockWidgetInfoArea *parentDockableWidget)
Corresponding dockable widget in info area.
void init()
Init default values.
virtual void paste()=0
Clipboard cut/copy/paste.
void displayFilterDialog()
Display the filter dialog.
menus::IMenuDelegate * m_menu
custom menu if any
void selectAll()
Select all rows.
swift::misc::CSetting< swift::misc::settings::TDirectorySettings > m_dirSettings
directory for load/save
void setSingleSelection()
Change selection modes.
menus::CMenuActions initMenuActions(MenuFlag menu)
Init menu actions.
bool m_forceColumnsToMaxSize
force that columns are extended to full viewport width
virtual void copy()=0
Clipboard cut/copy/paste.
components::CTextEditDialog * m_textEditDialog
text edit dialog
void objectsDeleted(const swift::misc::CVariant &objectContainer)
Objects deleted from model.
void dragLeaveEvent(QDragLeaveEvent *event)
@ MenuCanStashModels
stash models
@ MenuDisplayAutomatically
allow to switch display automatically
@ MenuClear
allow clearing the view via menu
@ MenuFont
font related menu (size)
@ MenuDisplayAutomaticallyAndRefresh
should come together
@ MenuRefresh
allow refreshing the view via menu
@ MenuOrderable
items can be ordered (if container is swift::misc::IOrderableList
@ MenuHighlightStashed
highlight stashed models
@ MenuCut
cut (for copy/paste)
@ MenuCopy
copy (for copy/paste)
@ MenuBackend
allow to request data from backend
@ MenuRemoveSelectedRows
allow to remove selected rows
@ MenuPaste
paste (for copy/paste)
@ MenuMaterializeFilter
materialize filter (filtered data become model data)
@ MenuDisableModelsTemp
temp.
@ MenuFilter
filter can be opened
@ MenuToggleSelectionMode
allow to toggle selection mode
void acceptClickSelection(bool accept)
Accept click selection.
void acceptRowSelection(bool accept)
Accept row selection.
Menu getMenu() const
Menus.
void dragMoveEvent(QDragMoveEvent *event)
void objectDoubleClicked(const swift::misc::CVariant &object)
Object has been double clicked.
virtual int rowCount() const =0
Elements in container.
bool displayAutomatically() const
Display automatically (when models are loaded).
bool m_enableDeleteSelectedRows
selected rows can be deleted
CViewBaseNonTemplate(QWidget *parent)
Constructor.
virtual void cut()=0
Clipboard cut/copy/paste.
virtual bool isOrderable() const =0
Is the corresponding model orderable, swift::misc::models::CListModelBaseNonTemplate::isOrderable.
void objectClicked(const swift::misc::CVariant &object)
Object has been clicked.
ColumnIndex
Properties by index.
Specialized value object compliant map for variants, based on indexes.
Class template for accessing a specific value in the CSettingsCache.
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...
Class for doing some arbitrary parcel of work in its own thread.
High level reusable GUI components.
Filter to search data sets.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.
virtual bool event(QEvent *event) override
QAbstractItemModel * model() const const
QObject * parent() const const
void setWordWrap(bool on)
#define SWIFT_GUI_EXPORT
Export a class or function from the library.