Files
oak-editor/app/node/project/serializer/serializer.h
T
Mike-Solar bb40b4923e style: unify identifier naming per updated conventions
Automated with clang-tidy readability-identifier-naming (config added to
.clang-tidy) plus scripted passes, per the updated rules now documented
in CONTRIBUTING.md:

- types (class/struct/enum/alias/template params): PascalCase
- functions, variables, members: snake_case (incl. rational -> Rational)
- private/protected members: trailing underscore; static member
  variables likewise (instance_, available_themes_)
- constants and enum values: snake_case (kLinear -> k_linear,
  F32P -> f32p); ALL_CAPS reserved for macros
- macros: OAK_ prefix (OLIVE_ADD_TEST/OLIVE_ASSERT/OLIVE_CONFIG ->
  OAK_ADD_TEST/OAK_ASSERT/OAK_CONFIG, GL_PREAMBLE -> OAK_GL_PREAMBLE,
  include guards -> OAK_*)
- file names: all lowercase (Current/Plugin/OliveHost/OliveClip/
  OlivePluginInstance -> current/plugin/olivehost/oliveclip/
  oliveplugininstance)
- getters share the member name sans underscore, setters set_foo()
- Qt and third-party (OpenFX) virtual overrides and framework callbacks
  keep their original names (exempt in .clang-tidy)

Manual follow-ups required where automation could not reach:
- string-based QMetaObject/SIGNAL/SLOT references updated to renamed
  methods (AddTask, CreatedFile, DeleteSpecificFile, moveSelectionUp, ...)
- macro bodies referencing renamed methods (OLIVE_CONFIG,
  NODE_DEFAULT_DESTRUCTOR, MANAGEDDISPLAYWIDGET_*)
- self-shadowing locals renamed where signals/methods became same-named
  (size_changed, worker_count, selected_items, import param, filters)
- third_party OFX member/namespace usages restored (OFX::Host::*,
  _created, _clipPrefsDirty, createInstance, clearPersistentMessage)
- STL protocol aliases restored (const_iterator) with .clang-tidy
  ignore rules; qHash overloads restored

Full build and test suite pass: ctest 4/4, ~1960 gtest cases green.
2026-07-19 16:10:54 +08:00

279 lines
5.5 KiB
C++

/***
Olive - Non-Linear Video Editor
Copyright (C) 2022 Olive Team
Modifications Copyright (C) 2025 mikesolar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OAK_PROJECTSERIALIZER_H
#define OAK_PROJECTSERIALIZER_H
#include <vector>
#include "common/define.h"
#include "node/project.h"
#include "typeserializer.h"
namespace olive
{
/**
* @brief An abstract base class for serializing/deserializing project data
*
* The goal of this is to further abstract serialized project data from their
* in-memory representations.
*/
class ProjectSerializer {
public:
enum LoadType {
k_project,
k_only_nodes,
k_only_clips,
k_only_markers,
k_only_keyframes
};
ProjectSerializer() = default;
virtual ~ProjectSerializer()
{
}
DISABLE_COPY_MOVE(ProjectSerializer)
enum ResultCode {
k_success,
k_project_too_old,
k_project_too_new,
k_unknown_version,
k_file_error,
k_xml_error,
k_overwrite_error,
k_no_data
};
using SerializedProperties = QHash<Node *, QMap<QString, QString>>;
using SerializedKeyframes = QHash<QString, QVector<NodeKeyframe *>>;
class LoadData {
public:
LoadData() = default;
SerializedProperties properties;
std::vector<TimelineMarker *> markers;
SerializedKeyframes keyframes;
MainWindowLayoutInfo layout;
QVector<Node *> nodes;
QHash<quintptr, Node *> node_ptrs;
QHash<Node *, QUuid> node_uuids;
Node::OutputConnections promised_connections;
};
class Result {
public:
Result(const ResultCode &code)
: code_(code)
{
}
bool operator==(const ResultCode &code)
{
return code_ == code;
}
bool operator!=(const ResultCode &code)
{
return code_ != code;
}
const ResultCode &code() const
{
return code_;
}
const QString &get_details() const
{
return details_;
}
void set_details(const QString &s)
{
details_ = s;
}
const LoadData &get_load_data() const
{
return load_data_;
}
void set_load_data(const LoadData &p)
{
load_data_ = p;
}
private:
ResultCode code_;
QString details_;
LoadData load_data_;
};
class SaveData {
public:
SaveData(LoadType type, Project *project = nullptr,
const QString &filename = QString())
{
type_ = type;
project_ = project;
filename_ = filename;
}
Project *get_project() const
{
return project_;
}
void set_project(Project *p)
{
project_ = p;
}
const QString &get_filename() const
{
return filename_;
}
void set_filename(const QString &s)
{
filename_ = s;
}
LoadType type() const
{
return type_;
}
const MainWindowLayoutInfo &get_layout() const
{
return layout_;
}
void set_layout(const MainWindowLayoutInfo &layout)
{
layout_ = layout;
}
const QVector<Node *> &get_only_serialize_nodes() const
{
return only_serialize_nodes_;
}
void set_only_serialize_nodes(const QVector<Node *> &only)
{
only_serialize_nodes_ = only;
}
void set_only_serialize_nodes_and_resolve_groups(QVector<Node *> only);
const std::vector<TimelineMarker *> &get_only_serialize_markers() const
{
return only_serialize_markers_;
}
void set_only_serialize_markers(const std::vector<TimelineMarker *> &only)
{
only_serialize_markers_ = only;
}
const std::vector<NodeKeyframe *> &get_only_serialize_keyframes() const
{
return only_serialize_keyframes_;
}
void set_only_serialize_keyframes(const std::vector<NodeKeyframe *> &only)
{
only_serialize_keyframes_ = only;
}
const SerializedProperties &get_properties() const
{
return properties_;
}
void set_properties(const SerializedProperties &p)
{
properties_ = p;
}
private:
LoadType type_;
Project *project_;
QString filename_;
MainWindowLayoutInfo layout_;
QVector<Node *> only_serialize_nodes_;
SerializedProperties properties_;
std::vector<TimelineMarker *> only_serialize_markers_;
std::vector<NodeKeyframe *> only_serialize_keyframes_;
};
static void initialize();
static void destroy();
static Result load(Project *project, const QString &filename,
LoadType load_type);
static Result load(Project *project, QXmlStreamReader *read_device,
LoadType load_type);
static Result paste(LoadType load_type, Project *project = nullptr);
static Result save(const SaveData &data, bool compress);
static Result save(QXmlStreamWriter *write_device, const SaveData &data);
static Result copy(const SaveData &data);
static bool check_compressed_id(QFile *file);
protected:
virtual LoadData load(Project *project, QXmlStreamReader *reader,
LoadType load_type, void *reserved) const = 0;
virtual void save(QXmlStreamWriter *writer, const SaveData &data,
void *reserved) const
{
}
virtual uint version() const = 0;
bool is_cancelled() const;
private:
static Result load_with_serializer_version(uint version, Project *project,
QXmlStreamReader *reader,
LoadType load_type);
static QVector<ProjectSerializer *> instances;
};
}
#endif // OAK_PROJECTSERIALIZER_H