File indexing completed on 2024-05-05 05:40:57
0001 /*************************************************************************** 0002 * Copyright (C) 2021 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * This software is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #include "campaignintegritydialog.h" 0021 #include "ui_campaignintegritydialog.h" 0022 0023 #include "delegates/actiondelegate.h" 0024 #include "model/actiononlistmodel.h" 0025 0026 #include <QQmlContext> 0027 #include <QQmlEngine> 0028 0029 namespace campaign 0030 { 0031 CampaignIntegrityDialog::CampaignIntegrityDialog(QStringList missingFiles, QStringList unmanagedFile, 0032 const QString& root, QWidget* parent) 0033 : QDialog(parent) 0034 , ui(new Ui::CampaignIntegrityDialog) 0035 , m_missingFileModel( 0036 new ActionOnListModel(missingFiles, {{"Forget", "edit-delete"}, {"Create", "document-new"}}, root)) 0037 , m_unmanagedFileModel( 0038 new ActionOnListModel(unmanagedFile, {{"Add into project", "list-add"}, {"Delete", "list-remove"}}, root)) 0039 { 0040 ui->setupUi(this); 0041 auto engine= ui->quickWidget->engine(); 0042 engine->addImportPath(QStringLiteral("qrc:/qml")); 0043 engine->addImportPath(QStringLiteral("qrc:/qml/rolistyle")); 0044 engine->rootContext()->setContextProperty("_dialog", this); 0045 engine->rootContext()->setContextProperty("_missingFilesModel", m_missingFileModel.get()); 0046 engine->rootContext()->setContextProperty("_unmanagedFilesModel", m_unmanagedFileModel.get()); 0047 ui->quickWidget->setSource(QUrl("qrc:/qml/Campaign/IntegrityPage.qml")); 0048 connect(engine, &QQmlEngine::warnings, this, [](const QList<QQmlError>& warnings) 0049 { 0050 for(auto const& w : warnings) 0051 qDebug() << w.toString(); 0052 }); 0053 } 0054 0055 CampaignIntegrityDialog::~CampaignIntegrityDialog() 0056 { 0057 delete ui; 0058 } 0059 0060 bool CampaignIntegrityDialog::canValidate() const 0061 { 0062 return m_missingFileModel->canValidate() && m_unmanagedFileModel->canValidate(); 0063 } 0064 0065 const QList<DataInfo>& CampaignIntegrityDialog::missingFileActions() const 0066 { 0067 return m_missingFileModel->dataset(); 0068 } 0069 0070 const QList<DataInfo>& CampaignIntegrityDialog::unmanagedFileActions() const 0071 { 0072 return m_unmanagedFileModel->dataset(); 0073 } 0074 0075 void CampaignIntegrityDialog::validate() 0076 { 0077 accept(); 0078 } 0079 0080 void CampaignIntegrityDialog::refuse() 0081 { 0082 reject(); 0083 } 0084 0085 void CampaignIntegrityDialog::setAction(int modelId, int index, int actionId) 0086 { 0087 auto model= (modelId == 0) ? m_missingFileModel.get() : m_unmanagedFileModel.get(); 0088 0089 model->setAction(index, actionId); 0090 emit canValidateChanged(); 0091 } 0092 0093 void CampaignIntegrityDialog::changeEvent(QEvent* e) 0094 { 0095 QDialog::changeEvent(e); 0096 switch(e->type()) 0097 { 0098 case QEvent::LanguageChange: 0099 ui->retranslateUi(this); 0100 break; 0101 default: 0102 break; 0103 } 0104 } 0105 } // namespace campaign