-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5eb468c
commit 0a06d7d
Showing
11 changed files
with
474 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// A corresponding LICENSE file is located in the root directory of this source tree | ||
// Copyright (C) 2023 BioVault (Biomedical Visual Analytics Unit LUMC - TU Delft) | ||
|
||
#include "AbstractExampleActionsModel.h" | ||
|
||
#include <actions/WidgetAction.h> | ||
|
||
#include <util/Exception.h> | ||
|
||
using namespace mv; | ||
using namespace mv::util; | ||
using namespace mv::gui; | ||
|
||
#ifdef _DEBUG | ||
#define ABSTRACT_EXAMPLE_ACTIONS_MODEL_VERBOSE | ||
#endif | ||
|
||
AbstractExampleActionsModel::ExampleActionItem::ExampleActionItem(const QString& title, mv::gui::WidgetAction* action) : | ||
QStandardItem(title), | ||
QObject(), | ||
_action(action) | ||
{ | ||
setEditable(false); | ||
setDropEnabled(false); | ||
|
||
Q_ASSERT(_action != nullptr); | ||
|
||
if (!_action) | ||
return; | ||
} | ||
|
||
mv::gui::WidgetAction* AbstractExampleActionsModel::ExampleActionItem::getAction() const | ||
{ | ||
return _action; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// A corresponding LICENSE file is located in the root directory of this source tree | ||
// Copyright (C) 2023 BioVault (Biomedical Visual Analytics Unit LUMC - TU Delft) | ||
|
||
#pragma once | ||
|
||
#include <models/StandardItemModel.h> | ||
|
||
#include <QStandardItem> | ||
|
||
namespace mv::gui { | ||
class WidgetAction; | ||
} | ||
|
||
/** | ||
* Abstract example actions model class | ||
* | ||
* @author Thomas Kroes | ||
*/ | ||
class AbstractExampleActionsModel : public mv::StandardItemModel | ||
{ | ||
protected: | ||
|
||
/** Base standard model item class for example widget action */ | ||
class ExampleActionItem : public QStandardItem, public QObject { | ||
public: | ||
|
||
/** | ||
* Construct with pointer to \p action | ||
* @param title Item title | ||
* @param action Pointer to action to display item for | ||
*/ | ||
ExampleActionItem(const QString& title, mv::gui::WidgetAction* action); | ||
|
||
/** | ||
* Get action | ||
* return Pointer to action to display item for | ||
*/ | ||
mv::gui::WidgetAction* getAction() const; | ||
|
||
private: | ||
mv::gui::WidgetAction* _action; /** Pointer to action to display item for */ | ||
}; | ||
|
||
public: | ||
|
||
/** No need for custom constructor */ | ||
using mv::StandardItemModel::StandardItemModel; | ||
|
||
friend class ExampleActionStyledItemDelegate; | ||
friend class ExampleActionsPlugin; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// A corresponding LICENSE file is located in the root directory of this source tree | ||
// Copyright (C) 2023 BioVault (Biomedical Visual Analytics Unit LUMC - TU Delft) | ||
|
||
#include "ExampleActionsFilterModel.h" | ||
|
||
#include <QDebug> | ||
|
||
#ifdef _DEBUG | ||
#define EXAMPLE_ACTIONS_FILTER_MODEL_VERBOSE | ||
#endif | ||
|
||
ExampleActionsFilterModel::ExampleActionsFilterModel(QObject* parent /*= nullptr*/) : | ||
SortFilterProxyModel(parent) | ||
{ | ||
setRecursiveFilteringEnabled(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// A corresponding LICENSE file is located in the root directory of this source tree | ||
// Copyright (C) 2023 BioVault (Biomedical Visual Analytics Unit LUMC - TU Delft) | ||
|
||
#pragma once | ||
|
||
#include <models/SortFilterProxyModel.h> | ||
|
||
/** | ||
* Example actions filter model class | ||
* | ||
* Sorting and filtering model for example actions | ||
* | ||
* @author Thomas Kroes | ||
*/ | ||
class ExampleActionsFilterModel : public mv::SortFilterProxyModel | ||
{ | ||
public: | ||
|
||
/** | ||
* Construct the filter model with \p parent | ||
* @param parent Pointer to parent object | ||
*/ | ||
ExampleActionsFilterModel(QObject* parent = nullptr); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// A corresponding LICENSE file is located in the root directory of this source tree | ||
// Copyright (C) 2023 BioVault (Biomedical Visual Analytics Unit LUMC - TU Delft) | ||
|
||
#include "ExampleActionsTreeModel.h" | ||
|
||
#include <actions/WidgetAction.h> | ||
|
||
#include <util/Exception.h> | ||
|
||
using namespace mv; | ||
using namespace mv::util; | ||
using namespace mv::gui; | ||
|
||
#ifdef _DEBUG | ||
#define EXAMPLE_ACTIONS_TREE_MODEL_VERBOSE | ||
#endif | ||
|
||
ExampleActionsTreeModel::ExampleActionsTreeModel(QObject* parent /*= nullptr*/) : | ||
AbstractExampleActionsModel(parent) | ||
{ | ||
setColumnCount(static_cast<int>(Column::Count)); | ||
|
||
appendRow(CategoryRow("Color", { | ||
{ "Color action", "For picking colors", "mv::gui::ColorAction" }, | ||
{ "1D Color map action", "For configuring one-dimensional color maps", "mv::gui::ColorMap1DAction" }, | ||
{ "2D Color map action", "For configuring two-dimensional color maps", "mv::gui::ColorMap2DAction" } | ||
})); | ||
|
||
appendRow(CategoryRow("File", { | ||
{ "File picker", "For picking file location", "mv::gui::FilePickerAction" }, | ||
{ "Directory picker", "For picking directories", "mv::gui::DirectoryPickerAction" } | ||
})); | ||
|
||
appendRow(CategoryRow("Grouping", { | ||
{ "Horizontal group", "For laying out actions horizontally", "mv::gui::HorizontalGroupAction" }, | ||
{ "Vertical group", "For laying out actions vertically", "mv::gui::VerticalGroupAction" }, | ||
{ "Groups", "Vertical groups accordion action", "mv::gui::GroupsAction" }, | ||
{ "Horizontal toolbar", "Horizontal group action that changes the state of action based on the available width ", "mv::gui::HorizontalToolbarAction" }, | ||
{ "Stretch", "Adds stretch to a group action", "mv::gui::StretchAction" } | ||
})); | ||
|
||
appendRow(CategoryRow("Miscellaneous", { | ||
{ "Dataset picker", "For picking datasets", "mv::gui::DatasetPickerAction" } | ||
})); | ||
} | ||
|
||
QVariant ExampleActionsTreeModel::headerData(int section, Qt::Orientation orientation, int role /*= Qt::DisplayRole*/) const | ||
{ | ||
switch (static_cast<Column>(section)) | ||
{ | ||
case Column::Name: | ||
return "Name"; | ||
|
||
case Column::Description: | ||
return "Description"; | ||
|
||
case Column::ClassName: | ||
return "Class name"; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
ExampleActionsTreeModel::CategoryRow::CategoryRow(const QString& category, const QList<QStringList>& actions) : QList<QStandardItem*>() | ||
{ | ||
auto categoryItem = new QStandardItem(category); | ||
|
||
for (const auto& action : actions) { | ||
QList<QStandardItem*> items; | ||
|
||
try { | ||
for (const auto& string : action) { | ||
|
||
const auto metaType = action[2]; | ||
const auto metaTypeId = QMetaType::type(metaType.toLatin1()); | ||
const auto metaObject = QMetaType::metaObjectForType(metaTypeId); | ||
|
||
if (!metaObject) | ||
throw std::runtime_error(QString("Meta object type '%1' is not known. Did you forget to register the action correctly with Qt meta object system? See ToggleAction.h for an example.").arg(metaType).toLatin1()); | ||
|
||
auto metaObjectInstance = metaObject->newInstance(Q_ARG(QObject*, nullptr), Q_ARG(QString, QString("Example%1").arg(metaType))); | ||
auto exampleAction = dynamic_cast<WidgetAction*>(metaObjectInstance); | ||
|
||
if (!exampleAction) | ||
throw std::runtime_error(QString("Unable to create a new instance of type '%1'").arg(metaType).toLatin1()); | ||
|
||
items << new ExampleActionItem(string, exampleAction); | ||
} | ||
} | ||
catch (std::exception& e) | ||
{ | ||
exceptionMessageBox("Unable to load example action:", e); | ||
} | ||
catch (...) | ||
{ | ||
exceptionMessageBox("Unable to load example action:"); | ||
} | ||
|
||
categoryItem->appendRow(items); | ||
} | ||
|
||
append(categoryItem); | ||
} |
Oops, something went wrong.