Skip to content

Commit

Permalink
Finished with refactor, compiles and runs ok
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasKroes committed Dec 11, 2024
1 parent 39003e2 commit 325dbba
Show file tree
Hide file tree
Showing 21 changed files with 269 additions and 270 deletions.
4 changes: 2 additions & 2 deletions ManiVault/src/private/NewProjectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "NewProjectDialog.h"

#include "StartPageAction.h"
#include "PageAction.h"

#include <AbstractWorkspaceManager.h>

Expand Down Expand Up @@ -55,7 +55,7 @@ NewProjectDialog::NewProjectDialog(QWidget* parent /*= nullptr*/) :
for (const auto workspaceLocation : workspaces().getWorkspaceLocations(WorkspaceLocation::Types(WorkspaceLocation::Type::BuiltIn))) {
Workspace workspace(workspaceLocation.getFilePath());

StartPageAction fromWorkspaceStartPageAction(workspaces().getIcon(), QFileInfo(workspaceLocation.getFilePath()).baseName(), workspaceLocation.getFilePath(), workspace.getDescriptionAction().getString(), workspaceLocation.getFilePath(), [this, workspaceLocation]() -> void {
PageAction fromWorkspaceStartPageAction(workspaces().getIcon(), QFileInfo(workspaceLocation.getFilePath()).baseName(), workspaceLocation.getFilePath(), workspace.getDescriptionAction().getString(), workspaceLocation.getFilePath(), [this, workspaceLocation]() -> void {
projects().newProject(workspaceLocation.getFilePath());

QDialog::accept();
Expand Down
4 changes: 2 additions & 2 deletions ManiVault/src/private/NewProjectDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include "StartPageActionsWidget.h"
#include "PageActionsWidget.h"

#include <QDialog>

Expand Down Expand Up @@ -36,6 +36,6 @@ class NewProjectDialog final : public QDialog
}

private:
StartPageActionsWidget _workspacesWidget; /** Actions widget for selecting a workspace and creating a project */
PageActionsWidget _workspacesWidget; /** Actions widget for selecting a workspace and creating a project */
mv::gui::TriggerAction _cancelAction; /** Action for exiting the dialog without creating a new project */
};
38 changes: 19 additions & 19 deletions ManiVault/src/private/PageAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// 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 "StartPageAction.h"
#include "StartPageActionsModel.h"
#include "PageAction.h"
#include "PageActionsModel.h"

bool StartPageAction::compactView = false;
bool PageAction::compactView = false;

StartPageAction::StartPageAction(const QIcon& icon, const QString& title, const QString& subtitle, const QString& description, const QString& tooltip, const ClickedCallback& clickedCallback) :
PageAction::PageAction(const QIcon& icon, const QString& title, const QString& subtitle, const QString& description, const QString& tooltip, const ClickedCallback& clickedCallback) :
_icon(icon),
_title(title),
_subtitle(subtitle),
Expand All @@ -17,30 +17,30 @@ StartPageAction::StartPageAction(const QIcon& icon, const QString& title, const
{
}

StartPageAction::StartPageAction(const QModelIndex& index)
PageAction::PageAction(const QModelIndex& index)
{
setEditorData(index);
}

void StartPageAction::setEditorData(const QModelIndex& index)
void PageAction::setEditorData(const QModelIndex& index)
{
setIcon(index.siblingAtColumn(static_cast<int>(StartPageActionsModel::Column::Icon)).data(Qt::UserRole + 1).value<QIcon>());
setTitle(index.siblingAtColumn(static_cast<int>(StartPageActionsModel::Column::Title)).data(Qt::EditRole).toString());
setDescription(index.siblingAtColumn(static_cast<int>(StartPageActionsModel::Column::Description)).data(Qt::EditRole).toString());
setComments(index.siblingAtColumn(static_cast<int>(StartPageActionsModel::Column::Comments)).data(Qt::EditRole).toString());
setTags(index.siblingAtColumn(static_cast<int>(StartPageActionsModel::Column::Tags)).data(Qt::EditRole).toStringList());
setSubtitle(index.siblingAtColumn(static_cast<int>(StartPageActionsModel::Column::Subtitle)).data(Qt::EditRole).toString());
setMetaData(index.siblingAtColumn(static_cast<int>(StartPageActionsModel::Column::MetaData)).data(Qt::EditRole).toString());
setPreviewImage(index.siblingAtColumn(static_cast<int>(StartPageActionsModel::Column::PreviewImage)).data(Qt::UserRole + 1).value<QImage>());
setContributors(index.siblingAtColumn(static_cast<int>(StartPageActionsModel::Column::Contributors)).data(Qt::UserRole + 1).toStringList());
setIcon(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::Icon)).data(Qt::UserRole + 1).value<QIcon>());
setTitle(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::Title)).data(Qt::EditRole).toString());
setDescription(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::Description)).data(Qt::EditRole).toString());
setComments(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::Comments)).data(Qt::EditRole).toString());
setTags(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::Tags)).data(Qt::EditRole).toStringList());
setSubtitle(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::Subtitle)).data(Qt::EditRole).toString());
setMetaData(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::MetaData)).data(Qt::EditRole).toString());
setPreviewImage(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::PreviewImage)).data(Qt::UserRole + 1).value<QImage>());
setContributors(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::Contributors)).data(Qt::UserRole + 1).toStringList());
}

