Skip to content

Commit

Permalink
Add decimation column to orphan field dialog
Browse files Browse the repository at this point in the history
Also clean up / refactor the orphan field handling instead. Really,
this should be ripped out completely from WobblyProject and just
be turned into a read-only view in WobblyWindow like the frame rate
viewer, but I'll keep it this way for now in case more features
are added to this at some point.

Fixes #19
  • Loading branch information
arch1t3cht committed Mar 16, 2024
1 parent ecdad3b commit ce93892
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 49 deletions.
23 changes: 13 additions & 10 deletions src/shared/OrphanFieldsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ QVariant OrphanFieldsModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole) {
const auto &frame = std::next(cbegin(), index.row());

if (index.column() == FirstColumn)
if (index.column() == FrameColumn)
return QVariant(frame->first);
else if (index.column() == LastColumn)
return QVariant(QString(frame->second));
else if (index.column() == MatchColumn)
return QVariant(QString(frame->second.match));
else if (index.column() == DecimationColumn)
return QVariant(QString(frame->second.decimated ? "Yes" : "No"));
}

return QVariant();
Expand All @@ -59,7 +61,8 @@ QVariant OrphanFieldsModel::data(const QModelIndex &index, int role) const {
QVariant OrphanFieldsModel::headerData(int section, Qt::Orientation orientation, int role) const {
const char *column_headers[ColumnCount] = {
"Frame",
"Type"
"Type",
"Decimated",
};

if (role == Qt::DisplayRole) {
Expand All @@ -74,8 +77,8 @@ QVariant OrphanFieldsModel::headerData(int section, Qt::Orientation orientation,
}


void OrphanFieldsModel::insert(const std::pair<int, char> &orphan) {
std::map<int, char>::const_iterator it = lower_bound(orphan.first);
void OrphanFieldsModel::insert(const value_type &orphan) {
OrphanFieldMap::const_iterator it = lower_bound(orphan.first);

if (it != cend() && it->first == orphan.first)
return;
Expand All @@ -86,14 +89,14 @@ void OrphanFieldsModel::insert(const std::pair<int, char> &orphan) {

beginInsertRows(QModelIndex(), new_row, new_row);

std::map<int, char>::insert(it, orphan);
OrphanFieldMap::insert(it, orphan);

endInsertRows();
}


void OrphanFieldsModel::erase(int frame) {
std::map<int, char>::const_iterator it = find(frame);
OrphanFieldMap::const_iterator it = find(frame);

if (it == cend())
return;
Expand All @@ -102,7 +105,7 @@ void OrphanFieldsModel::erase(int frame) {

beginRemoveRows(QModelIndex(), row, row);

std::map<int, char>::erase(it);
OrphanFieldMap::erase(it);

endRemoveRows();
}
Expand All @@ -114,7 +117,7 @@ void OrphanFieldsModel::clear() {

beginRemoveRows(QModelIndex(), 0, size() - 1);

std::map<int, char>::clear();
OrphanFieldMap::clear();

endRemoveRows();
}
25 changes: 13 additions & 12 deletions src/shared/OrphanFieldsModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ SOFTWARE.
#include "WobblyTypes.h"


class OrphanFieldsModel : public QAbstractTableModel, private std::map<int, char> {
class OrphanFieldsModel : public QAbstractTableModel, private OrphanFieldMap {
Q_OBJECT

enum Columns {
FirstColumn = 0,
LastColumn,
FrameColumn = 0,
MatchColumn,
DecimationColumn,
ColumnCount
};

Expand All @@ -48,17 +49,17 @@ class OrphanFieldsModel : public QAbstractTableModel, private std::map<int, char

QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

using std::map<int, char>::cbegin;
using std::map<int, char>::cend;
using std::map<int, char>::count;
using std::map<int, char>::lower_bound;
using std::map<int, char>::upper_bound;
using std::map<int, char>::size;
using std::map<int, char>::const_iterator;
using OrphanFieldMap::cbegin;
using OrphanFieldMap::cend;
using OrphanFieldMap::count;
using OrphanFieldMap::lower_bound;
using OrphanFieldMap::upper_bound;
using OrphanFieldMap::size;
using OrphanFieldMap::const_iterator;

void insert(const std::pair<int, char> &orphan);
void insert(const value_type &orphan);

void erase(int freeze_frame);
void erase(int frame);

void clear();
};
Expand Down
31 changes: 5 additions & 26 deletions src/shared/WobblyProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2664,15 +2664,14 @@ void WobblyProject::updateOrphanFields() {
}

void WobblyProject::updateSectionOrphanFields(int section_start, int section_end) {
orphan_fields->erase(section_start);
orphan_fields->erase(section_end - 1);

if (getMatch(section_start) == 'n')
addOrphanField({ section_start, 'n' });
else
deleteOrphanField(section_start);
orphan_fields->insert({ section_start, { 'n', isDecimatedFrame(section_start) } });

if (getMatch(section_end - 1) == 'b')
addOrphanField({ section_end - 1, 'b' });
else
deleteOrphanField(section_end - 1);
orphan_fields->insert({ section_end - 1, { 'b', isDecimatedFrame(section_end - 1) } });
}


Expand Down Expand Up @@ -2719,26 +2718,6 @@ OrphanFieldsModel *WobblyProject::getOrphanFieldsModel() {
}


void WobblyProject::addOrphanField(const std::pair<int, char> &orphan) {
if (orphan.first < 0 || orphan.first >= getNumFrames(PostSource))
throw WobblyException("Can't mark frame " + std::to_string(orphan.first) + " as orphan: value out of range.");

orphan_fields->insert(orphan);

setModified(true);
}


void WobblyProject::deleteOrphanField(int frame) {
if (frame < 0 || frame >= getNumFrames(PostSource))
throw WobblyException("Can't mark frame " + std::to_string(frame) + " as not orphan: value out of range.");

orphan_fields->erase(frame);

setModified(true);
}


bool WobblyProject::isOrphanField(int frame) const {
if (frame < 0 || frame >= getNumFrames(PostSource))
throw WobblyException("Can't check if frame " + std::to_string(frame) + " is orphan: value out of range.");
Expand Down
1 change: 0 additions & 1 deletion src/shared/WobblyProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ class WobblyProject : public QObject {
void clearCombedFrames();

OrphanFieldsModel *getOrphanFieldsModel();
void addOrphanField(const std::pair<int, char> &orphan);
void deleteOrphanField(int frame);
bool isOrphanField(int frame) const;
void clearOrphanFields();
Expand Down
6 changes: 6 additions & 0 deletions src/shared/WobblyTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ struct CustomList {

typedef std::vector<CustomList> CustomListVector;

struct OrphanField {
char match;
bool decimated;
};

typedef std::map<int, OrphanField> OrphanFieldMap;

struct Resize {
bool enabled;
Expand Down
5 changes: 5 additions & 0 deletions src/wobbly/WobblyWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5184,6 +5184,8 @@ void WobblyWindow::toggleDecimation() {
project->addDecimatedFrame(current_frame);
commit("Toggle decimation");

updateSectionOrphanFields(current_frame);

if (preview) {
try {
evaluateFinalScript();
Expand Down Expand Up @@ -5482,6 +5484,9 @@ void WobblyWindow::setDecimationPattern() {

updateFrameRatesViewer();

if (project)
project->updateOrphanFields();

try {
evaluateScript(preview);
} catch (WobblyException &e) {
Expand Down

0 comments on commit ce93892

Please sign in to comment.