Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sealtk/noaa/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sealtk_add_library(sealtk::noaa_gui
NotesDelegate.cpp
Player.cpp
Resources.cpp
TrackScoreDelegate.cpp
TrackTypeDelegate.cpp
Window.cpp
SEALTKBranding.qrc
Expand All @@ -19,6 +20,7 @@ sealtk_add_library(sealtk::noaa_gui
NotesDelegate.hpp
Player.hpp
Resources.hpp
TrackScoreDelegate.hpp
TrackTypeDelegate.hpp
Window.hpp

Expand Down
79 changes: 79 additions & 0 deletions sealtk/noaa/gui/TrackScoreDelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* This file is part of SEAL-TK, and is distributed under the OSI-approved BSD
* 3-Clause License. See top-level LICENSE file or
* https://github.com/Kitware/seal-tk/blob/master/LICENSE for details. */

#include <sealtk/noaa/gui/TrackScoreDelegate.hpp>

#include <sealtk/core/DataModelTypes.hpp>

#include <QDoubleSpinBox>

namespace sealtk
{

namespace noaa
{

namespace gui
{

// ----------------------------------------------------------------------------
TrackScoreDelegate::TrackScoreDelegate(QObject* parent)
: qtDoubleSpinBoxDelegate{parent}
{
this->setRange(0.0, 1.0);
this->setPrecision(5);
}

// ----------------------------------------------------------------------------
TrackScoreDelegate::~TrackScoreDelegate()
{
}

//-----------------------------------------------------------------------------
QWidget* TrackScoreDelegate::createEditor(
QWidget* parent, QStyleOptionViewItem const& item,
QModelIndex const& index) const
{
auto* const editor =
static_cast<QDoubleSpinBox*>(
qtDoubleSpinBoxDelegate::createEditor(parent, item, index));

editor->setFrame(false);
editor->setSingleStep(0.01);
editor->setAlignment(Qt::AlignRight | Qt::AlignVCenter);

return editor;
}

// ----------------------------------------------------------------------------
void TrackScoreDelegate::setEditorData(
QWidget* editor, QModelIndex const& index) const
{
if (auto* const model = index.model())
{
auto const& data = model->data(index, core::ClassificationScoreRole);
auto* const spin = qobject_cast<QDoubleSpinBox*>(editor);
spin->setValue(data.toDouble());
}
}

// ----------------------------------------------------------------------------
void TrackScoreDelegate::setModelData(
QWidget* editor, QAbstractItemModel* model, QModelIndex const& index) const
{
QDoubleSpinBox* spin = qobject_cast<QDoubleSpinBox*>(editor);
spin->interpretText();

auto const& typeData = model->data(index, core::ClassificationTypeRole);
auto const& newScore = spin->value();

auto newClassification = QVariantHash{{typeData.toString(), newScore}};
model->setData(index, newClassification, core::ClassificationRole);
}

} // namespace gui

} // namespace noaa

} // namespace sealtk
46 changes: 46 additions & 0 deletions sealtk/noaa/gui/TrackScoreDelegate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* This file is part of SEAL-TK, and is distributed under the OSI-approved BSD
* 3-Clause License. See top-level LICENSE file or
* https://github.com/Kitware/seal-tk/blob/master/LICENSE for details. */

#ifndef sealtk_noaa_gui_TrackScoreDelegate_hpp
#define sealtk_noaa_gui_TrackScoreDelegate_hpp

#include <sealtk/noaa/gui/Export.h>

#include <qtDoubleSpinBoxDelegate.h>

namespace sealtk
{

namespace noaa
{

namespace gui
{

class SEALTK_NOAA_GUI_EXPORT TrackScoreDelegate
: public qtDoubleSpinBoxDelegate
{
Q_OBJECT

public:
explicit TrackScoreDelegate(QObject* parent = nullptr);
~TrackScoreDelegate() override;

QWidget* createEditor(
QWidget* parent, QStyleOptionViewItem const& item,
QModelIndex const& index) const override;
void setEditorData(
QWidget* editor, QModelIndex const& index) const override;
void setModelData(
QWidget* editor, QAbstractItemModel* model,
QModelIndex const& index) const override;
};

} // namespace gui

} // namespace noaa

} // namespace sealtk

#endif
25 changes: 21 additions & 4 deletions sealtk/noaa/gui/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sealtk/noaa/gui/About.hpp>
#include <sealtk/noaa/gui/NotesDelegate.hpp>
#include <sealtk/noaa/gui/Player.hpp>
#include <sealtk/noaa/gui/TrackScoreDelegate.hpp>
#include <sealtk/noaa/gui/TrackTypeDelegate.hpp>

#include <sealtk/noaa/core/ImageListVideoSourceFactory.hpp>
Expand Down Expand Up @@ -119,12 +120,26 @@ class TrackRepresentation : public sg::AbstractItemRepresentation
auto const defaultFlags =
this->sg::AbstractItemRepresentation::flags(index);

if (index.column() == 3 || index.column() == 5)
switch (index.column())
{
return defaultFlags | Qt::ItemIsEditable;
}
case 3: // Type
case 5: // Notes
return defaultFlags | Qt::ItemIsEditable;

return defaultFlags;
case 4: // Score
{
auto const& data =
index.model()->data(index, sc::ClassificationRole);
if (!data.toHash().isEmpty())
{
return defaultFlags | Qt::ItemIsEditable;
}
return defaultFlags;
}

default:
return defaultFlags;
}
}
};

Expand Down Expand Up @@ -187,6 +202,7 @@ class WindowPrivate
sc::ScalarFilterModel trackModelFilter;
TrackRepresentation trackRepresentation;
TrackTypeDelegate typeDelegate;
TrackScoreDelegate scoreDelegate;
NotesDelegate notesDelegate;

sg::ClassificationSummaryRepresentation statisticsRepresentation;
Expand Down Expand Up @@ -258,6 +274,7 @@ Window::Window(QWidget* parent)
d->trackRepresentation.setSourceModel(&d->trackModelFilter);
d->ui.tracks->setModel(&d->trackRepresentation);
d->ui.tracks->setItemDelegateForColumn(3, &d->typeDelegate);
d->ui.tracks->setItemDelegateForColumn(4, &d->scoreDelegate);
d->ui.tracks->setItemDelegateForColumn(5, &d->notesDelegate);

connect(d->scoreFilter, &sg::FilterWidget::filterMinimumChanged,
Expand Down