Commit 4a13af0a authored by Glen Ditchfield's avatar Glen Ditchfield 🐛
Browse files

Remove unused classes

The dialog classes are not used anywhere, and AutoCheckTreeWidget
is only used by the dialogs.
parent 1a66bac6
Pipeline #50598 passed with stage
in 12 minutes and 29 seconds
......@@ -48,11 +48,6 @@ set(incidenceeditors_ng_shared_LIB_SRCS
editorconfig.cpp
korganizereditorconfig.cpp
autochecktreewidget.cpp
categoryeditdialog.cpp
categoryselectdialog.cpp
categorydialog.cpp
# Individual mail
individualmailcomponentfactory.cpp
individualmaildialog.cpp
......@@ -84,9 +79,6 @@ set(incidenceeditors_ng_desktop_LIB_SRCS
)
ki18n_wrap_ui(incidenceeditors_ng_desktop_LIB_SRCS
ui/categoryeditdialog_base.ui
ui/categoryselectdialog_base.ui
ui/categorydialog_base.ui
ui/template_management_dialog_base.ui
ui/dialogdesktop.ui
ui/alarmdialog.ui
......
/*
SPDX-FileCopyrightText: 2007 Mathias Soeken <msoeken@tzi.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "autochecktreewidget.h"
using namespace IncidenceEditorNG;
//@cond PRIVATE
class Q_DECL_HIDDEN AutoCheckTreeWidget::Private
{
public:
bool mAutoCheckChildren = false;
bool mAutoCheck = true;
};
//@endcond
AutoCheckTreeWidget::AutoCheckTreeWidget(QWidget *parent)
: QTreeWidget(parent)
, d(new Private())
{
connect(model(), &QAbstractItemModel::rowsInserted, this, &AutoCheckTreeWidget::slotRowsInserted);
connect(model(), &QAbstractItemModel::dataChanged, this, &AutoCheckTreeWidget::slotDataChanged);
setColumnCount(2);
}
AutoCheckTreeWidget::~AutoCheckTreeWidget()
{
delete d;
}
QTreeWidgetItem *AutoCheckTreeWidget::itemByPath(const QStringList &path) const
{
QStringList newPath = path;
QTreeWidgetItem *item = nullptr;
while (!newPath.isEmpty()) {
item = findItem(item, newPath.takeFirst());
if (!item) {
return nullptr;
}
}
return item;
}
QStringList AutoCheckTreeWidget::pathByItem(QTreeWidgetItem *item) const
{
QStringList path;
QTreeWidgetItem *current = item;
while (current) {
path.prepend(current->text(0));
current = current->parent();
}
return path;
}
bool AutoCheckTreeWidget::autoCheckChildren() const
{
return d->mAutoCheckChildren;
}
void AutoCheckTreeWidget::setAutoCheckChildren(bool autoCheckChildren)
{
d->mAutoCheckChildren = autoCheckChildren;
}
bool AutoCheckTreeWidget::autoCheck() const
{
return d->mAutoCheck;
}
void AutoCheckTreeWidget::setAutoCheck(bool autoCheck)
{
d->mAutoCheck = autoCheck;
}
QTreeWidgetItem *AutoCheckTreeWidget::findItem(QTreeWidgetItem *parent, const QString &text) const
{
if (parent) {
const int nbChild{parent->childCount()};
for (int i = 0; i < nbChild; ++i) {
if (parent->child(i)->text(0) == text) {
return parent->child(i);
}
}
} else {
for (int i = 0; i < topLevelItemCount(); ++i) {
if (topLevelItem(i)->text(0) == text) {
return topLevelItem(i);
}
}
}
return nullptr;
}
void AutoCheckTreeWidget::slotRowsInserted(const QModelIndex &parent, int start, int end)
{
if (d->mAutoCheck) {
QTreeWidgetItem *item = itemFromIndex(parent);
QTreeWidgetItem *child = nullptr;
if (item) {
QBrush b(Qt::yellow);
item->setBackground(0, b);
for (int i = start; i < qMax(end, item->childCount()); ++i) {
child = item->child(i);
child->setFlags(child->flags() | Qt::ItemIsUserCheckable);
child->setCheckState(0, Qt::Unchecked);
}
} else { /* top level item has been inserted */
for (int i = start; i < qMax(end, topLevelItemCount()); ++i) {
child = topLevelItem(i);
child->setFlags(child->flags() | Qt::ItemIsUserCheckable);
child->setCheckState(0, Qt::Unchecked);
}
}
}
}
void AutoCheckTreeWidget::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
if (!d->mAutoCheckChildren) {
return;
}
QTreeWidgetItem *item1 = itemFromIndex(topLeft);
QTreeWidgetItem *item2 = itemFromIndex(bottomRight);
if (item1 == item2) {
for (int i = 0; i < item1->childCount(); ++i) {
item1->child(i)->setCheckState(0, item1->checkState(0));
}
}
}
/*
SPDX-FileCopyrightText: 2007 Mathias Soeken <msoeken@tzi.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef INCIDENCEEDITOR_AUTOCHECKTREEWIDGET_H
#define INCIDENCEEDITOR_AUTOCHECKTREEWIDGET_H
#include <QTreeWidget>
namespace IncidenceEditorNG
{
/**
A tree widget which supports auto selecting child items, when clicking
an item of the tree.
Further you can find an item by passing a path as QStringList with
the method itemByPath().
@author Mathias Soeken <msoeken@tzi.de>
*/
class AutoCheckTreeWidget : public QTreeWidget
{
Q_OBJECT
Q_PROPERTY(bool autoCheckChildren READ autoCheckChildren WRITE setAutoCheckChildren)
Q_PROPERTY(bool autoCheck READ autoCheck WRITE setAutoCheck)
public:
/**
Default constructor. The default behavior is like a QTreeWidget, so you
have to activate the autoCheckChildren property manually.
*/
explicit AutoCheckTreeWidget(QWidget *parent = nullptr);
~AutoCheckTreeWidget() override;
/**
Returns QTreeWidgetItem which matches the path, if available.
@param path The path
@returns a item which is represented by the path, if available.
*/
QTreeWidgetItem *itemByPath(const QStringList &path) const;
/**
Returns a path by a given item as QStringList.
@param item The item
@returns a string list which is the represented path of the item.
*/
Q_REQUIRED_RESULT QStringList pathByItem(QTreeWidgetItem *item) const;
/**
@returns whether autoCheckChildren is enabled or not.
Default value is false.
*/
Q_REQUIRED_RESULT bool autoCheckChildren() const;
/**
enables or disables autoCheckChildren behavior.
@param autoCheckChildren if true, children of items are auto checked or
not, otherwise. Default value is false.
*/
void setAutoCheckChildren(bool autoCheckChildren);
/**
@returns whether newly added items have checkboxes by default.
Default value is true.
*/
Q_REQUIRED_RESULT bool autoCheck() const;
/**
Sets whether newly added items have checkboxes by default.
@param autoCheck if true, newly added items have unchecked checkboxes
by default, otherwise not. Default value is true.
*/
void setAutoCheck(bool autoCheck);
protected:
QTreeWidgetItem *findItem(QTreeWidgetItem *parent, const QString &text) const;
protected Q_SLOTS:
void slotRowsInserted(const QModelIndex &parent, int start, int end);
void slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
};
}
#endif
/*
SPDX-FileCopyrightText: 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
SPDX-FileContributor: Sérgio Martins <sergio.martins@kdab.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "categorydialog.h"
#include "categoryhierarchyreader.h"
#include "ui_categorydialog_base.h"
#include <CalendarSupport/CategoryConfig>
#include <CalendarSupport/KCalPrefs>
#include <QDialogButtonBox>
#include <QIcon>
#include <QPushButton>
#include <QVBoxLayout>
using namespace IncidenceEditorNG;
using namespace CalendarSupport;
class CategoryWidgetBase : public QWidget, public Ui::CategoryDialog_base
{
public:
CategoryWidgetBase(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
};
CategoryWidget::CategoryWidget(CategoryConfig *cc, QWidget *parent)
: QWidget(parent)
, mCategoryConfig(cc)
{
auto topL = new QHBoxLayout(this);
topL->setContentsMargins(0, 0, 0, 0);
mWidgets = new CategoryWidgetBase(this);
topL->addWidget(mWidgets);
mWidgets->mButtonAdd->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
mWidgets->mButtonRemove->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
mWidgets->mLineEdit->setPlaceholderText(i18n("Click to add a new category"));
connect(mWidgets->mLineEdit, &QLineEdit::textChanged, this, &CategoryWidget::handleTextChanged);
mWidgets->mButtonAdd->setEnabled(false);
mWidgets->mButtonRemove->setEnabled(false);
mWidgets->mColorCombo->setEnabled(false);
connect(mWidgets->mCategories, &QTreeWidget::itemSelectionChanged, this, &CategoryWidget::handleSelectionChanged);
connect(mWidgets->mButtonAdd, &QAbstractButton::clicked, this, &CategoryWidget::addCategory);
connect(mWidgets->mButtonRemove, &QAbstractButton::clicked, this, &CategoryWidget::removeCategory);
connect(mWidgets->mColorCombo, &KColorCombo::activated, this, &CategoryWidget::handleColorChanged);
}
CategoryWidget::~CategoryWidget()
{
}
AutoCheckTreeWidget *CategoryWidget::listView() const
{
return mWidgets->mCategories;
}
void CategoryWidget::hideButton()
{
}
void CategoryWidget::setCategories(const QStringList &categoryList)
{
mWidgets->mCategories->clear();
mCategoryList.clear();
QStringList cats = mCategoryConfig->customCategories();
for (QStringList::ConstIterator it = categoryList.begin(), end = categoryList.end(); it != end; ++it) {
if (!cats.contains(*it)) {
cats.append(*it);
}
}
mCategoryConfig->setCustomCategories(cats);
CategoryHierarchyReaderQTreeWidget(mWidgets->mCategories).read(cats);
}
void CategoryWidget::setSelected(const QStringList &selList)
{
clear();
const bool remAutoCheckChildren = mWidgets->mCategories->autoCheckChildren();
mWidgets->mCategories->setAutoCheckChildren(false);
for (QStringList::ConstIterator it = selList.begin(), end = selList.end(); it != end; ++it) {
QStringList path = CategoryHierarchyReader::path(*it);
QTreeWidgetItem *item = mWidgets->mCategories->itemByPath(path);
if (item) {
item->setCheckState(0, Qt::Checked);
}
}
mWidgets->mCategories->setAutoCheckChildren(remAutoCheckChildren);
}
static QStringList getSelectedCategories(AutoCheckTreeWidget *categoriesView)
{
QStringList categories;
QTreeWidgetItemIterator it(categoriesView, QTreeWidgetItemIterator::Checked);
while (*it) {
QStringList path = categoriesView->pathByItem(*it++);
if (!path.isEmpty()) {
path.replaceInStrings(CategoryConfig::categorySeparator, QLatin1Char('\\') + CategoryConfig::categorySeparator);
categories.append(path.join(CategoryConfig::categorySeparator));
}
}
return categories;
}
void CategoryWidget::clear()
{
const bool remAutoCheckChildren = mWidgets->mCategories->autoCheckChildren();
mWidgets->mCategories->setAutoCheckChildren(false);
QTreeWidgetItemIterator it(mWidgets->mCategories);
while (*it) {
(*it++)->setCheckState(0, Qt::Unchecked);
}
mWidgets->mCategories->setAutoCheckChildren(remAutoCheckChildren);
}
void CategoryWidget::setAutoselectChildren(bool autoselectChildren)
{
mWidgets->mCategories->setAutoCheckChildren(autoselectChildren);
}
void CategoryWidget::hideHeader()
{
mWidgets->mCategories->header()->hide();
}
QStringList CategoryWidget::selectedCategories(QString &categoriesStr)
{
mCategoryList = getSelectedCategories(listView());
categoriesStr = mCategoryList.join(QLatin1String(", "));
return mCategoryList;
}
QStringList CategoryWidget::selectedCategories() const
{
return mCategoryList;
}
void CategoryWidget::setCategoryList(const QStringList &categories)
{
mCategoryList = categories;
}
void CategoryWidget::addCategory()
{
QTreeWidgetItem *newItem = new QTreeWidgetItem(listView(), QStringList(mWidgets->mLineEdit->text()));
listView()->scrollToItem(newItem);
listView()->clearSelection();
newItem->setSelected(true);
}
void CategoryWidget::removeCategory()
{
// Multi-select not supported, only one selected
QTreeWidgetItem *itemToDelete = listView()->selectedItems().first();
delete itemToDelete;
}
void CategoryWidget::handleTextChanged(const QString &newText)
{
mWidgets->mButtonAdd->setEnabled(!newText.isEmpty());
}
void CategoryWidget::handleSelectionChanged()
{
const bool hasSelection = !listView()->selectedItems().isEmpty();
mWidgets->mButtonRemove->setEnabled(hasSelection);
mWidgets->mColorCombo->setEnabled(hasSelection);
if (hasSelection) {
const QTreeWidgetItem *item = listView()->selectedItems().first();
const QColor &color = KCalPrefs::instance()->categoryColor(item->text(0));
if (color.isValid()) {
mWidgets->mColorCombo->setColor(color);
// update is needed. bug in KColorCombo?
mWidgets->mColorCombo->update();
}
}
}
void CategoryWidget::handleColorChanged(const QColor &newColor)
{
if (!listView()->selectedItems().isEmpty()) {
const QTreeWidgetItem *item = listView()->selectedItems().first();
const QString category = item->text(0);
if (newColor.isValid()) {
KCalPrefs::instance()->setCategoryColor(category, newColor);
}
}
}
CategoryDialog::CategoryDialog(CategoryConfig *cc, QWidget *parent)
: QDialog(parent)
, d(nullptr)
{
setWindowTitle(i18nc("@title:window", "Select Categories"));
auto mainLayout = new QVBoxLayout(this);
QDialogButtonBox *buttonBox =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel /*| QDialogButtonBox::Help*/ | QDialogButtonBox::Apply, this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::rejected, this, &CategoryDialog::reject);
QWidget *page = new QWidget;
mainLayout->addWidget(page);
mainLayout->addWidget(buttonBox);
auto lay = new QVBoxLayout(page);
lay->setContentsMargins(0, 0, 0, 0);
mWidgets = new CategoryWidget(cc, this);
mCategoryConfig = cc;
mWidgets->setObjectName(QStringLiteral("CategorySelection"));
mWidgets->hideHeader();
lay->addWidget(mWidgets);
mWidgets->setCategories();
mWidgets->listView()->setFocus();
connect(okButton, &QPushButton::clicked, this, &CategoryDialog::slotOk);
connect(buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &CategoryDialog::slotApply);
}
CategoryDialog::~CategoryDialog()
{
delete mWidgets;
}
QStringList CategoryDialog::selectedCategories() const
{
return mWidgets->selectedCategories();
}
void CategoryDialog::slotApply()
{
QStringList l;
QStringList path;
QTreeWidgetItemIterator it(mWidgets->listView());
while (*it) {
path = mWidgets->listView()->pathByItem(*it++);
path.replaceInStrings(CategoryConfig::categorySeparator, QLatin1Char('\\') + CategoryConfig::categorySeparator);
l.append(path.join(CategoryConfig::categorySeparator));
}
mCategoryConfig->setCustomCategories(l);
mCategoryConfig->writeConfig();
QString categoriesStr;
QStringList categories = mWidgets->selectedCategories(categoriesStr);
Q_EMIT categoriesSelected(categories);
Q_EMIT categoriesSelected(categoriesStr);
}
void CategoryDialog::slotOk()
{
slotApply();
accept();
}
void CategoryDialog::updateCategoryConfig()
{
QString tmp;
QStringList selected = mWidgets->selectedCategories(tmp);
mWidgets->setCategories();
mWidgets->setSelected(selected);
}
void CategoryDialog::setAutoselectChildren(bool autoselectChildren)
{
mWidgets->setAutoselectChildren(autoselectChildren);
}
void CategoryDialog::setCategoryList(const QStringList &categories)
{
mWidgets->setCategoryList(categories);
}
void CategoryDialog::setSelected(const QStringList &selList)
{
mWidgets->setSelected(selList);
}
/*
SPDX-FileCopyrightText: 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
SPDX-FileContributor: Sérgio Martins <sergio.martins@kdab.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef INCIDENCEEDITOR_CATEGORYDIALOG_H
#define INCIDENCEEDITOR_CATEGORYDIALOG_H
#include <QDialog>
class CategoryWidgetBase;
namespace CalendarSupport
{
class CategoryConfig;
}
namespace IncidenceEditorNG
{
class AutoCheckTreeWidget;
class CategoryWidget : public QWidget
{
Q_OBJECT
public:
explicit CategoryWidget(CalendarSupport::CategoryConfig *config, QWidget *parent = nullptr);
~CategoryWidget() override;
void setCategories(const QStringList &categoryList = QStringList());
void setCategoryList(const QStringList &categories);
void setSelected(const QStringList &selList);
Q_REQUIRED_RESULT QStringList selectedCategories() const;
Q_REQUIRED_RESULT QStringList selectedCategories(QString &categoriesStr);
void setAutoselectChildren(bool autoselectChildren);
void hideButton();
void hideHeader();
Q_REQUIRED_RESULT AutoCheckTreeWidget *listView() const;
public Q_SLOTS:
void clear();
private:
void handleTextChanged(const QString &newText);
void handleSelectionChanged();
void handleColorChanged(const QColor &);
void addCategory();