Skip to content

Commit cc92894

Browse files
committed
layoutmodel.cpp: simplify by using Pair class
1 parent 83743cd commit cc92894

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed

src/layoutmodel.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
#include "layoutmodel.h"
55
#include "evdev-lst-layouts.h"
66

7-
Layout::Layout(QString code, QString desc)
8-
{
9-
m_code = code;
10-
m_desc = desc;
11-
}
12-
13-
Layout::~Layout() { }
14-
157
LayoutModel::LayoutModel(QObject *parent) : QAbstractListModel(parent)
168
{
179
QString xkb_default_layout = environmentGet("XKB_DEFAULT_LAYOUT");
@@ -50,9 +42,9 @@ LayoutModel::~LayoutModel() { }
5042
QString LayoutModel::getXkbDefaultLayout()
5143
{
5244
QString ret;
53-
QVectorIterator<QSharedPointer<Layout>> iter(m_layouts);
45+
QVectorIterator<QSharedPointer<Pair>> iter(m_layouts);
5446
while (iter.hasNext()) {
55-
ret += iter.next().get()->code();
47+
ret += iter.next().get()->value();
5648
if (iter.hasNext()) {
5749
ret += ",";
5850
}
@@ -74,7 +66,7 @@ QVariant LayoutModel::data(const QModelIndex &index, int role) const
7466
const int row = index.row();
7567
switch (role) {
7668
case Qt::DisplayRole:
77-
return m_layouts.at(row)->desc() + " [" + m_layouts.at(row)->code() + "]";
69+
return m_layouts.at(row)->description() + " [" + m_layouts.at(row)->value() + "]";
7870
}
7971
return {};
8072
}
@@ -87,15 +79,15 @@ void LayoutModel::update(void)
8779

8880
void LayoutModel::addLayout(const QString &code, const QString &desc)
8981
{
90-
QVectorIterator<QSharedPointer<Layout>> iter(m_layouts);
82+
QVectorIterator<QSharedPointer<Pair>> iter(m_layouts);
9183
while (iter.hasNext()) {
92-
if (iter.next().get()->code() == code) {
84+
if (iter.next().get()->value() == code) {
9385
qDebug() << "cannot add the same layout twice";
9486
return;
9587
}
9688
}
9789

98-
m_layouts.append(QSharedPointer<Layout>(new Layout(code, desc)));
90+
m_layouts.append(QSharedPointer<Pair>(new Pair(code, desc)));
9991
update();
10092
}
10193

src/layoutmodel.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
#pragma once
22
#include <QAbstractListModel>
33
#include <QString>
4-
5-
class Layout
6-
{
7-
public:
8-
Layout(QString code, QString desc);
9-
~Layout();
10-
11-
private:
12-
QString m_code;
13-
QString m_desc;
14-
15-
public:
16-
QString code() const { return m_code; }
17-
QString desc() const { return m_desc; }
18-
};
4+
#include "pair.h"
195

206
class LayoutModel : public QAbstractListModel
217
{
@@ -33,5 +19,5 @@ class LayoutModel : public QAbstractListModel
3319

3420
private:
3521
void update(void);
36-
QVector<QSharedPointer<Layout>> m_layouts;
22+
QVector<QSharedPointer<Pair>> m_layouts;
3723
};

0 commit comments

Comments
 (0)