diff --git a/src/avatars.cpp b/src/avatars.cpp index 3a6931fe5..eacd462d1 100644 --- a/src/avatars.cpp +++ b/src/avatars.cpp @@ -243,7 +243,7 @@ class AvatarCache : public FileCache { #ifdef AVATAR_EDBUG qDebug() << "remove from iconset and emit avatarChanged on itemPublished" << jidFull; #endif - iconset_->removeIcon(QString(QLatin1String("avatars/%1")).arg(jidFull)); + iconset_.removeIcon(QString(QLatin1String("avatars/%1")).arg(jidFull)); emit avatarChanged(jidFull); } } @@ -263,7 +263,7 @@ class AvatarCache : public FileCache { qDebug() << "remove from iconset and emit avatarChanged. ensureVCardUpdated hash=" << hash.toHex() << fullJid; #endif - iconset_->removeIcon(QString(QLatin1String("avatars/%1")).arg(fullJid)); + iconset_.removeIcon(QString(QLatin1String("avatars/%1")).arg(fullJid)); emit avatarChanged(fullJid); } @@ -280,7 +280,7 @@ class AvatarCache : public FileCache { #ifdef AVATAR_EDBUG qDebug() << "remove from iconset and emit avatarChanged. importManualAvatar" << j.bare(); #endif - iconset_->removeIcon(QString(QLatin1String("avatars/%1")).arg(j.bare())); + iconset_.removeIcon(QString(QLatin1String("avatars/%1")).arg(j.bare())); emit avatarChanged(j); } @@ -290,7 +290,7 @@ class AvatarCache : public FileCache { #ifdef AVATAR_EDBUG qDebug() << "remove from iconset and emit avatarChanged. removeManualAvatar" << j.bare(); #endif - iconset_->removeIcon(QString(QLatin1String("avatars/%1")).arg(j.bare())); + iconset_.removeIcon(QString(QLatin1String("avatars/%1")).arg(j.bare())); emit avatarChanged(j); } } @@ -299,7 +299,7 @@ class AvatarCache : public FileCache { { QString bareJid = _jid.bare(); QString iconName = QString("avatars/%1").arg(bareJid); - auto iconp = iconset_->icon(iconName); + auto iconp = iconset_.icon(iconName); if (iconp) { #ifdef AVATAR_EDBUG qDebug() << "return icons" << iconName << "from iconset for jid" << bareJid; @@ -353,7 +353,7 @@ class AvatarCache : public FileCache { #ifdef AVATAR_EDBUG qDebug() << "setting icon to iconset " << iconName << "=" << pm; #endif - iconset_->setIcon(iconName, icon); + iconset_.setIcon(iconName, icon); return pm; } @@ -363,7 +363,7 @@ class AvatarCache : public FileCache { QString fullJid = _jid.full(); QString iconName = QString("avatars/%1").arg(fullJid); - auto iconp = iconset_->icon(iconName); + auto iconp = iconset_.icon(iconName); if (iconp) { return iconp->pixmap(); } @@ -400,7 +400,7 @@ class AvatarCache : public FileCache { #ifdef AVATAR_EDBUG qDebug() << "setting icon " << QString("avatars/%1").arg(fullJid) << "=" << pm; #endif - iconset_->setIcon(QString("avatars/%1").arg(fullJid), icon); // FIXME do we ever release it? + iconset_.setIcon(QString("avatars/%1").arg(fullJid), icon); // FIXME do we ever release it? return pm; } @@ -577,8 +577,7 @@ class AvatarCache : public FileCache { AvatarCache() : FileCache(AvatarFactory::getCacheDir()) { // Register iconset - iconset_ = new Iconset(); - iconset_->addToFactory(); // the factory will own the iconset + iconset_.addToFactory(); // the factory will own the iconset updateJids(); connect(VCardFactory::instance(), &VCardFactory::vcardChanged, this, @@ -611,7 +610,7 @@ class AvatarCache : public FileCache { #ifdef AVATAR_EDBUG qDebug() << "removing icon from iconset:" << QString(QLatin1String("avatars/%1")).arg(fullJid); #endif - iconset_->removeIcon(QString(QLatin1String("avatars/%1")).arg(fullJid)); + iconset_.removeIcon(QString(QLatin1String("avatars/%1")).arg(fullJid)); emit avatarChanged(j); } }); @@ -858,7 +857,7 @@ class AvatarCache : public FileCache { QHash jidToIcons; QHash jid2hash; - Iconset *iconset_; + Iconset iconset_; static AvatarCache *_instance; }; diff --git a/src/contactlistviewdelegate.cpp b/src/contactlistviewdelegate.cpp index 50e2e7520..3fa319703 100644 --- a/src/contactlistviewdelegate.cpp +++ b/src/contactlistviewdelegate.cpp @@ -133,7 +133,7 @@ ContactListViewDelegate::Private::Private(ContactListViewDelegate *parent, Conta statusIconSize_ = PsiIconset::instance() ->roster.value(PsiOptions::instance()->getOption(statusIconsetOptionPath).toString()) - ->iconSize(); + .iconSize(); optionChanged("*"); colorOptionChanged("*"); diff --git a/src/options/opt_iconset.cpp b/src/options/opt_iconset.cpp index e07d9e841..9f99c2893 100644 --- a/src/options/opt_iconset.cpp +++ b/src/options/opt_iconset.cpp @@ -27,6 +27,8 @@ #include #include +#include + class IconsetEmoUI : public QWidget, public Ui::IconsetEmo { public: IconsetEmoUI() : QWidget() { setupUi(this); } @@ -196,16 +198,19 @@ static int countKdeEmoticonsIconsets(QStringList excludeList) class IconsetLoadEvent : public QEvent { public: - IconsetLoadEvent(IconsetLoadThread *par, Iconset *i) : QEvent(QEvent::User), p(par), is(i) { } + IconsetLoadEvent(IconsetLoadThread *par, std::optional i = {}) : + QEvent(QEvent::User), p(par), is(std::move(i)) + { + } IconsetLoadThread *thread() const { return p; } // if iconset() is '0' then it means that iconset wasn't loaded successfully - Iconset *iconset() const { return is; } + std::optional iconset() const { return is; } private: - IconsetLoadThread *p; - Iconset *is; + IconsetLoadThread *p; + std::optional is; }; //---------------------------------------------------------------------------- @@ -214,7 +219,7 @@ class IconsetLoadEvent : public QEvent { class IconsetFinishEvent : public QEvent { public: - IconsetFinishEvent() : QEvent((QEvent::Type)(QEvent::User + 1)) { } + IconsetFinishEvent() : QEvent(static_cast(QEvent::User + 1)) { } }; //---------------------------------------------------------------------------- @@ -223,7 +228,7 @@ class IconsetFinishEvent : public QEvent { class IconsetLoadThreadDestroyEvent : public QEvent { public: - IconsetLoadThreadDestroyEvent(QThread *t) : QEvent((QEvent::Type)(QEvent::User + 2)), thread(t) { } + IconsetLoadThreadDestroyEvent(QThread *t) : QEvent(static_cast(QEvent::User + 2)), thread(t) { } ~IconsetLoadThreadDestroyEvent() { @@ -288,7 +293,7 @@ void IconsetLoadThread::run() loadKdeEmoticons(); for (int i = 0; i < failedList.size(); i++) { - postEvent(new IconsetLoadEvent(this, nullptr)); + postEvent(new IconsetLoadEvent(this)); } postEvent(new IconsetFinishEvent()); @@ -316,16 +321,15 @@ void IconsetLoadThread::loadKdeEmoticons() if (excludeList.contains(iconsetId) || !Iconset::isSourceAllowed(fi)) continue; - Iconset *is = new Iconset; + Iconset is; - if (is->load(fi.absoluteFilePath(), Iconset::Format::KdeEmoticons)) { - failedList.removeOne(is->id()); - excludeList << is->id(); + if (is.load(fi.absoluteFilePath(), Iconset::Format::KdeEmoticons)) { + failedList.removeOne(is.id()); + excludeList << is.id(); // don't forget to delete iconset in ::event()! postEvent(new IconsetLoadEvent(this, is)); } else { - delete is; failedList << iconsetId; } } @@ -356,16 +360,15 @@ void IconsetLoadThread::loadPsiIconsets() if (excludeList.contains(iconsetId)) continue; - Iconset *is = new Iconset; + Iconset is; - if (is->load(iconsetFI.absoluteFilePath())) { - failedList.removeOne(is->id()); - excludeList << is->id(); + if (is.load(iconsetFI.absoluteFilePath())) { + failedList.removeOne(is.id()); + excludeList << is.id(); // don't forget to delete iconset in ::event()! postEvent(new IconsetLoadEvent(this, is)); } else { - delete is; failedList << iconsetId; } } @@ -405,9 +408,9 @@ void OptionsTabIconsetSystem::applyOptions() return; IconsetSystemUI *d = static_cast(w); - const Iconset *is = d->iss_system->iconset(); - if (is) { - QFileInfo fi(is->fileName()); + Iconset is = d->iss_system->iconset(); + if (is.count() > 0) { + QFileInfo fi(is.fileName()); PsiOptions::instance()->setOption("options.iconsets.system", fi.fileName()); } } @@ -451,16 +454,14 @@ bool OptionsTabIconsetSystem::event(QEvent *e) numIconsets = 1; d->progress->setValue(int((float(100 * ++iconsetsLoaded / numIconsets)))); - Iconset *i = le->iconset(); - if (i) { - PsiIconset::instance()->stripFirstAnimFrame(i); - d->iss_system->insert(*i); + auto iopt = le->iconset(); + if (iopt) { + PsiIconset::instance()->stripFirstAnimFrame(*iopt); + d->iss_system->insert(*iopt); - QFileInfo fi(i->fileName()); + QFileInfo fi(iopt->fileName()); if (fi.fileName() == PsiOptions::instance()->getOption("options.iconsets.system").toString()) d->iss_system->lastItem()->setSelected(true); - - delete i; } return true; @@ -484,9 +485,9 @@ bool OptionsTabIconsetSystem::event(QEvent *e) void OptionsTabIconsetSystem::previewIconset() { IconsetSystemUI *d = static_cast(w); - const Iconset *is = d->iss_system->iconset(); - if (is) { - isDetails(*is, parentWidget->parentWidget(), psi); + Iconset is = d->iss_system->iconset(); + if (is.count() > 0) { + isDetails(is, parentWidget->parentWidget(), psi); } } @@ -556,9 +557,9 @@ void OptionsTabIconsetEmoticons::applyOptions() IconWidgetItem *item = static_cast(d->iss_emoticons->item(row)); if (item->isSelected()) { - const Iconset *is = item->iconset(); - if (is) { - QFileInfo fi(is->fileName()); + auto is = item->iconset(); + if (is.count() > 0) { + QFileInfo fi(is.fileName()); list << fi.fileName(); } } @@ -578,8 +579,8 @@ void OptionsTabIconsetEmoticons::restoreOptions() d->iss_emoticons->clear(); { - for (Iconset *is : std::as_const(PsiIconset::instance()->emoticons)) { - d->iss_emoticons->insert(*is); + for (const Iconset &is : std::as_const(PsiIconset::instance()->emoticons)) { + d->iss_emoticons->insert(is); d->iss_emoticons->lastItem()->setSelected(true); } } @@ -587,8 +588,8 @@ void OptionsTabIconsetEmoticons::restoreOptions() { QStringList loaded; { - for (Iconset *tmp : std::as_const(PsiIconset::instance()->emoticons)) { - loaded << tmp->id(); + for (const Iconset &tmp : std::as_const(PsiIconset::instance()->emoticons)) { + loaded << tmp.id(); } } @@ -625,11 +626,10 @@ bool OptionsTabIconsetEmoticons::event(QEvent *e) numIconsets = 1; d->progress->setValue(int(float(100 * ++iconsetsLoaded / numIconsets))); - Iconset *is = le->iconset(); - if (is) { - PsiIconset::removeAnimation(is); - d->iss_emoticons->insert(*is); - delete is; + auto isopt = le->iconset(); + if (isopt) { + PsiIconset::removeAnimation(*isopt); + d->iss_emoticons->insert(*isopt); } return true; @@ -657,10 +657,10 @@ bool OptionsTabIconsetEmoticons::event(QEvent *e) void OptionsTabIconsetEmoticons::previewIconset() { - IconsetEmoUI *d = static_cast(w); - const Iconset *is = d->iss_emoticons->iconset(); - if (is) { - isDetails(*is, parentWidget->parentWidget(), psi); + IconsetEmoUI *d = static_cast(w); + Iconset is = d->iss_emoticons->iconset(); + if (is.count() > 0) { + isDetails(is, parentWidget->parentWidget(), psi); } } @@ -712,9 +712,9 @@ void OptionsTabIconsetMoods::applyOptions() IconsetMoodUI *d = static_cast(w); - const Iconset *is = d->iss_moods->iconset(); - if (is) { - QFileInfo fi(is->fileName()); + Iconset is = d->iss_moods->iconset(); + if (is.count() > 0) { + QFileInfo fi(is.fileName()); PsiOptions::instance()->setOption("options.iconsets.moods", fi.fileName()); } } @@ -764,16 +764,14 @@ bool OptionsTabIconsetMoods::event(QEvent *e) numIconsets = 1; d->progress->setValue(int(float(100 * ++iconsetsLoaded / numIconsets))); - Iconset *i = le->iconset(); + auto i = le->iconset(); if (i) { - PsiIconset::instance()->stripFirstAnimFrame(i); + PsiIconset::instance()->stripFirstAnimFrame(*i); d->iss_moods->insert(*i); QFileInfo fi(i->fileName()); if (fi.fileName() == PsiOptions::instance()->getOption("options.iconsets.moods").toString()) d->iss_moods->lastItem()->setSelected(true); - - delete i; } return true; @@ -800,9 +798,9 @@ bool OptionsTabIconsetMoods::event(QEvent *e) void OptionsTabIconsetMoods::previewIconset() { IconsetMoodUI *d = static_cast(w); - const Iconset *is = d->iss_moods->iconset(); - if (is) { - isDetails(*is, parentWidget->parentWidget(), psi); + const Iconset is = d->iss_moods->iconset(); + if (is.count() > 0) { + isDetails(is, parentWidget->parentWidget(), psi); } } @@ -854,9 +852,9 @@ void OptionsTabIconsetActivity::applyOptions() IconsetActivityUI *d = static_cast(w); - const Iconset *is = d->iss_activity->iconset(); - if (is) { - QFileInfo fi(is->fileName()); + const Iconset is = d->iss_activity->iconset(); + if (!is.isEmpty()) { + QFileInfo fi(is.fileName()); PsiOptions::instance()->setOption("options.iconsets.activities", fi.fileName()); } } @@ -906,16 +904,14 @@ bool OptionsTabIconsetActivity::event(QEvent *e) numIconsets = 1; d->progress->setValue(int(float(100 * ++iconsetsLoaded / numIconsets))); - Iconset *i = le->iconset(); + auto i = le->iconset(); if (i) { - PsiIconset::instance()->stripFirstAnimFrame(i); + PsiIconset::instance()->stripFirstAnimFrame(*i); d->iss_activity->insert(*i); QFileInfo fi(i->fileName()); if (fi.fileName() == PsiOptions::instance()->getOption("options.iconsets.activities").toString()) d->iss_activity->lastItem()->setSelected(true); - - delete i; } return true; @@ -943,9 +939,9 @@ bool OptionsTabIconsetActivity::event(QEvent *e) void OptionsTabIconsetActivity::previewIconset() { IconsetActivityUI *d = static_cast(w); - const Iconset *is = d->iss_activity->iconset(); - if (is) { - isDetails(*is, parentWidget->parentWidget(), psi); + const Iconset is = d->iss_activity->iconset(); + if (!is.isEmpty()) { + isDetails(is, parentWidget->parentWidget(), psi); } } @@ -997,9 +993,9 @@ void OptionsTabIconsetAffiliations::applyOptions() IconsetAffiliationUI *d = static_cast(w); - const Iconset *is = d->iss_affiliation->iconset(); - if (is) { - QFileInfo fi(is->fileName()); + const Iconset is = d->iss_affiliation->iconset(); + if (!is.isEmpty()) { + QFileInfo fi(is.fileName()); PsiOptions::instance()->setOption("options.iconsets.affiliations", fi.fileName()); } } @@ -1049,16 +1045,14 @@ bool OptionsTabIconsetAffiliations::event(QEvent *e) numIconsets = 1; d->progress->setValue(int(float(100 * ++iconsetsLoaded / numIconsets))); - Iconset *i = le->iconset(); + auto i = le->iconset(); if (i) { - PsiIconset::instance()->stripFirstAnimFrame(i); + PsiIconset::instance()->stripFirstAnimFrame(*i); d->iss_affiliation->insert(*i); QFileInfo fi(i->fileName()); if (fi.fileName() == PsiOptions::instance()->getOption("options.iconsets.affiliations").toString()) d->iss_affiliation->lastItem()->setSelected(true); - - delete i; } return true; @@ -1086,9 +1080,9 @@ bool OptionsTabIconsetAffiliations::event(QEvent *e) void OptionsTabIconsetAffiliations::previewIconset() { IconsetAffiliationUI *d = static_cast(w); - const Iconset *is = d->iss_affiliation->iconset(); - if (is) { - isDetails(*is, parentWidget->parentWidget(), psi); + const Iconset is = d->iss_affiliation->iconset(); + if (!is.isEmpty()) { + isDetails(is, parentWidget->parentWidget(), psi); } } @@ -1141,9 +1135,9 @@ void OptionsTabIconsetClients::applyOptions() IconsetClientUI *d = static_cast(w); - const Iconset *is = d->iss_clients->iconset(); - if (is) { - QFileInfo fi(is->fileName()); + const Iconset is = d->iss_clients->iconset(); + if (!is.isEmpty()) { + QFileInfo fi(is.fileName()); PsiOptions::instance()->setOption("options.iconsets.clients", fi.fileName()); } } @@ -1193,16 +1187,14 @@ bool OptionsTabIconsetClients::event(QEvent *e) numIconsets = 1; d->progress->setValue(int(float(100 * ++iconsetsLoaded / numIconsets))); - Iconset *i = le->iconset(); + auto i = le->iconset(); if (i) { - PsiIconset::instance()->stripFirstAnimFrame(i); + PsiIconset::instance()->stripFirstAnimFrame(*i); d->iss_clients->insert(*i); QFileInfo fi(i->fileName()); if (fi.fileName() == PsiOptions::instance()->getOption("options.iconsets.clients").toString()) d->iss_clients->lastItem()->setSelected(true); - - delete i; } return true; @@ -1230,9 +1222,9 @@ bool OptionsTabIconsetClients::event(QEvent *e) void OptionsTabIconsetClients::previewIconset() { IconsetClientUI *d = static_cast(w); - const Iconset *is = d->iss_clients->iconset(); - if (is) { - isDetails(*is, parentWidget->parentWidget(), psi); + const Iconset is = d->iss_clients->iconset(); + if (!is.isEmpty()) { + isDetails(is, parentWidget->parentWidget(), psi); } } @@ -1340,9 +1332,9 @@ void OptionsTabIconsetRoster::applyOptions() // roster - default { - const Iconset *is = d->iss_defRoster->iconset(); - if (is) { - QFileInfo fi(is->fileName()); + const Iconset is = d->iss_defRoster->iconset(); + if (!is.isEmpty()) { + QFileInfo fi(is.fileName()); PsiOptions::instance()->setOption("options.iconsets.status", fi.fileName()); } } @@ -1423,9 +1415,9 @@ bool OptionsTabIconsetRoster::event(QEvent *e) numIconsets = 1; d->progress->setValue(int(float(100 * ++iconsetsLoaded / numIconsets))); - Iconset *i = le->iconset(); + auto i = le->iconset(); if (i) { - PsiIconset::instance()->stripFirstAnimFrame(i); + PsiIconset::instance()->stripFirstAnimFrame(*i); QFileInfo fi(i->fileName()); // roster - default @@ -1438,8 +1430,6 @@ bool OptionsTabIconsetRoster::event(QEvent *e) // roster - custom d->iss_customRoster->insert(*i); - - delete i; } return true; @@ -1454,9 +1444,9 @@ bool OptionsTabIconsetRoster::event(QEvent *e) auto mapPath = PsiOptions::instance()->mapLookup("options.iconsets.service-status", i->data(0, ServiceRole).toString()); if (mapPath.has_value()) { - Iconset *iss = PsiIconset::instance()->roster.value( + auto iss = PsiIconset::instance()->roster.find( PsiOptions::instance()->getOption(*mapPath + ".iconset").toString()); - if (iss) { + if (iss != PsiIconset::instance()->roster.end()) { i->setText(1, iss->name()); QFileInfo fi(iss->fileName()); i->setData(0, IconsetRole, fi.fileName()); @@ -1482,8 +1472,8 @@ bool OptionsTabIconsetRoster::event(QEvent *e) item->setText(0, clipCustomText(regexp)); item->setData(0, RegexpRole, regexp); - Iconset *iss = PsiIconset::instance()->roster[icoset]; - if (iss) { + auto iss = PsiIconset::instance()->roster.find(icoset); + if (iss != PsiIconset::instance()->roster.end()) { item->setText(1, iss->name()); QFileInfo fi(iss->fileName()); item->setData(0, IconsetRole, fi.fileName()); @@ -1522,27 +1512,27 @@ void OptionsTabIconsetRoster::setData(PsiCon *psicon, QWidget *p) void OptionsTabIconsetRoster::defaultDetails() { IconsetRosterUI *d = static_cast(w); - const Iconset *is = d->iss_defRoster->iconset(); - if (is) { - isDetails(*is, parentWidget->parentWidget(), psi); + const Iconset is = d->iss_defRoster->iconset(); + if (!is.isEmpty()) { + isDetails(is, parentWidget->parentWidget(), psi); } } void OptionsTabIconsetRoster::servicesDetails() { IconsetRosterUI *d = static_cast(w); - const Iconset *is = d->iss_servicesRoster->iconset(); - if (is) { - isDetails(*is, parentWidget->parentWidget(), psi); + const Iconset is = d->iss_servicesRoster->iconset(); + if (!is.isEmpty()) { + isDetails(is, parentWidget->parentWidget(), psi); } } void OptionsTabIconsetRoster::customDetails() { IconsetRosterUI *d = static_cast(w); - const Iconset *is = d->iss_customRoster->iconset(); - if (is) { - isDetails(*is, parentWidget->parentWidget(), psi); + const Iconset is = d->iss_customRoster->iconset(); + if (!is.isEmpty()) { + isDetails(is, parentWidget->parentWidget(), psi); } } @@ -1558,12 +1548,12 @@ void OptionsTabIconsetRoster::isServices_iconsetSelected(QListWidgetItem *item, if (!it) return; - const Iconset *is = static_cast(item)->iconset(); - if (!is) + auto is = static_cast(item)->iconset(); + if (is.isEmpty()) return; - it->setText(1, is->name()); - QFileInfo fi(is->fileName()); + it->setText(1, is.name()); + QFileInfo fi(is.fileName()); it->setData(0, IconsetRole, fi.fileName()); } @@ -1583,9 +1573,9 @@ void OptionsTabIconsetRoster::isServices_selectionChanged(QTreeWidgetItem *it) emit noDirty(true); for (int row = 0; row < d->iss_servicesRoster->count(); row++) { IconWidgetItem *item = static_cast(d->iss_servicesRoster->item(row)); - const Iconset *is = item->iconset(); - if (is) { - QFileInfo fi(is->fileName()); + auto is = item->iconset(); + if (!is.isEmpty()) { + QFileInfo fi(is.fileName()); if (fi.fileName() == name) { emit noDirty(true); item->setSelected(true); @@ -1611,12 +1601,12 @@ void OptionsTabIconsetRoster::isCustom_iconsetSelected(QListWidgetItem *item, QL if (!it) return; - const Iconset *is = static_cast(item)->iconset(); - if (!is) + auto is = static_cast(item)->iconset(); + if (is.isEmpty()) return; - it->setText(1, is->name()); - QFileInfo fi(is->fileName()); + it->setText(1, is.name()); + QFileInfo fi(is.fileName()); it->setData(0, IconsetRole, fi.fileName()); } @@ -1641,9 +1631,9 @@ void OptionsTabIconsetRoster::isCustom_selectionChanged(QTreeWidgetItem *it) for (int row = 0; row < d->iss_customRoster->count(); row++) { IconWidgetItem *item = static_cast(d->iss_customRoster->item(row)); - const Iconset *is = item->iconset(); - if (is) { - QFileInfo fi(is->fileName()); + auto is = item->iconset(); + if (!is.isEmpty()) { + QFileInfo fi(is.fileName()); if (fi.fileName() == name) { item->setSelected(true); d->iss_customRoster->scrollToItem(item); @@ -1670,17 +1660,17 @@ void OptionsTabIconsetRoster::isCustom_add() { IconsetRosterUI *d = static_cast(w); - QString def; - const Iconset *iconset = d->iss_defRoster->iconset(); - if (iconset) { - QFileInfo fi(iconset->fileName()); + QString def; + const Iconset iconset = d->iss_defRoster->iconset(); + if (!iconset.isEmpty()) { + QFileInfo fi(iconset.fileName()); def = fi.fileName(); } else qWarning("OptionsTabIconsetRoster::isCustom_add(): 'def' is null!"); QTreeWidgetItem *item = new QTreeWidgetItem(d->tw_customRoster); - const Iconset *i = PsiIconset::instance()->roster[def]; - if (i) { + auto i = PsiIconset::instance()->roster.find(def); + if (i != PsiIconset::instance()->roster.end()) { item->setText(1, i->name()); QFileInfo fi(i->fileName()); diff --git a/src/pluginhost.cpp b/src/pluginhost.cpp index e81ae759c..a0e2dd473 100644 --- a/src/pluginhost.cpp +++ b/src/pluginhost.cpp @@ -77,7 +77,7 @@ */ PluginHost::PluginHost(PluginManager *manager, const QString &pluginFile) : manager_(manager), plugin_(nullptr), file_(pluginFile), priority_(PsiPlugin::PriorityNormal), loader_(nullptr), - iconset_(nullptr), valid_(false), connected_(false), enabled_(false), hasInfo_(false), infoString_(QString()) + valid_(false), connected_(false), enabled_(false), hasInfo_(false), infoString_(QString()) { updateMetadata(); } @@ -330,8 +330,7 @@ bool PluginHost::unload() return false; } else if (loader_->unload()) { // delete plugin_; // loader will delete it automatically - delete iconset_; - iconset_ = nullptr; + iconset_.clear(); connected_ = false; delete loader_; plugin_ = nullptr; @@ -978,11 +977,8 @@ void PluginHost::addIcon(const QString &name, const QByteArray &ba) PsiIcon icon; icon.setImpix(pm); icon.setName(name); - if (!iconset_) { - iconset_ = new Iconset(); - } - iconset_->setIcon(name, icon); - iconset_->addToFactory(); + iconset_.setIcon(name, icon); + iconset_.addToFactory(); } QTextEdit *PluginHost::getEditBox() diff --git a/src/pluginhost.h b/src/pluginhost.h index a46a6343d..dcd2b35dc 100644 --- a/src/pluginhost.h +++ b/src/pluginhost.h @@ -290,9 +290,9 @@ class PluginHost : public QObject, int priority_ = 0; QByteArray rawIcon_; QIcon icon_; - QPluginLoader *loader_ = nullptr; - QPointer enableHandler = nullptr; - Iconset *iconset_ = nullptr; + QPluginLoader *loader_ = nullptr; + QPointer enableHandler = nullptr; + Iconset iconset_; bool hasToolBarButton_ = false; bool hasGCToolBarButton_ = false; diff --git a/src/psicon.cpp b/src/psicon.cpp index 010b876c7..84ba6c88c 100644 --- a/src/psicon.cpp +++ b/src/psicon.cpp @@ -273,8 +273,8 @@ public slots: void updateIconSelect() { Iconset iss; - for (Iconset *iconset : std::as_const(PsiIconset::instance()->emoticons)) { - iss += *iconset; + for (const Iconset &iconset : std::as_const(PsiIconset::instance()->emoticons)) { + iss += iconset; } iconSelect->setIconset(iss); diff --git a/src/psiiconset.cpp b/src/psiiconset.cpp index b938f3717..7da2b6564 100644 --- a/src/psiiconset.cpp +++ b/src/psiiconset.cpp @@ -168,37 +168,24 @@ class PsiIconset::Private { } } - void loadIconset(Iconset *to, Iconset *from) + void loadIconset(Iconset &to, const Iconset &from) { - if (!to) { - qWarning("PsiIconset::loadIconset(): 'to' iconset is NULL!"); - if (from) - qWarning("from->name() = '%s'", qPrintable(from->name())); - return; - } - if (!from) { - qWarning("PsiIconset::loadIconset(): 'from' iconset is NULL!"); - if (to) - qWarning("to->name() = '%s'", qPrintable(to->name())); - return; - } - - QListIterator it = from->iterator(); + QListIterator it = from.iterator(); while (it.hasNext()) { PsiIcon *icon = it.next(); if (icon && !icon->name().isEmpty()) { - PsiIcon *toIcon = const_cast(to->icon(icon->name())); + PsiIcon *toIcon = const_cast(to.icon(icon->name())); if (toIcon) { bool b = toIcon->blockSignals(true); *toIcon = *icon; toIcon->blockSignals(b); } else - to->setIcon(icon->name(), *icon); + to.setIcon(icon->name(), *icon); } } - to->setInformation(*from); + to.setInformation(from); } PsiIcon *jid2icon(const Jid &jid, const QString &iconName) @@ -211,9 +198,9 @@ class PsiIconset::Private { for (const StatusIconsets::IconsetItem &item : std::as_const(status_icons.list)) { if (item.regexp.pattern().isEmpty() ? jid.node().isEmpty() : (item.regexp.match(jid.domain()).hasMatch())) { - const Iconset *is = psi->roster.value(item.iconset); - if (is) { - PsiIcon *i = const_cast(is->icon(iconName)); + auto isIt = psi->roster.find(item.iconset); + if (isIt != psi->roster.end()) { + PsiIcon *i = const_cast(isIt->icon(iconName)); if (i) { icon = i; break; @@ -226,9 +213,9 @@ class PsiIconset::Private { // third level -- custom icons for (const StatusIconsets::IconsetItem &item : std::as_const(status_icons.customList)) { if (item.regexp.match(jid.bare()).hasMatch()) { - const Iconset *is = psi->roster.value(item.iconset); - if (is) { - PsiIcon *i = const_cast(is->icon(iconName)); + auto isIt = psi->roster.find(item.iconset); + if (isIt != psi->roster.end()) { + PsiIcon *i = const_cast(isIt->icon(iconName)); if (i) { icon = i; break; @@ -249,7 +236,7 @@ class PsiIconset::Private { Iconset is; is.load(iconsetPath("system/" + PsiOptions::instance()->getOption("options.iconsets.system").toString())); - loadIconset(&def, &is); + loadIconset(def, is); } stripFirstAnimFrame(def); @@ -257,19 +244,19 @@ class PsiIconset::Private { return def; } - Iconset *defaultRosterIconset(bool *ok) + Iconset defaultRosterIconset(bool *ok) { - Iconset *def = new Iconset; - *ok = def->load(":/iconsets/roster/default"); + Iconset def; + *ok = def.load(":/iconsets/roster/default"); if (PsiOptions::instance()->getOption("options.iconsets.status").toString() != "default") { Iconset is; is.load(iconsetPath("roster/" + PsiOptions::instance()->getOption("options.iconsets.status").toString())); - loadIconset(def, &is); + loadIconset(def, is); } - stripFirstAnimFrame(*def); + stripFirstAnimFrame(def); return def; } @@ -283,7 +270,7 @@ class PsiIconset::Private { Iconset is; is.load(iconsetPath("moods/" + PsiOptions::instance()->getOption("options.iconsets.moods").toString())); - loadIconset(&def, &is); + loadIconset(def, is); } stripFirstAnimFrame(def); @@ -301,7 +288,7 @@ class PsiIconset::Private { is.load(iconsetPath("activities/" + PsiOptions::instance()->getOption("options.iconsets.activities").toString())); - loadIconset(&def, &is); + loadIconset(def, is); } stripFirstAnimFrame(def); @@ -318,7 +305,7 @@ class PsiIconset::Private { Iconset is; is.load(iconsetPath("clients/" + PsiOptions::instance()->getOption("options.iconsets.clients").toString())); - loadIconset(&def, &is); + loadIconset(def, is); } stripFirstAnimFrame(def); @@ -336,7 +323,7 @@ class PsiIconset::Private { is.load(iconsetPath("affiliations/" + PsiOptions::instance()->getOption("options.iconsets.affiliations").toString())); - loadIconset(&def, &is); + loadIconset(def, is); } stripFirstAnimFrame(def); @@ -344,30 +331,28 @@ class PsiIconset::Private { return def; } - QList emoticons() + QList emoticons() { - QList emo; + QList emo; const auto names = PsiOptions::instance()->getOption("options.iconsets.emoticons").toStringList(); for (const QString &name : names) { - auto isPath = iconsetPath("emoticons/" + name, Iconset::Format::Psi, true); - Iconset *is = nullptr; + auto isPath = iconsetPath("emoticons/" + name, Iconset::Format::Psi, true); + if (!isPath.isEmpty()) { - is = new Iconset; - if (is->load(iconsetPath("emoticons/" + name))) { - is->addToFactory(); + Iconset is; + if (is.load(iconsetPath("emoticons/" + name))) { + is.addToFactory(); emo.append(is); continue; } - delete is; } - is = new Iconset; - if (is->load(iconsetPath(name, Iconset::Format::KdeEmoticons), Iconset::Format::KdeEmoticons)) { - is->addToFactory(); + Iconset is; + if (is.load(iconsetPath(name, Iconset::Format::KdeEmoticons), Iconset::Format::KdeEmoticons)) { + is.addToFactory(); emo.append(is); - } else - delete is; + } } return emo; @@ -403,7 +388,7 @@ bool PsiIconset::loadSystem() emit systemIconsSizeChanged(sys.iconSize()); } - d->loadIconset(&d->system, &sys); + d->loadIconset(d->system, sys); // d->system = d->systemIconset(); d->system.addToFactory(); @@ -417,13 +402,12 @@ bool PsiIconset::loadSystem() bool PsiIconset::loadRoster() { // load roster - qDeleteAll(roster); roster.clear(); // default roster iconset - bool ok; - Iconset *def = d->defaultRosterIconset(&ok); - def->addToFactory(); + bool ok; + Iconset def = d->defaultRosterIconset(&ok); + def.addToFactory(); roster.insert(PsiOptions::instance()->getOption("options.iconsets.status").toString(), def); d->cur_status = PsiOptions::instance()->getOption("options.iconsets.status").toString(); @@ -458,13 +442,11 @@ bool PsiIconset::loadRoster() continue; } - Iconset *is = new Iconset; - if (is->load(d->iconsetPath("roster/" + it2))) { - is->addToFactory(); - d->stripFirstAnimFrame(*is); + Iconset is; + if (is.load(d->iconsetPath("roster/" + it2))) { + is.addToFactory(); + d->stripFirstAnimFrame(is); roster.insert(it2, is); - } else { - delete is; } } @@ -475,7 +457,6 @@ void PsiIconset::loadEmoticons() { QStringList cur_emoticons = PsiOptions::instance()->getOption("options.iconsets.emoticons").toStringList(); if (d->cur_emoticons != cur_emoticons) { - qDeleteAll(emoticons); emoticons.clear(); emoticons = d->emoticons(); @@ -491,7 +472,7 @@ bool PsiIconset::loadMoods() QString cur_moods = PsiOptions::instance()->getOption("options.iconsets.moods").toString(); if (d->cur_moods != cur_moods) { Iconset moods = d->moodsIconset(&ok); - d->loadIconset(&d->moods, &moods); + d->loadIconset(d->moods, moods); d->moods.addToFactory(); d->cur_moods = cur_moods; @@ -506,7 +487,7 @@ bool PsiIconset::loadActivity() QString cur_activity = PsiOptions::instance()->getOption("options.iconsets.activities").toString(); if (d->cur_activity != cur_activity) { Iconset activities = d->activityIconset(&ok); - d->loadIconset(&d->activities, &activities); + d->loadIconset(d->activities, activities); d->activities.addToFactory(); d->cur_activity = cur_activity; @@ -521,7 +502,7 @@ bool PsiIconset::loadClients() QString cur_clients = PsiOptions::instance()->getOption("options.iconsets.clients").toString(); if (d->cur_clients != cur_clients) { Iconset clients = d->clientsIconset(&ok); - d->loadIconset(&d->clients, &clients); + d->loadIconset(d->clients, clients); d->clients.addToFactory(); QSet iconNames; @@ -610,7 +591,7 @@ bool PsiIconset::loadAffiliations() QString cur_affiliations = PsiOptions::instance()->getOption("options.iconsets.affiliations").toString(); if (d->cur_affiliations != cur_affiliations) { Iconset affiliations = d->affiliationsIconset(&ok); - d->loadIconset(&d->affiliations, &affiliations); + d->loadIconset(d->affiliations, affiliations); d->affiliations.addToFactory(); d->cur_affiliations = cur_affiliations; @@ -735,18 +716,17 @@ void PsiIconset::reloadRoster() QString cur_status = PsiOptions::instance()->getOption("options.iconsets.status").toString(); // default roster iconset if (d->cur_status != cur_status) { - Iconset *newDef = d->defaultRosterIconset(&ok); - Iconset *oldDef = roster[d->cur_status]; + Iconset newDef = d->defaultRosterIconset(&ok); + Iconset oldDef = roster[d->cur_status]; - if (oldDef->iconSize() != newDef->iconSize()) - emit rosterIconsSizeChanged(newDef->iconSize()); + if (oldDef.iconSize() != newDef.iconSize()) + emit rosterIconsSizeChanged(newDef.iconSize()); d->loadIconset(oldDef, newDef); roster.remove(d->cur_status); roster.insert(cur_status, oldDef); - delete newDef; d->cur_status = cur_status; } @@ -790,26 +770,25 @@ void PsiIconset::reloadRoster() if (*it2 == PsiOptions::instance()->getOption("options.iconsets.status").toString()) continue; - Iconset *is = new Iconset; - if (is->load(d->iconsetPath("roster/" + *it2))) { - d->stripFirstAnimFrame(*is); - Iconset *oldis = roster[*it2]; + Iconset is; + if (is.load(d->iconsetPath("roster/" + *it2))) { + d->stripFirstAnimFrame(is); + auto oldisIt = roster.find(*it2); - if (oldis) - d->loadIconset(oldis, is); + if (oldisIt != roster.end()) + d->loadIconset(oldisIt.value(), is); else { - is->addToFactory(); + is.addToFactory(); roster.insert(*it2, is); } - } else - delete is; + } } bool clear = false; while (!clear) { clear = true; - QMutableHashIterator it3(roster); + QMutableHashIterator it3(roster); while (it3.hasNext()) { it3.next(); QString name = it3.key(); @@ -818,7 +797,6 @@ void PsiIconset::reloadRoster() if (!rosterIconsets.contains(name)) { // remove redundant iconset - delete roster[name]; it3.remove(); clear = false; break; @@ -915,18 +893,18 @@ PsiIcon *PsiIconset::statusPtr(const XMPP::Status &s) { return statusPtr(makeSTA PsiIcon PsiIconset::status(const XMPP::Status &s) { return status(makeSTATUS(s)); } -PsiIcon *PsiIconset::transportStatusPtr(QString name, int s) +const PsiIcon *PsiIconset::transportStatusPtr(QString name, int s) { - PsiIcon *icon = nullptr; + const PsiIcon *icon = nullptr; QVariantList serviceicons = PsiOptions::instance()->mapKeyList("options.iconsets.service-status"); if (serviceicons.contains(name)) { - const Iconset *is = roster.value( + auto it = roster.find( PsiOptions::instance() ->getOption(*PsiOptions::instance()->mapLookup("options.iconsets.service-status", name) + ".iconset") .toString()); - if (is) { - icon = const_cast(is->icon(status2name(s))); + if (it != roster.end()) { + icon = it->icon(status2name(s)); } } @@ -936,25 +914,25 @@ PsiIcon *PsiIconset::transportStatusPtr(QString name, int s) return icon; } -PsiIcon *PsiIconset::transportStatusPtr(QString name, const XMPP::Status &s) +const PsiIcon *PsiIconset::transportStatusPtr(QString name, const XMPP::Status &s) { return transportStatusPtr(name, makeSTATUS(s)); } PsiIcon PsiIconset::transportStatus(QString name, int s) { - PsiIcon *icon = transportStatusPtr(name, s); + auto icon = transportStatusPtr(name, s); if (icon) return *icon; - return PsiIcon(); + return {}; } PsiIcon PsiIconset::transportStatus(QString name, const XMPP::Status &s) { - PsiIcon *icon = transportStatusPtr(name, s); + auto icon = transportStatusPtr(name, s); if (icon) return *icon; - return PsiIcon(); + return {}; } PsiIcon *PsiIconset::statusPtr(const XMPP::Jid &jid, int s) { return d->jid2icon(jid, status2name(s)); } @@ -1013,19 +991,13 @@ PsiIcon PsiIconset::status(UserListItem *u) const Iconset &PsiIconset::system() const { return d->system; } -void PsiIconset::stripFirstAnimFrame(Iconset *is) -{ - if (is) - d->stripFirstAnimFrame(*is); -} +void PsiIconset::stripFirstAnimFrame(Iconset &is) { d->stripFirstAnimFrame(is); } -void PsiIconset::removeAnimation(Iconset *is) +void PsiIconset::removeAnimation(Iconset &is) { - if (is) { - QListIterator it = is->iterator(); - while (it.hasNext()) { - it.next()->removeAnim(false); - } + QListIterator it = is.iterator(); + while (it.hasNext()) { + it.next()->removeAnim(false); } } diff --git a/src/psiiconset.h b/src/psiiconset.h index f5a7fad5a..a3a65a5ef 100644 --- a/src/psiiconset.h +++ b/src/psiiconset.h @@ -41,15 +41,15 @@ class PsiIconset : public QObject { void reloadRoster(); bool loadAll(); - QHash roster; - QList emoticons; - Iconset moods; - Iconset activities; - Iconset clients; - Iconset affiliations; - const Iconset &system() const; - void stripFirstAnimFrame(Iconset *); - static void removeAnimation(Iconset *); + QHash roster; + QList emoticons; + Iconset moods; + Iconset activities; + Iconset clients; + Iconset affiliations; + const Iconset &system() const; + void stripFirstAnimFrame(Iconset &); + static void removeAnimation(Iconset &); PsiIcon *event2icon(const PsiEvent::Ptr &e); @@ -69,8 +69,8 @@ class PsiIconset : public QObject { PsiIcon status(const XMPP::Jid &, const XMPP::Status &); // functions to get status icon by transport name - PsiIcon *transportStatusPtr(QString name, int); - PsiIcon *transportStatusPtr(QString name, const XMPP::Status &); + const PsiIcon *transportStatusPtr(QString name, int); + const PsiIcon *transportStatusPtr(QString name, const XMPP::Status &); PsiIcon transportStatus(QString name, int); PsiIcon transportStatus(QString name, const XMPP::Status &); diff --git a/src/textutil.cpp b/src/textutil.cpp index d0f278008..e2535a2d6 100644 --- a/src/textutil.cpp +++ b/src/textutil.cpp @@ -294,8 +294,10 @@ static void emojiconifyPlainText(RTParse &p, const QString &in) p.putRich(QLatin1String(R"html()html") + code + QLatin1String("")); #else // FIXME custom style here is a hack. This supposed to be handled via style resource in PsiTextView - p.putRich(QString(R"()") - .arg(code)); + p.putRich( + QString( + R"()") + .arg(code)); #endif }; int position; @@ -509,8 +511,8 @@ QString TextUtil::emoticonify(const QString &in) int foundPos = -1, foundLen = -1; - for (const Iconset *iconset : std::as_const(PsiIconset::instance()->emoticons)) { - QListIterator it = iconset->iterator(); + for (const Iconset &iconset : std::as_const(PsiIconset::instance()->emoticons)) { + QListIterator it = iconset.iterator(); while (it.hasNext()) { PsiIcon *icon = it.next(); if (icon->regExp().pattern().isEmpty()) diff --git a/src/tools/iconset/iconset.cpp b/src/tools/iconset/iconset.cpp index bd6bc5121..26908a437 100644 --- a/src/tools/iconset/iconset.cpp +++ b/src/tools/iconset/iconset.cpp @@ -825,16 +825,11 @@ void PsiIcon::stripFirstAnimFrame() //! \if _hide_doc_ class IconsetFactoryPrivate : public QObject { private: - IconsetFactoryPrivate() : QObject(QCoreApplication::instance()), iconsets_(nullptr), emptyPixmap_(nullptr) { } + IconsetFactoryPrivate() : QObject(QCoreApplication::instance()), emptyPixmap_(nullptr) { } ~IconsetFactoryPrivate() { - if (iconsets_) { - while (!iconsets_->empty()) - delete iconsets_->takeFirst(); - delete iconsets_; - iconsets_ = nullptr; - } + iconsets_.clear(); if (emptyPixmap_) { delete emptyPixmap_; @@ -843,7 +838,7 @@ class IconsetFactoryPrivate : public QObject { } static IconsetFactoryPrivate *instance_; - QList *iconsets_; + QList iconsets_; mutable QPixmap *emptyPixmap_; public: @@ -859,8 +854,8 @@ class IconsetFactoryPrivate : public QObject { { QStringList list; - for (const Iconset *iconset : std::as_const(*iconsets_)) { - QListIterator it = iconset->iterator(); + for (const Iconset &iconset : iconsets_) { + QListIterator it = iconset.iterator(); while (it.hasNext()) { list << it.next()->name(); } @@ -869,8 +864,8 @@ class IconsetFactoryPrivate : public QObject { return list; } - void registerIconset(const Iconset *); - void unregisterIconset(const Iconset *); + void registerIconset(const Iconset &); + void unregisterIconset(const Iconset &); public: static IconsetFactoryPrivate *instance() @@ -893,36 +888,20 @@ class IconsetFactoryPrivate : public QObject { IconsetFactoryPrivate *IconsetFactoryPrivate::instance_ = nullptr; -void IconsetFactoryPrivate::registerIconset(const Iconset *i) +void IconsetFactoryPrivate::registerIconset(const Iconset &i) { - if (!iconsets_) { - iconsets_ = new QList; - } - - if (!iconsets_->contains(const_cast(i))) { - iconsets_->append(const_cast(i)); + if (!iconsets_.contains(i)) { + iconsets_.append(i); } } -void IconsetFactoryPrivate::unregisterIconset(const Iconset *i) -{ - if (iconsets_ && iconsets_->contains(const_cast(i))) { - iconsets_->removeAll(const_cast(i)); - } -} +void IconsetFactoryPrivate::unregisterIconset(const Iconset &i) { iconsets_.removeAll(i); } const PsiIcon *IconsetFactoryPrivate::icon(const QString &name) const { - if (!iconsets_) { - return nullptr; - } - const PsiIcon *out = nullptr; - for (const Iconset *const iconset : std::as_const(*iconsets_)) { - if (iconset) { - out = iconset->icon(name); - } - + for (const Iconset &iconset : iconsets_) { + out = iconset.icon(name); if (out) { break; } @@ -1531,7 +1510,7 @@ Iconset::Iconset(const Iconset &from) /** * Destroys Iconset, and frees all allocated Icons. */ -Iconset::~Iconset() { IconsetFactoryPrivate::instance()->unregisterIconset(this); } +Iconset::~Iconset() = default; /** * Copies all Icons as well as additional information from Iconset \a from. @@ -1543,13 +1522,13 @@ Iconset &Iconset::operator=(const Iconset &from) return *this; } -Iconset Iconset::copy() const -{ - Iconset is; - is.d = new Private(*this->d.data()); +// Iconset Iconset::copy() const +// { +// Iconset is; +// is.d = new Private(*this->d.data()); - return is; -} +// return is; +// } void Iconset::detach() { d.detach(); } @@ -1584,6 +1563,8 @@ void Iconset::clear() */ int Iconset::count() const { return d->list.count(); } +bool Iconset::isEmpty() const { return d->list.isEmpty(); } + /** * Loads Icons and additional information from directory \a dir. Directory can usual directory, * or a .zip/.jisp archive. There must exist file named \c icondef.xml in that directory. @@ -1763,12 +1744,12 @@ void Iconset::setInfo(const QHash &i) { d->info = i; } /** * Adds Iconset to IconsetFactory. */ -void Iconset::addToFactory() const { IconsetFactoryPrivate::instance()->registerIconset(this); } +void Iconset::addToFactory() const { IconsetFactoryPrivate::instance()->registerIconset(*this); } /** * Removes Iconset from IconsetFactory. */ -void Iconset::removeFromFactory() const { IconsetFactoryPrivate::instance()->unregisterIconset(this); } +void Iconset::removeFromFactory() const { IconsetFactoryPrivate::instance()->unregisterIconset(*this); } bool Iconset::isSourceAllowed(const QFileInfo &fi) { diff --git a/src/tools/iconset/iconset.h b/src/tools/iconset/iconset.h index 5461189d7..4435e07dd 100644 --- a/src/tools/iconset/iconset.h +++ b/src/tools/iconset/iconset.h @@ -189,11 +189,13 @@ class Iconset { Iconset(const Iconset &); ~Iconset(); - Iconset &operator=(const Iconset &); - Iconset &operator+=(const Iconset &); + Iconset &operator=(const Iconset &); + Iconset &operator+=(const Iconset &); + inline bool operator==(const Iconset &other) const { return d == other.d; } void clear(); int count() const; + bool isEmpty() const; bool load(const QString &dir, Format format = Format::Psi); @@ -228,12 +230,12 @@ class Iconset { static bool isSourceAllowed(const QFileInfo &fi); static void setSoundPrefs(QString unpackPath, QObject *receiver, const char *slot); - Iconset copy() const; - void detach(); + // Iconset copy() const; + void detach(); private: class Private; - QSharedDataPointer d; + QExplicitlySharedDataPointer d; }; class IconsetFactory { diff --git a/src/widgets/iconsetselect.h b/src/widgets/iconsetselect.h index 60d7f3e2f..0e923cf6c 100644 --- a/src/widgets/iconsetselect.h +++ b/src/widgets/iconsetselect.h @@ -33,7 +33,7 @@ class IconsetSelect : public QListWidget { void insert(const Iconset &); // iconsets must be inserted in following order: most prioritent first - const Iconset *iconset() const; + Iconset iconset() const; QListWidgetItem *lastItem() const; #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) diff --git a/src/widgets/iconwidget.cpp b/src/widgets/iconwidget.cpp index a2e5e5608..f325f54f3 100644 --- a/src/widgets/iconwidget.cpp +++ b/src/widgets/iconwidget.cpp @@ -291,22 +291,22 @@ class IconsetSelectItem : public RealIconWidgetItem { #endif } - const Iconset *iconset() const + Iconset iconset() const override { #ifndef WIDGET_PLUGIN - return &iss; + return iss; #else return 0; #endif } - int height() const + int height() const override { int hh = listWidget()->fontMetrics().lineSpacing() + h; return qMax(hh, 16); } - int width() const + int width() const override { #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) int ww = qMax(listWidget()->fontMetrics().horizontalAdvance(text()) + 6 + 15, w + 10); @@ -316,7 +316,7 @@ class IconsetSelectItem : public RealIconWidgetItem { return qMax(ww, 16); } - void paint(QPainter *painter) const + void paint(QPainter *painter) const override { #ifndef WIDGET_PLUGIN QFontMetrics fm = painter->fontMetrics(); @@ -332,7 +332,7 @@ class IconsetSelectItem : public RealIconWidgetItem { Q_UNUSED(painter); #endif } - QPoint textPosition(QPainter *painter) const + QPoint textPosition(QPainter *painter) const override { QFontMetrics fm = painter->fontMetrics(); return QPoint(3, fm.ascent() + (fm.leading() + 1) / 2 + 1); @@ -383,7 +383,7 @@ void IconsetSelect::moveItemDown() setCurrentItem(i); } -const Iconset *IconsetSelect::iconset() const +Iconset IconsetSelect::iconset() const { IconsetSelectItem *i = static_cast(currentItem()); if (!i) { @@ -392,7 +392,7 @@ const Iconset *IconsetSelect::iconset() const } if (i) return i->iconset(); - return nullptr; + return {}; } QListWidgetItem *IconsetSelect::lastItem() const { return item(count() - 1); } diff --git a/src/widgets/iconwidget.h b/src/widgets/iconwidget.h index 2e1928b6a..82b943915 100644 --- a/src/widgets/iconwidget.h +++ b/src/widgets/iconwidget.h @@ -20,17 +20,17 @@ #ifndef ICONWIDGET_H #define ICONWIDGET_H +#include "iconset.h" + #include #include -class Iconset; - class IconWidgetItem : public QObject, public QListWidgetItem { Q_OBJECT public: IconWidgetItem(QListWidget *parent = nullptr) : QListWidgetItem(parent) { } - virtual const Iconset *iconset() const { return nullptr; } + virtual Iconset iconset() const { return {}; }; }; #endif // ICONWIDGET_H diff --git a/version b/version index 13fe95dc5..78340617f 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.5.2055 (2024-10-06, fb5ac2ca) +1.5.2056 (2024-10-07, c86b1387)