Commit 837bffd9 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix hide item

parent 95bd0782
#include "selectiontypedialogtest.h"
SelectionTypeDialogTest::SelectionTypeDialogTest(QObject *parent) : QObject(parent)
{
}
#ifndef SELECTIONTYPEDIALOGTEST_H
#define SELECTIONTYPEDIALOGTEST_H
class SelectionTypeDialogTest : public QObject
{
Q_OBJECT
public:
explicit SelectionTypeDialogTest(QObject *parent = nullptr);
signals:
public slots:
};
#endif // SELECTIONTYPEDIALOGTEST_H
\ No newline at end of file
......@@ -44,15 +44,15 @@ void SelectionTypeTreeWidgetTest::shouldHaveDefaultSelectedWidget()
void SelectionTypeTreeWidgetTest::shouldLoadTemplate_data()
{
QTest::addColumn<QString>("filename");
QTest::addColumn<int>("numberItems");
QTest::newRow("selectedtypemodel1.xml") << QStringLiteral("selectedtypemodel1.xml") << 7;
QTest::newRow("selectedtypemodel2.xml") << QStringLiteral("selectedtypemodel2.xml") << 3;
QTest::addColumn<int>("topLevelItems");
QTest::newRow("selectedtypemodel1.xml") << QStringLiteral("selectedtypemodel1.xml") << 4;
QTest::newRow("selectedtypemodel2.xml") << QStringLiteral("selectedtypemodel2.xml") << 1;
}
void SelectionTypeTreeWidgetTest::shouldLoadTemplate()
{
QFETCH(QString, filename);
QFETCH(int, numberItems);
QFETCH(int, topLevelItems);
QString fileNameFullPath = QLatin1String(PIMDATAEXPORTER_DATA_DIR) + QLatin1String("/") + filename;
......@@ -66,7 +66,7 @@ void SelectionTypeTreeWidgetTest::shouldLoadTemplate()
w.show();
QTest::qWait(5000);
#endif
QCOMPARE(w.topLevelItemCount(), numberItems);
QCOMPARE(w.topLevelItemCount(), topLevelItems);
}
......
......@@ -97,29 +97,49 @@ void SelectionTypeTreeWidget::initialize()
void SelectionTypeTreeWidget::removeNotSelectedItems()
{
removeNotSelectedItem(mKmailItem);
removeNotSelectedItem(mKalarmItem);
removeNotSelectedItem(mKaddressbookItem);
removeNotSelectedItem(mKorganizerItem);
removeNotSelectedItem(mKNotesItem);
removeNotSelectedItem(mAkregatorItem);
removeNotSelectedItem(mBlogiloItem);
if (!removeNotSelectedItem(mKmailItem)) {
delete mKmailItem;
mKmailItem = nullptr;
}
if (!removeNotSelectedItem(mKalarmItem)) {
delete mKalarmItem;
mKalarmItem = nullptr;
}
if (!removeNotSelectedItem(mKaddressbookItem)) {
delete mKaddressbookItem;
mKaddressbookItem = nullptr;
}
if (!removeNotSelectedItem(mKorganizerItem)) {
delete mKorganizerItem;
mKorganizerItem = nullptr;
}
if (!removeNotSelectedItem(mKNotesItem)) {
delete mKNotesItem;
mKNotesItem = nullptr;
}
if (!removeNotSelectedItem(mAkregatorItem)) {
delete mAkregatorItem;
mAkregatorItem = nullptr;
}
if (!removeNotSelectedItem(mBlogiloItem)) {
delete mBlogiloItem;
mBlogiloItem = nullptr;
}
}
void SelectionTypeTreeWidget::removeNotSelectedItem(QTreeWidgetItem *parent)
bool SelectionTypeTreeWidget::removeNotSelectedItem(QTreeWidgetItem *parent)
{
for (int i = 0; i < parent->childCount(); ++i) {
for (int i = parent->childCount() - 1; i >= 0; --i) {
QTreeWidgetItem *item = parent->child(i);
if (item->checkState(0) == Qt::Unchecked) {
delete item;
}
}
if (parent->childCount() == 0) {
delete parent;
parent = nullptr;
} else {
bool hasChildren = (parent->childCount() != 0);
if (hasChildren) {
parent->setCheckState(0, Qt::Checked);
}
return hasChildren;
}
QHash<Utils::AppsType, Utils::importExportParameters> SelectionTypeTreeWidget::storedType() const
......@@ -255,12 +275,14 @@ void SelectionTypeTreeWidget::setSelectItems(bool b)
void SelectionTypeTreeWidget::changeState(QTreeWidgetItem *item, bool b)
{
blockSignals(true);
item->setCheckState(0, b ? Qt::Checked : Qt::Unchecked);
for (int i = 0; i < item->childCount(); ++i) {
item->child(i)->setCheckState(0, b ? Qt::Checked : Qt::Unchecked);
if (item) {
blockSignals(true);
item->setCheckState(0, b ? Qt::Checked : Qt::Unchecked);
for (int i = 0; i < item->childCount(); ++i) {
item->child(i)->setCheckState(0, b ? Qt::Checked : Qt::Unchecked);
}
blockSignals(false);
}
blockSignals(false);
}
void SelectionTypeTreeWidget::slotItemChanged(QTreeWidgetItem *item, int column)
......
......@@ -64,7 +64,7 @@ private:
void initializeSubItem(QTreeWidgetItem *item, Utils::StoredTypes types);
void loadFileName(const QString &fileName);
QString templateSelectionToString();
void removeNotSelectedItem(QTreeWidgetItem *parent);
bool removeNotSelectedItem(QTreeWidgetItem *parent);
QTreeWidgetItem *mKmailItem;
QTreeWidgetItem *mKalarmItem;
......
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