2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-17 23:17:22 +08:00
|
|
|
#include "compilersetdirectorieswidget.h"
|
|
|
|
#include "ui_compilersetdirectorieswidget.h"
|
2021-12-23 00:24:52 +08:00
|
|
|
#include "../iconsmanager.h"
|
2021-04-17 23:17:22 +08:00
|
|
|
|
2021-04-18 11:25:40 +08:00
|
|
|
#include <QFileDialog>
|
2021-04-17 23:17:22 +08:00
|
|
|
#include <QStringListModel>
|
2021-04-18 11:25:40 +08:00
|
|
|
#include <QDebug>
|
2021-04-17 23:17:22 +08:00
|
|
|
|
|
|
|
CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::CompilerSetDirectoriesWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
mModel = new CompilerSetDirectoriesWidget::ListModel();
|
|
|
|
ui->listView->setModel(mModel);
|
2021-04-18 11:25:40 +08:00
|
|
|
connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
|
|
|
this, &CompilerSetDirectoriesWidget::selectionChanged);
|
|
|
|
ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
|
2021-12-23 00:24:52 +08:00
|
|
|
connect(pIconsManager, &IconsManager::actionIconsUpdated,
|
|
|
|
this, &CompilerSetDirectoriesWidget::updateIcons);
|
2021-04-17 23:17:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CompilerSetDirectoriesWidget::~CompilerSetDirectoriesWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompilerSetDirectoriesWidget::setDirList(const QStringList &list)
|
|
|
|
{
|
|
|
|
mModel->setStringList(list);
|
2021-04-18 11:25:40 +08:00
|
|
|
QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes();
|
|
|
|
ui->btnDelete->setEnabled(lst.count()>0);
|
2021-04-17 23:17:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList CompilerSetDirectoriesWidget::dirList() const
|
|
|
|
{
|
|
|
|
return mModel->stringList();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags CompilerSetDirectoriesWidget::ListModel::flags(const QModelIndex &index) const
|
|
|
|
{
|
2021-04-18 11:25:40 +08:00
|
|
|
Qt::ItemFlags flags = Qt::NoItemFlags;
|
2021-04-17 23:17:22 +08:00
|
|
|
if (index.isValid()) {
|
2021-04-18 11:25:40 +08:00
|
|
|
flags = Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable ;
|
2021-04-29 20:54:44 +08:00
|
|
|
} else if (index.row() == -1) {
|
2021-04-18 11:25:40 +08:00
|
|
|
// -1 means it's a drop target?
|
|
|
|
flags = Qt::ItemIsDropEnabled;
|
2021-04-17 23:17:22 +08:00
|
|
|
}
|
2021-04-18 11:25:40 +08:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompilerSetDirectoriesWidget::on_btnAdd_pressed()
|
|
|
|
{
|
|
|
|
QString folder = QFileDialog::getExistingDirectory(this,tr("Choose Folder"));
|
|
|
|
if (!folder.isEmpty()) {
|
|
|
|
int row = mModel->rowCount();
|
|
|
|
mModel->insertRow(row);
|
|
|
|
QModelIndex index= mModel->index(row,0);
|
|
|
|
mModel->setData(index,folder,Qt::DisplayRole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompilerSetDirectoriesWidget::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
|
|
|
{
|
|
|
|
ui->btnDelete->setEnabled(!selected.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompilerSetDirectoriesWidget::on_btnDelete_pressed()
|
|
|
|
{
|
|
|
|
QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes();
|
|
|
|
if (lst.count()>0) {
|
|
|
|
mModel->removeRow(lst[0].row());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CompilerSetDirectoriesWidget::on_btnRemoveInvalid_pressed()
|
|
|
|
{
|
|
|
|
QStringList lst;
|
|
|
|
for (const QString& folder : dirList() ) {
|
|
|
|
QFileInfo info(folder);
|
|
|
|
if (info.exists() && info.isDir() ) {
|
2021-04-20 22:24:33 +08:00
|
|
|
lst.append(folder.trimmed());
|
2021-04-18 11:25:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
setDirList(lst);
|
2021-04-17 23:17:22 +08:00
|
|
|
}
|
2021-12-23 00:24:52 +08:00
|
|
|
|
|
|
|
void CompilerSetDirectoriesWidget::updateIcons()
|
|
|
|
{
|
|
|
|
pIconsManager->setIcon(ui->btnAdd,IconsManager::ACTION_MISC_ADD);
|
|
|
|
pIconsManager->setIcon(ui->btnDelete, IconsManager::ACTION_MISC_REMOVE);
|
|
|
|
pIconsManager->setIcon(ui->btnRemoveInvalid, IconsManager::ACTION_MISC_VALIDATE);
|
|
|
|
}
|