File indexing completed on 2025-02-23 04:34:24

0001 /**
0002  * \file tableofcontentseditor.cpp
0003  * Editor for table of contents frames.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 18 Sep 2015
0008  *
0009  * Copyright (C) 2015-2018  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #include "tableofcontentseditor.h"
0028 #include <QVBoxLayout>
0029 #include <QCheckBox>
0030 #include <QStringListModel>
0031 #include "stringlistedit.h"
0032 
0033 /**
0034  * Constructor.
0035  *
0036  * @param parent parent widget
0037  */
0038 TableOfContentsEditor::TableOfContentsEditor(QWidget* parent)
0039   : QWidget(parent)
0040 {
0041   setObjectName(QLatin1String("TableOfContentsEditor"));
0042   auto layout = new QVBoxLayout(this);
0043   m_isTopLevelCheckBox = new QCheckBox(tr("Top level"));
0044   layout->addWidget(m_isTopLevelCheckBox);
0045   m_isOrderedCheckBox = new QCheckBox(tr("Ordered"));
0046   layout->addWidget(m_isOrderedCheckBox);
0047   m_elementsModel = new QStringListModel(this);
0048   layout->addWidget(new StringListEdit(m_elementsModel));
0049 }
0050 
0051 /**
0052  * Set chapters in table of contents.
0053  * @param isTopLevel true if top level
0054  * @param isOrdered true if contents are ordered
0055  * @param elements list of child element IDs
0056  */
0057 void TableOfContentsEditor::setValues(bool isTopLevel, bool isOrdered,
0058                                       const QStringList& elements)
0059 {
0060   m_isTopLevelCheckBox->setChecked(isTopLevel);
0061   m_isOrderedCheckBox->setChecked(isOrdered);
0062   m_elementsModel->setStringList(elements);
0063 }
0064 
0065 /**
0066  * @brief TableOfContentsEditor::getValues
0067  * @param isTopLevel true is returned here if top level
0068  * @param isOrdered true is returned here contents are ordered
0069  * @return list of child element IDs.
0070  */
0071 QStringList TableOfContentsEditor::getValues(bool& isTopLevel,
0072                                              bool& isOrdered) const
0073 {
0074   isTopLevel = m_isTopLevelCheckBox->isChecked();
0075   isOrdered = m_isOrderedCheckBox->isChecked();
0076   return m_elementsModel->stringList();
0077 }