Merge pull request #1216 from manongjohn/scene_edit_history_preference

Control file history information
This commit is contained in:
manongjohn 2023-09-24 08:14:32 -04:00 committed by GitHub
commit 205f942226
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 103 additions and 23 deletions

View file

@ -26,8 +26,12 @@ using namespace std;
//------------------------------------------------------- //-------------------------------------------------------
TContentHistory::TContentHistory(bool isLevel) TContentHistory::TContentHistory(bool isLevel, QString altUsername,
: m_isLevel(isLevel), m_frozenHistory() {} bool recordEdit)
: m_isLevel(isLevel)
, m_frozenHistory()
, m_altUsername(altUsername)
, m_recordEdit(recordEdit) {}
//------------------------------------------------------- //-------------------------------------------------------
@ -36,7 +40,8 @@ TContentHistory::~TContentHistory() {}
//------------------------------------------------------- //-------------------------------------------------------
TContentHistory *TContentHistory::clone() const { TContentHistory *TContentHistory::clone() const {
TContentHistory *history = new TContentHistory(m_isLevel); TContentHistory *history =
new TContentHistory(m_isLevel, m_altUsername, m_recordEdit);
history->deserialize(serialize()); history->deserialize(serialize());
return history; return history;
} }
@ -84,7 +89,7 @@ inline QString getStr(const TFrameId &id) {
const QString Fmt = "dd MMM yy hh:mm"; const QString Fmt = "dd MMM yy hh:mm";
static QString getLine(int counter, const QDateTime &date, static QString getLine(int counter, const QDateTime &date,
const set<TFrameId> &frames) { const set<TFrameId> &frames, QString altUsername) {
static QString user; static QString user;
static QString machine; static QString machine;
if (user == "") { if (user == "") {
@ -97,6 +102,8 @@ static QString getLine(int counter, const QDateTime &date,
else if (value.startsWith("COMPUTERNAME=")) else if (value.startsWith("COMPUTERNAME="))
machine = blanks(value.right(value.size() - 13)); machine = blanks(value.right(value.size() - 13));
} }
if (!altUsername.isEmpty()) user = blanks(altUsername);
} }
if (frames.empty()) if (frames.empty())
@ -149,7 +156,9 @@ const QString TContentHistory::currentToString() const {
if (!m_isLevel) { if (!m_isLevel) {
assert(m_records.size() == 1); assert(m_records.size() == 1);
return getLine(++counter, m_records.begin()->second, set<TFrameId>()); if (!m_recordEdit) return "";
return getLine(++counter, m_records.begin()->second, set<TFrameId>(),
m_altUsername);
} }
QString out; QString out;
@ -168,7 +177,8 @@ const QString TContentHistory::currentToString() const {
++it1; ++it1;
} }
assert(!frames.empty()); assert(!frames.empty());
out += getLine(++counter, currDate, frames); if (m_recordEdit)
out += getLine(++counter, currDate, frames, m_altUsername);
if (it1 != dateSorted.end()) currDate = it1->first; if (it1 != dateSorted.end()) currDate = it1->first;
} }

View file

@ -12,6 +12,7 @@
//#include <fstream.h> //#include <fstream.h>
#include "../compatibility/tfile_io.h" #include "../compatibility/tfile_io.h"
#include "tenv.h" #include "tenv.h"
#include "toonz/preferences.h"
/*=====================================================================*/ /*=====================================================================*/
@ -700,7 +701,11 @@ void ParsedPliImp::loadInfo(bool readPlt, TPalette *&palette,
m_iChan.seekg(pos, ios::beg); m_iChan.seekg(pos, ios::beg);
TagElem *tagElem = readTag(); TagElem *tagElem = readTag();
TextTag *textTag = (TextTag *)tagElem->m_tag; TextTag *textTag = (TextTag *)tagElem->m_tag;
history = new TContentHistory(true); QString altUsername =
Preferences::instance()->getStringValue(recordAsUsername);
bool recordEdit =
Preferences::instance()->getBoolValue(recordFileHistory);
history = new TContentHistory(true, altUsername, recordEdit);
history->deserialize(QString::fromStdString(textTag->m_text)); history->deserialize(QString::fromStdString(textTag->m_text));
delete tagElem; delete tagElem;
} }

View file

