RedPanda-CPP/RedPandaIDE/settingsdialog/compilersetdirectorieswidge...

86 lines
2.4 KiB
C++
Raw Normal View History

2021-04-17 23:17:22 +08:00
#include "compilersetdirectorieswidget.h"
#include "ui_compilersetdirectorieswidget.h"
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-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 ;
} else if (index.row() ==-1) {
// -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
}