GUI: In the project dialog select libraries in a listbox

This commit is contained in:
Daniel Marjamäki 2019-04-06 16:44:43 +02:00
parent 82a1e3c61c
commit 7237acdb47
2 changed files with 13 additions and 12 deletions

View File

@ -140,11 +140,11 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent)
} }
} }
qSort(libs); qSort(libs);
foreach (const QString library, libs) { mUI.mLibraries->clear();
QCheckBox *checkbox = new QCheckBox(this); for (const QString &lib : libs) {
checkbox->setText(library); QListWidgetItem* item = new QListWidgetItem(lib, mUI.mLibraries);
mUI.mLayoutLibraries->addWidget(checkbox); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set checkable flag
mLibraryCheckboxes << checkbox; item->setCheckState(Qt::Unchecked); // AND initialize check state
} }
// Platforms.. // Platforms..
@ -499,9 +499,10 @@ QStringList ProjectFileDialog::getExcludedPaths() const
QStringList ProjectFileDialog::getLibraries() const QStringList ProjectFileDialog::getLibraries() const
{ {
QStringList libraries; QStringList libraries;
foreach (const QCheckBox *checkbox, mLibraryCheckboxes) { for (int row = 0; row < mUI.mLibraries->count(); ++row) {
if (checkbox->isChecked()) QListWidgetItem *item = mUI.mLibraries->item(row);
libraries << checkbox->text(); if (item->checkState() == Qt::Checked)
libraries << item->text();
} }
return libraries; return libraries;
} }
@ -554,9 +555,9 @@ void ProjectFileDialog::setExcludedPaths(const QStringList &paths)
void ProjectFileDialog::setLibraries(const QStringList &libraries) void ProjectFileDialog::setLibraries(const QStringList &libraries)
{ {
for (int i = 0; i < mLibraryCheckboxes.size(); i++) { for (int row = 0; row < mUI.mLibraries->count(); ++row) {
QCheckBox *checkbox = mLibraryCheckboxes[i]; QListWidgetItem *item = mUI.mLibraries->item(row);
checkbox->setChecked(libraries.contains(checkbox->text())); item->setCheckState(libraries.contains(item->text()) ? Qt::Checked : Qt::Unchecked);
} }
} }

View File

@ -332,7 +332,7 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<layout class="QHBoxLayout" name="mLayoutLibraries"/> <widget class="QListWidget" name="mLibraries"/>
</item> </item>
<item> <item>
<widget class="QLabel" name="mLabelLibrariesNote"> <widget class="QLabel" name="mLabelLibrariesNote">