@ -18,6 +18,7 @@
#include "tenv.h" #include "tenv.h"
#include "tconvert.h" #include "tconvert.h"
#include "trasterimage.h" #include "trasterimage.h"
#include "toonz/preferences.h"
#include <QByteArray> #include <QByteArray>
@ -1501,7 +1502,13 @@ TLevelReaderTzl::TLevelReaderTzl(const TFilePath &path)
fread(&historyData[0], 1, lSize, historyChan); fread(&historyData[0], 1, lSize, historyChan);
fclose(historyChan); fclose(historyChan);
if (!m_contentHistory) m_contentHistory = new TContentHistory(true); if (!m_contentHistory) {
QString altUsername =
Preferences::instance()->getStringValue(recordAsUsername);
bool recordEdit =
Preferences::instance()->getBoolValue(recordFileHistory);
m_contentHistory = new TContentHistory(true, altUsername, recordEdit);
}
m_contentHistory->deserialize(QString::fromStdString(historyData)); m_contentHistory->deserialize(QString::fromStdString(historyData));
} }

View file

@ -29,12 +29,14 @@ class DVAPI TContentHistory {
bool m_isLevel; bool m_isLevel;
std::map<TFrameId, QDateTime> m_records; std::map<TFrameId, QDateTime> m_records;
QString m_frozenHistory; QString m_frozenHistory;
QString m_altUsername;
bool m_recordEdit;
const QString currentToString() const; const QString currentToString() const;
public: public:
//! set isLevel=true if you want to keep track of single-frames modifications //! set isLevel=true if you want to keep track of single-frames modifications
TContentHistory(bool isLevel); TContentHistory(bool isLevel, QString altUsername, bool recordEdit);
~TContentHistory(); ~TContentHistory();

View file

@ -73,6 +73,8 @@ enum PreferencesItemId {
rasterBackgroundColor, rasterBackgroundColor,
resetUndoOnSavingLevel, resetUndoOnSavingLevel,
defaultProjectPath, defaultProjectPath,
recordFileHistory,
recordAsUsername,
//---------- //----------
// Import / Export // Import / Export

View file

@ -651,6 +651,17 @@ void PreferencesPopup::onColorCalibrationChanged() {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void PreferencesPopup::onRecordAsUserChanged() {
QString username = m_pref->getStringValue(recordAsUsername);
if (username.isEmpty()) {
username = TSystem::getUserName();
m_pref->setValue(recordAsUsername, QVariant::fromValue(username));
getUI<LineEdit*>(recordAsUsername)->setText(username);
}
}
//-----------------------------------------------------------------------------
void PreferencesPopup::onDefLevelTypeChanged() { void PreferencesPopup::onDefLevelTypeChanged() {
bool isRaster = m_pref->getIntValue(DefLevelType) != PLI_XSHLEVEL && bool isRaster = m_pref->getIntValue(DefLevelType) != PLI_XSHLEVEL &&
!m_pref->getBoolValue(newLevelSizeToCameraSizeEnabled); !m_pref->getBoolValue(newLevelSizeToCameraSizeEnabled);
@ -971,7 +982,8 @@ void PreferencesPopup::onImportPolicyExternallyChanged(int policy) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QWidget* PreferencesPopup::createUI(PreferencesItemId id, QWidget* PreferencesPopup::createUI(PreferencesItemId id,
const QList<ComboBoxItem>& comboItems) { const QList<ComboBoxItem>& comboItems,
bool isLineEdit) {
PreferencesItem item = m_pref->getItem(id); PreferencesItem item = m_pref->getItem(id);
// create widget depends on the parameter types // create widget depends on the parameter types
QWidget* widget = nullptr; QWidget* widget = nullptr;
@ -1039,6 +1051,12 @@ QWidget* PreferencesPopup::createUI(PreferencesItemId id,
ret = connect(combo, SIGNAL(currentIndexChanged(int)), this, ret = connect(combo, SIGNAL(currentIndexChanged(int)), this,
SLOT(onChange())); SLOT(onChange()));
widget = combo; widget = combo;
} else if (isLineEdit) { // create LineEdit
DVGui::LineEdit* lineEdit =
new DVGui::LineEdit(item.value.toString(), this);
ret =
connect(lineEdit, SIGNAL(editingFinished()), this, SLOT(onChange()));
widget = lineEdit;
} else { // create FileField } else { // create FileField
DVGui::FileField* field = DVGui::FileField* field =
new DVGui::FileField(this, item.value.toString()); new DVGui::FileField(this, item.value.toString());
@ -1115,16 +1133,18 @@ QGridLayout* PreferencesPopup::insertGroupBoxUI(PreferencesItemId id,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void PreferencesPopup::insertUI(PreferencesItemId id, QGridLayout* layout, void PreferencesPopup::insertUI(PreferencesItemId id, QGridLayout* layout,
const QList<ComboBoxItem>& comboItems) { const QList<ComboBoxItem>& comboItems,
bool isLineEdit) {
PreferencesItem item = m_pref->getItem(id); PreferencesItem item = m_pref->getItem(id);
QWidget* widget = createUI(id, comboItems); QWidget* widget = createUI(id, comboItems, isLineEdit);
if (!widget) return; if (!widget) return;
bool isFileField = false; bool isEditBox = false;
if (item.type == QMetaType::QVariantMap || if (item.type == QMetaType::QVariantMap ||
(item.type == QMetaType::QString && dynamic_cast<FileField*>(widget))) (item.type == QMetaType::QString &&
isFileField = true; (dynamic_cast<FileField*>(widget) || dynamic_cast<LineEdit*>(widget))))
isEditBox = true;
// CheckBox contains label in itself // CheckBox contains label in itself
if (item.type == QMetaType::Bool) if (item.type == QMetaType::Bool)
@ -1133,8 +1153,8 @@ void PreferencesPopup::insertUI(PreferencesItemId id, QGridLayout* layout,
int row = layout->rowCount(); int row = layout->rowCount();
layout->addWidget(new QLabel(getUIString(id), this), row, 0, layout->addWidget(new QLabel(getUIString(id), this), row, 0,
Qt::AlignRight | Qt::AlignVCenter); Qt::AlignRight | Qt::AlignVCenter);
if (isFileField) if (isEditBox)
layout->addWidget(widget, row, 1, 1, 2); layout->addWidget(widget, row, 1, 1, (isLineEdit ? 1 : 2));
else { else {
bool isWideComboBox = false; bool isWideComboBox = false;
for (auto cbItem : comboItems) { for (auto cbItem : comboItems) {
@ -1267,6 +1287,8 @@ QString PreferencesPopup::getUIString(PreferencesItemId id) {
{resetUndoOnSavingLevel, tr("Clear Undo History when Saving Levels")}, {resetUndoOnSavingLevel, tr("Clear Undo History when Saving Levels")},
{doNotShowPopupSaveScene, tr("Do not show Save Scene popup warning")}, {doNotShowPopupSaveScene, tr("Do not show Save Scene popup warning")},
{defaultProjectPath, tr("Default Project Path:")}, {defaultProjectPath, tr("Default Project Path:")},
{recordFileHistory, tr("Record File History* (tnz, pli, hst)")},
{recordAsUsername, tr("History Username*:")},
// Import / Export // Import / Export
{ffmpegPath, tr("Executable Directory:")}, {ffmpegPath, tr("Executable Directory:")},
@ -1914,8 +1936,16 @@ QWidget* PreferencesPopup::createSavingPage() {
insertUI(fastRenderPath, lay); insertUI(fastRenderPath, lay);
QGridLayout* recordHistoryLay = insertGroupBoxUI(recordFileHistory, lay);
{ insertUI(recordAsUsername, recordHistoryLay, QList<ComboBoxItem>(), true); }
lay->setRowStretch(lay->rowCount(), 1); lay->setRowStretch(lay->rowCount(), 1);
insertFootNote(lay);
widget->setLayout(lay); widget->setLayout(lay);
m_onEditedFuncMap.insert(recordAsUsername,
&PreferencesPopup::onRecordAsUserChanged);
return widget; return widget;
} }
@ -2391,6 +2421,8 @@ void PreferencesPopup::onChange() {
m_pref->setValue(id, field->getValue()); m_pref->setValue(id, field->getValue());
else if (QGroupBox* groupBox = dynamic_cast<QGroupBox*>(senderWidget)) else if (QGroupBox* groupBox = dynamic_cast<QGroupBox*>(senderWidget))
m_pref->setValue(id, groupBox->isChecked()); m_pref->setValue(id, groupBox->isChecked());
else if (LineEdit* lineEdit = dynamic_cast<LineEdit*>(senderWidget))
m_pref->setValue(id, lineEdit->text());
else else
return; return;

View file

@ -102,10 +102,12 @@ private:
QWidget* createUI( QWidget* createUI(
PreferencesItemId id, PreferencesItemId id,
const QList<ComboBoxItem>& comboItems = QList<ComboBoxItem>()); const QList<ComboBoxItem>& comboItems = QList<ComboBoxItem>(),
bool isLineEdit = false);
QGridLayout* insertGroupBoxUI(PreferencesItemId id, QGridLayout* layout); QGridLayout* insertGroupBoxUI(PreferencesItemId id, QGridLayout* layout);
void insertUI(PreferencesItemId id, QGridLayout* layout, void insertUI(PreferencesItemId id, QGridLayout* layout,
const QList<ComboBoxItem>& comboItems = QList<ComboBoxItem>()); const QList<ComboBoxItem>& comboItems = QList<ComboBoxItem>(),
bool isLineEdit = false);
void insertDualUIs( void insertDualUIs(
PreferencesItemId leftId, PreferencesItemId rightId, QGridLayout* layout, PreferencesItemId leftId, PreferencesItemId rightId, QGridLayout* layout,
const QList<ComboBoxItem>& leftComboItems = QList<ComboBoxItem>(), const QList<ComboBoxItem>& leftComboItems = QList<ComboBoxItem>(),
@ -149,6 +151,8 @@ private:
void onUnitChanged(); void onUnitChanged();
void beforeRoomChoiceChanged(); void beforeRoomChoiceChanged();
void onColorCalibrationChanged(); void onColorCalibrationChanged();
// Saving
void onRecordAsUserChanged();
// Drawing // Drawing
void onDefLevelTypeChanged(); void onDefLevelTypeChanged();
void onUseNumpadForSwitchingStylesClicked(); void onUseNumpadForSwitchingStylesClicked();

View file

@ -497,6 +497,11 @@ void Preferences::definePreferenceItems() {
define(defaultProjectPath, "defaultProjectPath", QMetaType::QString, define(defaultProjectPath, "defaultProjectPath", QMetaType::QString,
documentsPath); documentsPath);
define(recordFileHistory, "recordFileHistory", QMetaType::Bool, true);
QString userName = TSystem::getUserName();
define(recordAsUsername, "recordAsUsername", QMetaType::QString, userName);
// Import / Export // Import / Export
define(ffmpegPath, "ffmpegPath", QMetaType::QString, ""); define(ffmpegPath, "ffmpegPath", QMetaType::QString, "");
define(ffmpegTimeout, "ffmpegTimeout", QMetaType::Int, 0, 0, define(ffmpegTimeout, "ffmpegTimeout", QMetaType::Int, 0, 0,

View file

@ -1499,8 +1499,12 @@ TCamera *ToonzScene::getCurrentPreviewCamera() {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
TContentHistory *ToonzScene::getContentHistory(bool createIfNeeded) { TContentHistory *ToonzScene::getContentHistory(bool createIfNeeded) {
if (!m_contentHistory && createIfNeeded) if (!m_contentHistory && createIfNeeded) {
m_contentHistory = new TContentHistory(false); QString altUsername =
Preferences::instance()->getStringValue(recordAsUsername);
bool recordEdit = Preferences::instance()->getBoolValue(recordFileHistory);
m_contentHistory = new TContentHistory(false, altUsername, recordEdit);
}
return m_contentHistory; return m_contentHistory;
} }

View file

@ -331,7 +331,10 @@ void TXshSimpleLevel::touchFrame(const TFrameId &fid) {
m_properties->setDirtyFlag(true); m_properties->setDirtyFlag(true);
TContentHistory *ch = getContentHistory(); TContentHistory *ch = getContentHistory();
if (!ch) { if (!ch) {
ch = new TContentHistory(true); QString altUsername =
Preferences::instance()->getStringValue(recordAsUsername);
bool recordEdit = Preferences::instance()->getBoolValue(recordFileHistory);
ch = new TContentHistory(true, altUsername, recordEdit);
setContentHistory(ch); setContentHistory(ch);
} }
ch->frameModifiedNow(fid); ch->frameModifiedNow(fid);

View file

@ -225,7 +225,7 @@ InfoViewerImp::InfoViewerImp()
create(eSampleSize, QObject::tr("Sample Size: ")); create(eSampleSize, QObject::tr("Sample Size: "));
create(eSampleType, QObject::tr("Sample Type: ")); create(eSampleType, QObject::tr("Sample Type: "));
m_historyLabel.setStyleSheet("color: rgb(0, 0, 200);"); setLabelStyle(&m_historyLabel);
m_history.setStyleSheet("font-size: 12px; font-family: \"courier\";"); m_history.setStyleSheet("font-size: 12px; font-family: \"courier\";");
// m_history.setStyleSheet("font-family: \"courier\";"); // m_history.setStyleSheet("font-family: \"courier\";");
m_history.setReadOnly(true); m_history.setReadOnly(true);
@ -344,6 +344,12 @@ void InfoViewerImp::setImageInfo() {
} catch (...) { } catch (...) {
return; return;
} }
if (lr && m_path.getType() == "pli") {
try {
lr->loadInfo();
} catch (...) {
}
}
if (!m_fids.empty() && lr && ii) { if (!m_fids.empty() && lr && ii) {
setVal(eImageSize, setVal(eImageSize,
QString::number(ii->m_lx) + " X " + QString::number(ii->m_ly)); QString::number(ii->m_lx) + " X " + QString::number(ii->m_ly));