1 #include "common/common_pch.h"
2 
3 // #include <QDebug>
4 // #include <typeinfo>
5 
6 #include "common/qt.h"
7 #include "mkvtoolnix-gui/header_editor/page_base.h"
8 #include "mkvtoolnix-gui/header_editor/value_page.h"
9 
10 namespace mtx::gui::HeaderEditor {
11 
12 using namespace mtx::gui;
13 
PageBase(Tab & parent,translatable_string_c const & title)14 PageBase::PageBase(Tab &parent,
15                    translatable_string_c const &title)
16   : QWidget{&parent}
17   , m_parent(parent)
18   , m_title{title}
19 {
20   setVisible(false);
21 
22   setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Expanding});
23 }
24 
~PageBase()25 PageBase::~PageBase() {
26 }
27 
28 PageBase *
hasBeenModified()29 PageBase::hasBeenModified() {
30   if (hasThisBeenModified()) {
31     // auto vp = dynamic_cast<ValuePage const *>(this);
32     // qDebug() << "I have been modified: " << typeid(*this).name() << " title " << title()
33     //          << " orig " << (vp ? vp->originalValueAsString() : Q("<not a value page>")) << " current " << (vp ? vp->currentValueAsString() : Q("<not a value page>"));
34     return this;
35   }
36 
37   for (auto child : m_children) {
38     auto modifiedPage = child->hasBeenModified();
39     if (modifiedPage)
40       return modifiedPage;
41   }
42 
43   return nullptr;
44 }
45 
46 void
doModifications()47 PageBase::doModifications() {
48   modifyThis();
49 
50   for (auto child : m_children)
51     child->doModifications();
52 }
53 
54 QModelIndex
validate() const55 PageBase::validate()
56   const {
57   if (!validateThis())
58     return m_pageIdx;
59 
60   for (auto child : m_children) {
61     auto result = child->validate();
62     if (result.isValid())
63       return result;
64   }
65 
66   return QModelIndex{};
67 }
68 
69 QString
title() const70 PageBase::title()
71   const {
72   return Q(m_title.get_translated());
73 }
74 
75 void
setItems(QList<QStandardItem * > const & items) const76 PageBase::setItems(QList<QStandardItem *> const &items)
77   const {
78   items.at(0)->setText(title());
79 }
80 
81 }
82