bool StartPageAction::isCompactView()
bool PageAction::isCompactView()
{
return StartPageAction::compactView;
return PageAction::compactView;
}

void StartPageAction::setCompactView(bool compactView)
void PageAction::setCompactView(bool compactView)
{
StartPageAction::compactView = compactView;
PageAction::compactView = compactView;
}
14 changes: 6 additions & 8 deletions ManiVault/src/private/PageAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
#include <QIcon>
#include <QImage>
#include <QList>
#include <QModelIndex>
#include <QString>
#include <QStringList>

#include <functional>

/**
* Start page action
* Page action
*
* Container class for start page action.
* Container class for page action.
*
* @author Thomas Kroes
*/
class StartPageAction final
class PageAction final
{
public:

Expand All @@ -37,13 +35,13 @@ class StartPageAction final
* @param tooltip Action tooltip
* @param clickedCallback Callback function that is called when the action row is clicked
*/
StartPageAction(const QIcon& icon, const QString& title, const QString& subtitle, const QString& description, const QString& tooltip, const ClickedCallback& clickedCallback);
PageAction(const QIcon& icon, const QString& title, const QString& subtitle, const QString& description, const QString& tooltip, const ClickedCallback& clickedCallback);

/**
* Construct from model \p index
* @param index Model index to set editor data from
*/
StartPageAction(const QModelIndex& index);
PageAction(const QModelIndex& index);

public: // Getters and setters

Expand Down Expand Up @@ -118,4 +116,4 @@ class StartPageAction final
static bool compactView;
};

using StartPageActions = QList<StartPageAction>;
using PageActions = QList<PageAction>;
37 changes: 12 additions & 25 deletions ManiVault/src/private/PageActionDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,38 @@
// 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 "StartPageActionDelegate.h"
#include "StartPageActionDelegateEditorWidget.h"
#include "StartPageAction.h"

#include <QCoreApplication>
#include "PageActionDelegate.h"
#include "PageActionDelegateEditorWidget.h"
#include "PageAction.h"

#ifdef _DEBUG
#define START_PAGE_ACTION_DELEGATE_VERBOSE
#define PAGE_ACTION_DELEGATE_VERBOSE
#endif

StartPageActionDelegate::StartPageActionDelegate(QObject* parent /*= nullptr*/) :
PageActionDelegate::PageActionDelegate(QObject* parent /*= nullptr*/) :
QStyledItemDelegate(parent)
{
}

QSize StartPageActionDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
QSize PageActionDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
/*
QScopedPointer<StartPageActionDelegateEditorWidget> widget(new StartPageActionDelegateEditorWidget);
widget->setAttribute(Qt::WA_DontShowOnScreen);
QCoreApplication::processEvents();
qDebug() << QSize(option.rect.width(), widget->sizeHint().height());
*/

// Hard-coded for optimization purposes
return StartPageAction::isCompactView() ? QSize(0, 26) : QSize(0, 43); // 43
return PageAction::isCompactView() ? QSize(0, 26) : QSize(0, 43);
}

QWidget* StartPageActionDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
QWidget* PageActionDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
Q_UNUSED(option)
Q_UNUSED(index)

return new StartPageActionDelegateEditorWidget(parent);
return new PageActionDelegateEditorWidget(parent);
}

void StartPageActionDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
void PageActionDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
qobject_cast<StartPageActionDelegateEditorWidget*>(editor)->setEditorData(index);
qobject_cast<PageActionDelegateEditorWidget*>(editor)->setEditorData(index);
}

void StartPageActionDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
void PageActionDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
Q_UNUSED(index)

Expand Down
34 changes: 27 additions & 7 deletions ManiVault/src/private/PageActionDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
#include <QStyledItemDelegate>

/**
* Delegate class
* Page delegate class
*
* Delegate class for custom start page action display in a view.
* For custom page action display in a view.
*
* @author Thomas Kroes
*/
class StartPageActionDelegate : public QStyledItemDelegate
class PageActionDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:

/**
* Construct delegate with \p parent object
* Construct delegate with pointer to \p parent object
* @param parent Pointer to parent object
*/
StartPageActionDelegate(QObject* parent = nullptr);
PageActionDelegate(QObject* parent = nullptr);

/**
* Gives the size hint for \p option and model \p index
Expand All @@ -32,10 +32,30 @@ class StartPageActionDelegate : public QStyledItemDelegate
*/
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;

/**
* Create custom delegate widget
* @param parent Pointer to parent widget
* @param option Style view options
* @param index Model index
* @return Pointer to widget
*/
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void setEditorData(QWidget* editor, const QModelIndex& index) const;

/**
* Set \p editor data for model \p index
* @param editor Pointer to editor
* @param index Model index
*/
void setEditorData(QWidget* editor, const QModelIndex& index) const override;

/**
* Override update editor geometry
* @param editor Pointer to editor widget
* @param option Style view options
* @param index Model index
*/
void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;

private:
static std::int32_t height;
static std::int32_t height; /** Height of the delegate widget */
};
Loading

0 comments on commit 325dbba

Please sign in to comment.