Commit 653900d2 authored by Laurent Montel's avatar Laurent Montel 😁

USe nullptr. Clean up. Optimization

parent 49f84c21
......@@ -212,6 +212,7 @@ void Module::loadHardware()
}
// Create a formatted list of grouped processors
QStringList names;
names.reserve(processorMap.count());
for (auto it = processorMap.constBegin(); it != processorMap.constEnd(); ++it) {
const int count = it.value();
QString name = it.key();
......
......@@ -34,7 +34,7 @@ static void setVar(QString *var, const QString &value)
if (error != KShell::NoError) { // Failed to parse.
return;
}
*var = args.join(QChar(' '));
*var = args.join(QLatin1Char(' '));
}
static void setVar(QStringList *var, const QString &value)
......@@ -91,12 +91,12 @@ OSRelease::OSRelease()
while (!file.atEnd()) {
line = file.readLine();
if (line.startsWith(QChar('#'))) {
if (line.startsWith(QLatin1Char('#'))) {
// Comment line
continue;
}
comps = line.split(QChar('='));
comps = line.split(QLatin1Char('='));
if (comps.size() != 2) {
// Invalid line.
......
......@@ -153,7 +153,7 @@ void DeviceListing::deviceAddedSlot(const QString &udi)
QTreeWidgetItem *parent = getTreeWidgetItemFromUdi(this, dev.parentUdi());
// Incase of bad index
if (deviceMap[deviceType] == NULL) {
if (deviceMap[deviceType] == nullptr) {
QTreeWidgetItem *topItem = topLevelItem(0);
if (topItem == 0) {
delete solhelp;
......@@ -179,7 +179,7 @@ void DeviceListing::deviceAddedSlot(const QString &udi)
new SolStorageDevice(deviceMap[deviceType], dev, SolStorageDevice::NOCHILDREN);
break;
case Solid::DeviceInterface::StorageVolume:
if (parent == NULL) {
if (parent == nullptr) {
break;
}
new SolVolumeDevice(parent, dev);
......
......@@ -117,17 +117,12 @@ QLabel *InfoPanel::setDevicesIcon(const QIcon &deviceIcon)
void InfoPanel::setTopInfo(const QIcon &deviceIcon, Solid::Device *device)
{
QList<QString> labels;
setTopWidgetLayout();
QVListLayout *tLayout = static_cast<QVListLayout *>(top->layout());
tLayout->addWidget(setDevicesIcon(deviceIcon), 0, Qt::AlignHCenter);
labels << i18n("Product: ")
<< device->product()
<< i18n("Vendor: ")
<< friendlyString(device->vendor());
const QStringList labels {i18n("Product: "), device->product(), i18n("Vendor: "), friendlyString(device->vendor())};
status->updateStatus(device->udi());
tLayout->applyQListToLayout(labels);
......
......@@ -37,7 +37,7 @@ void QVListLayout::applyQListToLayout(const QStringList &list)
QFont labelFont;
labelFont.setBold(true);
foreach (const QString &item, list) {
for (const QString &item : list) {
if (!item.isEmpty()) {
bLabel = new QLabel(item);
bLabel->setWordWrap(true);
......
......@@ -25,7 +25,7 @@
SolDevice::SolDevice(const Solid::DeviceInterface::Type &type)
: QTreeWidgetItem()
, deviceSet(0)
, deviceSet(false)
{
deviceTypeHolder = type;
setText(0, Solid::DeviceInterface::typeToString(type));
......@@ -33,14 +33,14 @@ SolDevice::SolDevice(const Solid::DeviceInterface::Type &type)
SolDevice::SolDevice(QTreeWidgetItem *parent)
: QTreeWidgetItem(parent)
, deviceSet(0)
, deviceSet(false)
{
deviceTypeHolder = Solid::DeviceInterface::Unknown;
}
SolDevice::SolDevice(const Solid::DeviceInterface::Type &type, const QString &typeName)
: QTreeWidgetItem()
, deviceSet(0)
, deviceSet(false)
{
deviceTypeHolder = type;
setText(0, typeName);
......
......@@ -64,7 +64,7 @@ QVListLayout *SolProcessorDevice::infoPanelLayout()
const Solid::Processor *prodev = interface<const Solid::Processor>();
if (!prodev) {
return NULL;
return nullptr;
}
deviceInfoLayout = new QVListLayout();
......@@ -181,7 +181,7 @@ QVListLayout *SolStorageDevice::infoPanelLayout()
const Solid::StorageDrive *stodev = interface<const Solid::StorageDrive>();
if (!stodev) {
return NULL;
return nullptr;
}
deviceInfoLayout = new QVListLayout();
......@@ -244,13 +244,13 @@ void SolVolumeDevice::setDefaultListing(const Solid::DeviceInterface::Type &type
QVListLayout *SolVolumeDevice::infoPanelLayout()
{
QStringList labels;
KCapacityBar *usageBar = NULL;
KCapacityBar *usageBar = nullptr;
const Solid::StorageVolume *voldev = interface<const Solid::StorageVolume>();
const Solid::StorageAccess *accdev = interface<const Solid::StorageAccess>();
if (!voldev) {
return NULL;
return nullptr;
}
deviceInfoLayout = new QVListLayout();
......@@ -349,7 +349,7 @@ QVListLayout *SolMediaPlayerDevice::infoPanelLayout()
const Solid::PortableMediaPlayer *mpdev = interface<const Solid::PortableMediaPlayer>();
if (!mpdev) {
return NULL;
return nullptr;
}
deviceInfoLayout = new QVListLayout();
......@@ -391,7 +391,7 @@ QVListLayout *SolCameraDevice::infoPanelLayout()
const Solid::Camera *camdev = interface<const Solid::Camera>();
if (!camdev) {
return NULL;
return nullptr;
}
deviceInfoLayout = new QVListLayout();
......@@ -433,7 +433,7 @@ QVListLayout *SolBatteryDevice::infoPanelLayout()
const Solid::Battery *batdev = interface<const Solid::Battery>();
if (!batdev) {
return NULL;
return nullptr;
}
deviceInfoLayout = new QVListLayout();
......
......@@ -32,7 +32,7 @@ Solid::DeviceInterface::Type SolidHelper::deviceType(const Solid::Device *dev)
Solid::DeviceInterface::StorageVolume
};
for (unsigned int i = 0; i < (sizeof(needHardware)/sizeof(Solid::DeviceInterface::Type)); i++) {
for (unsigned int i = 0, total = (sizeof(needHardware)/sizeof(Solid::DeviceInterface::Type)); i < total; ++i) {
if (dev->isDeviceInterface(needHardware[i]) == true) {
return needHardware[i];
}
......
......@@ -145,7 +145,7 @@ int StatisticsProvider::largestValue() const
}
int max = 0; // TODO std::max or something?
for (auto it = m_values.constBegin(); it != m_values.constEnd(); ++it) {
for (auto it = m_values.constBegin(), end = m_values.constEnd(); it != end; ++it) {
if ((*it).value > max) {
max = (*it).value;
}
......
......@@ -48,8 +48,7 @@ KInfoListWidget::KInfoListWidget(const QString &_title, QWidget *parent, bool _g
//setButtons(KCModule::Help);
getlistbox = _getlistbox;
QHBoxLayout *layout = new QHBoxLayout(this);
//PORT QT5 layout->setSpacing(KDialog::spacingHint());
layout->setMargin(0);
layout->setMargin(0);
widgetStack = new QStackedWidget(this);
layout->addWidget(widgetStack);
......
......@@ -28,8 +28,8 @@ Chart::Chart(QWidget* parent) :
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
memoryInfos = NULL;
freeMemoryLabel = NULL;
memoryInfos = nullptr;
mFreeMemoryLabel = nullptr;
}
......@@ -38,7 +38,7 @@ void Chart::setMemoryInfos(t_memsize* memoryInfos) {
}
void Chart::setFreeMemoryLabel(QLabel* freeMemoryLabel) {
this->freeMemoryLabel = freeMemoryLabel;
this->mFreeMemoryLabel = freeMemoryLabel;
}
......@@ -54,7 +54,7 @@ bool Chart::drawChart(t_memsize total, const QList<t_memsize>& used, const QList
paint.setPen(pen);
paint.drawRect(rect());
setAccessibleDescription(i18n("Not available."));
freeMemoryLabel->setText(i18n("Not available."));
mFreeMemoryLabel->setText(i18n("Not available."));
return false;
}
......@@ -103,7 +103,7 @@ bool Chart::drawChart(t_memsize total, const QList<t_memsize>& used, const QList
QRect r = rect();
qDrawShadePanel(&paint, r.x(), r.y(), r.width(), r.height(), palette(), true, 1);
freeMemoryLabel->setText(i18n("%1 free", formattedUnit(last_used)));
mFreeMemoryLabel->setText(i18n("%1 free", formattedUnit(last_used)));
setAccessibleDescription(accessibleDescription.join('\n'));
return true;
......@@ -129,13 +129,13 @@ ChartWidget::ChartWidget(const QString& title, const QString& hint, Chart* chart
chart->setToolTip(hint);
mainLayout->addWidget(chart);
freeMemoryLabel = new QLabel(QLatin1String(""), this);
freeMemoryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
freeMemoryLabel->setAlignment(Qt::AlignHCenter);
freeMemoryLabel->setToolTip(hint);
mainLayout->addWidget(freeMemoryLabel);
mFreeMemoryLabel = new QLabel(QLatin1String(""), this);
mFreeMemoryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
mFreeMemoryLabel->setAlignment(Qt::AlignHCenter);
mFreeMemoryLabel->setToolTip(hint);
mainLayout->addWidget(mFreeMemoryLabel);
chart->setFreeMemoryLabel(freeMemoryLabel);
chart->setFreeMemoryLabel(mFreeMemoryLabel);
}
void ChartWidget::setMemoryInfos(t_memsize* memoryInfos) {
......
......@@ -38,7 +38,7 @@ public:
explicit Chart(QWidget* parent = nullptr);
void setMemoryInfos(t_memsize* memoryInfos);
void setFreeMemoryLabel(QLabel* freeMemoryLabel);
void setFreeMemoryLabel(QLabel* freeMemoryLabel);
static QString formattedUnit(t_memsize value);
......@@ -48,7 +48,7 @@ protected:
t_memsize* memoryInfos = nullptr;
QLabel* freeMemoryLabel = nullptr;
QLabel* mFreeMemoryLabel = nullptr;
};
......@@ -69,7 +69,7 @@ private:
Chart* chart = nullptr;
QLabel* freeMemoryLabel = nullptr;
QLabel* mFreeMemoryLabel = nullptr;
};
......
......@@ -87,7 +87,6 @@ KCMNic::KCMNic(QWidget *parent, const QVariantList &) :
KCModule(parent) {
QVBoxLayout *box=new QVBoxLayout(this);
box->setMargin(0);
//PORT QT5 box->setSpacing(KDialog::spacingHint());
m_list=new QTreeWidget(this);
m_list->setRootIsDecorated(false);
box->addWidget(m_list);
......@@ -258,7 +257,7 @@ QList<MyNIC*> findNICs() {
getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len, buf, 127, 0, 0, NI_NUMERICHOST);
tmp->addr = buf;
if (ifa->ifa_netmask != NULL) {
if (ifa->ifa_netmask != nullptr) {
bzero(buf, 128);
getnameinfo(ifa->ifa_netmask, ifa->ifa_netmask->sa_len, buf, 127, 0, 0, NI_NUMERICHOST);
tmp->netmask = buf;
......
......@@ -102,9 +102,9 @@ void KCMOpenGL::treeWidgetChanged() {
QTreeWidgetItem *newItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding, const QString &textCol1, const QString &textCol2 = QString()) {
QTreeWidgetItem *newItem;
if ((parent == NULL) && (preceding == NULL)) {
if ((parent == nullptr) && (preceding == nullptr)) {
newItem = new QTreeWidgetItem();
} else if (preceding == NULL) {
} else if (preceding == nullptr) {
newItem = new QTreeWidgetItem(parent);
} else {
newItem = new QTreeWidgetItem(parent, preceding);
......@@ -280,7 +280,7 @@ print_extension_list(const char *ext, QTreeWidgetItem *l1)
if (!ext || !ext[0])
return;
QString qext = QString::fromLatin1(ext);
QTreeWidgetItem *l2 = NULL;
QTreeWidgetItem *l2 = nullptr;
i = j = 0;
while (1) {
......@@ -339,9 +339,9 @@ print_limits(QTreeWidgetItem *l1, const char * glExtensions, bool getProcAddress
const char *ext;
};
QTreeWidgetItem *l2 = NULL, *l3 = NULL;
QTreeWidgetItem *l2 = nullptr, *l3 = nullptr;
#if defined(PFNGLGETPROGRAMIVARBPROC)
PFNGLGETPROGRAMIVARBPROC kcm_glGetProgramivARB = NULL;
PFNGLGETPROGRAMIVARBPROC kcm_glGetProgramivARB = nullptr;
#endif
#define KCMGL_FLOAT 128
......@@ -516,7 +516,7 @@ print_limits(QTreeWidgetItem *l1, const char * glExtensions, bool getProcAddress
if (l2) l2 = newItem(l1, l2, groups[i].descr);
else l2 = newItem(l1, groups[i].descr);
l3 = NULL;
l3 = nullptr;
const struct token_name *cur_token;
for (cur_token = groups[i].group; cur_token->type; cur_token++) {
......@@ -553,7 +553,7 @@ print_limits(QTreeWidgetItem *l1, const char * glExtensions, bool getProcAddress
static QTreeWidgetItem *print_screen_info(QTreeWidgetItem *l1, QTreeWidgetItem *after, const QString &title)
{
QTreeWidgetItem *l2 = NULL, *l3 = NULL;
QTreeWidgetItem *l2 = nullptr, *l3 = nullptr;
if (after) {
l1 = newItem(l1, after, title);
......@@ -605,7 +605,7 @@ static QTreeWidgetItem *print_screen_info(QTreeWidgetItem *l1, QTreeWidgetItem *
#if KCM_HAVE_GLX
if (QGuiApplication::platformName() == QStringLiteral("xcb")) {
l3 = newItem(l2, l3, i18n("Implementation specific"));
print_limits(l3, gli.glExtensions, strstr(gli.clientExtensions, "GLX_ARB_get_proc_address") != NULL);
print_limits(l3, gli.glExtensions, strstr(gli.clientExtensions, "GLX_ARB_get_proc_address") != nullptr);
}
#endif
......@@ -716,7 +716,7 @@ static QTreeWidgetItem *get_gl_info_glx(Display *dpy, int scrnum, Bool allowDire
gli.glRenderer = (const char *) glGetString(GL_RENDERER);
gli.glVersion = (const char *) glGetString(GL_VERSION);
gli.glExtensions = (const char *) glGetString(GL_EXTENSIONS);
gli.displayName = NULL;
gli.displayName = nullptr;
gli.gluVersion = (const char *) gluGetString(GLU_VERSION);
gli.gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
......@@ -835,7 +835,7 @@ static QTreeWidgetItem *get_gl_info_egl(Display *dpy, int scrnum, QTreeWidgetIte
gli.glRenderer = (const char *) glGetString(GL_RENDERER);
gli.glVersion = (const char *) glGetString(GL_VERSION);
gli.glExtensions = (const char *) glGetString(GL_EXTENSIONS);
gli.displayName = NULL;
gli.displayName = nullptr;
result = print_screen_info(l1, after, i18n("Direct Rendering (EGL)"));
}
else {
......@@ -879,7 +879,7 @@ static QTreeWidgetItem *get_gl_info_egl_qt(QTreeWidgetItem *l1, QTreeWidgetItem
gli.glRenderer = (const char *) glGetString(GL_RENDERER);
gli.glVersion = (const char *) glGetString(GL_VERSION);
gli.glExtensions = (const char *) glGetString(GL_EXTENSIONS);
gli.displayName = NULL;
gli.displayName = nullptr;
result = print_screen_info(l1, after, title);
}
else {
......@@ -894,7 +894,7 @@ static QTreeWidgetItem *get_gl_info_egl_qt(QTreeWidgetItem *l1, QTreeWidgetItem
bool GetInfo_OpenGL(QTreeWidget *treeWidget)
{
QTreeWidgetItem *l1, *l2 = NULL;
QTreeWidgetItem *l1, *l2 = nullptr;
static bool isX11 = QGuiApplication::platformName() == QStringLiteral("xcb");
static bool isWayland = QGuiApplication::platformName().contains(QStringLiteral("wayland"));
......@@ -909,7 +909,7 @@ bool GetInfo_OpenGL(QTreeWidget *treeWidget)
l1 = new QTreeWidgetItem(treeWidget);
if (isX11) {
char *displayName = NULL;
char *displayName = nullptr;
Display *dpy;
int numScreens, scrnum;
......
......@@ -33,7 +33,7 @@
#define After(ttf,in) (in.contains(ttf)?QString(in.mid(in.indexOf(ttf)+QString(ttf).length())):QString(""))
NetMon::NetMon(QWidget * parent, KConfig *config) :
QWidget(parent), configFile(config), showmountProc(0), strShare(""), strUser(""), strGroup(""), strMachine(""), strSince(""), strPid(""), iUser(0), iGroup(0), iMachine(0), iPid(0) {
QWidget(parent), configFile(config), showmountProc(nullptr), strShare(""), strUser(""), strGroup(""), strMachine(""), strSince(""), strPid(""), iUser(0), iGroup(0), iMachine(0), iPid(0) {
QBoxLayout *topLayout = new QVBoxLayout(this);
list = new QTreeWidget(this);
......
......@@ -31,7 +31,7 @@
class SambaContainer : public KCModule {
Q_OBJECT
public:
SambaContainer(QWidget *parent=0, const QVariantList &list = QVariantList());
SambaContainer(QWidget *parent=nullptr, const QVariantList &list = QVariantList());
virtual ~SambaContainer();
void load() Q_DECL_OVERRIDE;
void save() Q_DECL_OVERRIDE;
......
......@@ -96,7 +96,7 @@ static void delete_recursive(QTreeWidgetItem *item, const QMap<int, QTreeWidgetI
return;
QTreeWidgetItemIterator it(item, QTreeWidgetItemIterator::All);
while ( *it != NULL ) {
while ( *it != nullptr ) {
QTreeWidgetItem* currentItem = *it;
if (new_items.contains(currentItem->text(1).toUInt()) == false) {
delete_recursive(currentItem->child(0), new_items);
......
......@@ -136,7 +136,7 @@ USBDevice* USBDevice::find(int bus, int device) {
return usbDevice;
}
return NULL;
return nullptr;
}
QString USBDevice::product() {
......@@ -276,7 +276,7 @@ bool USBDevice::parseSys(const QString &dname) {
d.setNameFilters(QStringList() << QStringLiteral("usb*"));
const QStringList list = d.entryList();
for (QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it) {
for (QStringList::const_iterator it = list.constBegin(), total = list.constEnd(); it != total; ++it) {
USBDevice* device = new USBDevice();
int bus = 0;
......
......@@ -56,7 +56,6 @@ KInfoCenter::KInfoCenter() : KXmlGuiWindow( 0, Qt::WindowContextHelpButtonHint )
setCentralWidget(m_cWidget);
QVBoxLayout *cLayout = new QVBoxLayout(m_cWidget);
Q_UNUSED(cLayout);
cLayout->setSpacing(0);
cLayout->setContentsMargins(0, 0, 0, 0);
......
......@@ -45,24 +45,24 @@ void InfoKcmModel::createTreeItems()
{
const KService::List categoryList = KServiceTypeTrader::self()->query(QStringLiteral("KInfoCenterCategory"));
foreach(const KService::Ptr &categoryModule, categoryList) {
for(const KService::Ptr &categoryModule : categoryList) {
m_root->addChild(new KcmCategoryItem(categoryModule,m_root));
}
KService::List moduleList = KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), QStringLiteral("[X-KDE-ParentApp] == 'kinfocenter'"));
const KService::List moduleList = KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), QStringLiteral("[X-KDE-ParentApp] == 'kinfocenter'"));
foreach(const KService::Ptr &kcmModule, moduleList) {
for (const KService::Ptr &kcmModule : moduleList) {
if (kcmModule->isType(KST_KService) == true) {
QString category = kcmModule->property(QStringLiteral("X-KDE-KInfoCenter-Category")).toString().trimmed();
if(!category.isEmpty() || !category.isNull()) {
KcmTreeItem *item = m_root->containsCategory(category);
if(item != NULL) {
if(item != nullptr) {
item->addChild(new KcmTreeItem(kcmModule,item));
} else {
KcmTreeItem *lost = m_root->containsCategory(QStringLiteral("lost_and_found"));
if(lost != NULL) {
if(lost != nullptr) {
lost->addChild(new KcmTreeItem(kcmModule,lost));
} else {
qWarning() << "Lost and found category not found, unable to display lost Kcontrol modules";
......
......@@ -48,7 +48,7 @@ KcmTreeItem *KcmTreeItem::child(const int row)
if(childCount() > row) {
return m_children.value(row);
}
return NULL;
return nullptr;
}
int KcmTreeItem::childCount()
......@@ -112,7 +112,7 @@ KcmTreeItem *KcmTreeItem::containsCategory(const QString& category)
}
}
}
return NULL;
return nullptr;
}
KCModuleInfo KcmTreeItem::kcm() const
......
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