forked from qt-creator/qt-creator
Maemo: Move some device configurations code around.
This commit is contained in:
@@ -176,6 +176,49 @@ private:
|
|||||||
const QString &m_portsSpec;
|
const QString &m_portsSpec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void MaemoPortList::addPort(int port) { addRange(port, port); }
|
||||||
|
|
||||||
|
void MaemoPortList::addRange(int startPort, int endPort)
|
||||||
|
{
|
||||||
|
m_ranges << Range(startPort, endPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MaemoPortList::hasMore() const { return !m_ranges.isEmpty(); }
|
||||||
|
|
||||||
|
int MaemoPortList::count() const
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
foreach (const Range &r, m_ranges)
|
||||||
|
n += r.second - r.first + 1;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MaemoPortList::getNext()
|
||||||
|
{
|
||||||
|
Q_ASSERT(!m_ranges.isEmpty());
|
||||||
|
Range &firstRange = m_ranges.first();
|
||||||
|
const int next = firstRange.first++;
|
||||||
|
if (firstRange.first > firstRange.second)
|
||||||
|
m_ranges.removeFirst();
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MaemoPortList::toString() const
|
||||||
|
{
|
||||||
|
QString stringRep;
|
||||||
|
foreach (const Range &range, m_ranges) {
|
||||||
|
stringRep += QString::number(range.first);
|
||||||
|
if (range.second != range.first)
|
||||||
|
stringRep += QLatin1Char('-') + QString::number(range.second);
|
||||||
|
stringRep += QLatin1Char(',');
|
||||||
|
}
|
||||||
|
if (!stringRep.isEmpty())
|
||||||
|
stringRep.remove(stringRep.length() - 1, 1); // Trailing comma.
|
||||||
|
return stringRep;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MaemoDeviceConfig::Ptr MaemoDeviceConfig::create(const QString &name,
|
MaemoDeviceConfig::Ptr MaemoDeviceConfig::create(const QString &name,
|
||||||
DeviceType type, Id &nextId)
|
DeviceType type, Id &nextId)
|
||||||
{
|
{
|
||||||
@@ -286,6 +329,9 @@ void MaemoDeviceConfig::save(QSettings &settings) const
|
|||||||
settings.setValue(InternalIdKey, m_internalId);
|
settings.setValue(InternalIdKey, m_internalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MaemoDeviceConfig::Id MaemoDeviceConfig::InvalidId = 0;
|
||||||
|
|
||||||
|
|
||||||
MaemoDeviceConfigurations *MaemoDeviceConfigurations::instance(QObject *parent)
|
MaemoDeviceConfigurations *MaemoDeviceConfigurations::instance(QObject *parent)
|
||||||
{
|
{
|
||||||
if (m_instance == 0) {
|
if (m_instance == 0) {
|
||||||
@@ -514,7 +560,7 @@ MaemoDeviceConfig::ConstPtr MaemoDeviceConfigurations::defaultDeviceConfig() con
|
|||||||
int MaemoDeviceConfigurations::indexForInternalId(MaemoDeviceConfig::Id internalId) const
|
int MaemoDeviceConfigurations::indexForInternalId(MaemoDeviceConfig::Id internalId) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_devConfigs.count(); ++i) {
|
for (int i = 0; i < m_devConfigs.count(); ++i) {
|
||||||
if (deviceAt(i)->internalId() == internalId)
|
if (deviceAt(i)->m_internalId == internalId)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@@ -522,7 +568,7 @@ int MaemoDeviceConfigurations::indexForInternalId(MaemoDeviceConfig::Id internal
|
|||||||
|
|
||||||
MaemoDeviceConfig::Id MaemoDeviceConfigurations::internalId(MaemoDeviceConfig::ConstPtr devConf) const
|
MaemoDeviceConfig::Id MaemoDeviceConfigurations::internalId(MaemoDeviceConfig::ConstPtr devConf) const
|
||||||
{
|
{
|
||||||
return devConf ? devConf->internalId() : MaemoDeviceConfig::InvalidId;
|
return devConf ? devConf->m_internalId : MaemoDeviceConfig::InvalidId;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MaemoDeviceConfigurations::rowCount(const QModelIndex &parent) const
|
int MaemoDeviceConfigurations::rowCount(const QModelIndex &parent) const
|
||||||
|
|||||||
@@ -52,45 +52,20 @@ namespace Internal {
|
|||||||
|
|
||||||
class MaemoPortList
|
class MaemoPortList
|
||||||
{
|
{
|
||||||
typedef QPair<int, int> Range;
|
|
||||||
public:
|
public:
|
||||||
void addPort(int port) { addRange(port, port); }
|
void addPort(int port);
|
||||||
void addRange(int startPort, int endPort) {
|
void addRange(int startPort, int endPort);
|
||||||
m_ranges << Range(startPort, endPort);
|
bool hasMore() const;
|
||||||
}
|
int count() const;
|
||||||
bool hasMore() const { return !m_ranges.isEmpty(); }
|
int getNext();
|
||||||
int count() const {
|
QString toString() const;
|
||||||
int n = 0;
|
|
||||||
foreach (const Range &r, m_ranges)
|
|
||||||
n += r.second - r.first + 1;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
int getNext() {
|
|
||||||
Q_ASSERT(!m_ranges.isEmpty());
|
|
||||||
Range &firstRange = m_ranges.first();
|
|
||||||
const int next = firstRange.first++;
|
|
||||||
if (firstRange.first > firstRange.second)
|
|
||||||
m_ranges.removeFirst();
|
|
||||||
return next;
|
|
||||||
}
|
|
||||||
QString toString() const
|
|
||||||
{
|
|
||||||
QString stringRep;
|
|
||||||
foreach (const Range &range, m_ranges) {
|
|
||||||
stringRep += QString::number(range.first);
|
|
||||||
if (range.second != range.first)
|
|
||||||
stringRep += QLatin1Char('-') + QString::number(range.second);
|
|
||||||
stringRep += QLatin1Char(',');
|
|
||||||
}
|
|
||||||
if (!stringRep.isEmpty())
|
|
||||||
stringRep.remove(stringRep.length() - 1, 1); // Trailing comma.
|
|
||||||
return stringRep;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
typedef QPair<int, int> Range;
|
||||||
QList<Range> m_ranges;
|
QList<Range> m_ranges;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class MaemoDeviceConfig
|
class MaemoDeviceConfig
|
||||||
{
|
{
|
||||||
friend class MaemoDeviceConfigurations;
|
friend class MaemoDeviceConfigurations;
|
||||||
@@ -105,10 +80,9 @@ public:
|
|||||||
DeviceType type() const { return m_type; }
|
DeviceType type() const { return m_type; }
|
||||||
QString portsSpec() const { return m_portsSpec; }
|
QString portsSpec() const { return m_portsSpec; }
|
||||||
bool isDefault() const { return m_isDefault; }
|
bool isDefault() const { return m_isDefault; }
|
||||||
Id internalId() const { return m_internalId; }
|
|
||||||
static QString portsRegExpr();
|
static QString portsRegExpr();
|
||||||
|
|
||||||
static const Id InvalidId = 0;
|
static const Id InvalidId;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef QSharedPointer<MaemoDeviceConfig> Ptr;
|
typedef QSharedPointer<MaemoDeviceConfig> Ptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user