Commit 9167a1f6 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use directly a QListWidget

parent d996cc5e
Pipeline #44980 canceled with stage
......@@ -20,7 +20,7 @@
#include "groupmanagementwidgettest.h"
#include "groupmanagementwidget.h"
#include <QListView>
#include <QListWidget>
#include <QTest>
#include <QVBoxLayout>
......@@ -38,7 +38,7 @@ void GroupManagementWidgetTest::shouldHaveDefaultValues()
QVERIFY(mainLayout);
QCOMPARE(mainLayout->contentsMargins(), {});
auto mListView = w.findChild<QListView *>(QStringLiteral("mListView"));
QVERIFY(mListView);
QCOMPARE(mListView->selectionMode(), QAbstractItemView::MultiSelection);
auto mListWidget = w.findChild<QListWidget *>(QStringLiteral("mListWidget"));
QVERIFY(mListWidget);
QCOMPARE(mListWidget->selectionMode(), QAbstractItemView::MultiSelection);
}
......@@ -40,9 +40,8 @@ GroupManagementDialog::GroupManagementDialog(QWidget *parent)
mGroupManagementWidget->setObjectName(QStringLiteral("mGroupManagementWidget"));
auto mainLayout = new QVBoxLayout(this);
mainLayout->setObjectName(QStringLiteral("mainLayout"));
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
buttonBox->setObjectName(QStringLiteral("buttonBox"));
connect(buttonBox, &QDialogButtonBox::accepted, this, &GroupManagementDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &GroupManagementDialog::reject);
mainLayout->addWidget(mGroupManagementWidget);
mainLayout->addWidget(buttonBox);
......
......@@ -19,20 +19,22 @@
*/
#include "groupmanagementwidget.h"
#include "loadgroupmenu.h"
#include <KLocalizedString>
#include <QListView>
#include <QDir>
#include <QListWidget>
#include <QVBoxLayout>
GroupManagementWidget::GroupManagementWidget(QWidget *parent)
: QWidget(parent)
, mListView(new QListView(this))
, mListWidget(new QListWidget(this))
{
auto mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins({});
mainLayout->setObjectName(QStringLiteral("mainLayout"));
mListView->setObjectName(QStringLiteral("mListView"));
mainLayout->addWidget(mListView);
mListView->setSelectionMode(QAbstractItemView::MultiSelection);
mListWidget->setObjectName(QStringLiteral("mListWidget"));
mainLayout->addWidget(mListWidget);
mListWidget->setSelectionMode(QAbstractItemView::MultiSelection);
init();
}
......@@ -43,5 +45,18 @@ GroupManagementWidget::~GroupManagementWidget()
void GroupManagementWidget::init()
{
//TODO
const QString groupPath = LoadGroupMenu::defaultGroupPath();
if (groupPath.isEmpty()) {
return;
}
QDir dir(groupPath);
const QStringList groups = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
if (groups.isEmpty()) {
return;
}
for (const QString &file : groups) {
QListWidgetItem *item = new QListWidgetItem(file, mListWidget);
const QString fullPath = groupPath + QLatin1Char('/') + file;
item->setData(FullPathRole, fullPath);
}
}
......@@ -24,7 +24,7 @@
#include <QWidget>
#include "libkdebugsettings_private_export.h"
class QListView;
class QListWidget;
class LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT GroupManagementWidget : public QWidget
{
Q_OBJECT
......@@ -32,8 +32,11 @@ public:
explicit GroupManagementWidget(QWidget *parent = nullptr);
~GroupManagementWidget() override;
private:
enum {
FullPathRole = Qt::UserRole + 1
};
void init();
QListView *const mListView;
QListWidget *const mListWidget;
};
#endif // GROUPMANAGEMENTWIDGET_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment