Apply the astyle-kdelibs script

This commit is contained in:
Kevin Ottens 2014-04-26 01:45:47 +02:00
parent c2aa81e2d4
commit 72ba7b4146
210 changed files with 4821 additions and 4923 deletions

View File

@ -54,70 +54,70 @@ void ConfigLoaderTest::cleanup()
void ConfigLoaderTest::boolDefaultValue() void ConfigLoaderTest::boolDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemBool*, "DefaultBoolItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemBool *, "DefaultBoolItem");
QVERIFY(typeItem->isEqual(true)); QVERIFY(typeItem->isEqual(true));
} }
void ConfigLoaderTest::colorDefaultValue() void ConfigLoaderTest::colorDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemColor*, "DefaultColorItem"); GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemColor *, "DefaultColorItem");
QVERIFY(typeItem->isEqual(QColor("#00FF00"))); QVERIFY(typeItem->isEqual(QColor("#00FF00")));
} }
void ConfigLoaderTest::dateTimeDefaultValue() void ConfigLoaderTest::dateTimeDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemDateTime*, "DefaultDateTimeItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemDateTime *, "DefaultDateTimeItem");
QVERIFY(typeItem->isEqual(QDateTime::fromString("Thu Sep 09 2010"))); QVERIFY(typeItem->isEqual(QDateTime::fromString("Thu Sep 09 2010")));
} }
void ConfigLoaderTest::enumDefaultValue() void ConfigLoaderTest::enumDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemEnum*, "DefaultEnumItem"); GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemEnum *, "DefaultEnumItem");
QVERIFY(typeItem->isEqual(3)); QVERIFY(typeItem->isEqual(3));
} }
void ConfigLoaderTest::fontDefaultValue() void ConfigLoaderTest::fontDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemFont*, "DefaultFontItem"); GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemFont *, "DefaultFontItem");
QVERIFY(typeItem->isEqual(QFont("DejaVu Sans"))); QVERIFY(typeItem->isEqual(QFont("DejaVu Sans")));
} }
void ConfigLoaderTest::intDefaultValue() void ConfigLoaderTest::intDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemInt*, "DefaultIntItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemInt *, "DefaultIntItem");
QVERIFY(typeItem->isEqual(27)); QVERIFY(typeItem->isEqual(27));
} }
void ConfigLoaderTest::passwordDefaultValue() void ConfigLoaderTest::passwordDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPassword*, "DefaultPasswordItem"); GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPassword *, "DefaultPasswordItem");
QVERIFY(typeItem->isEqual(QString::fromLatin1("h4x."))); QVERIFY(typeItem->isEqual(QString::fromLatin1("h4x.")));
} }
void ConfigLoaderTest::pathDefaultValue() void ConfigLoaderTest::pathDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPath*, "DefaultPathItem"); GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPath *, "DefaultPathItem");
QVERIFY(typeItem->isEqual(QString::fromLatin1("/dev/null"))); QVERIFY(typeItem->isEqual(QString::fromLatin1("/dev/null")));
} }
void ConfigLoaderTest::stringDefaultValue() void ConfigLoaderTest::stringDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemString*, "DefaultStringItem"); GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemString *, "DefaultStringItem");
QVERIFY(typeItem->isEqual(QString::fromLatin1("TestString"))); QVERIFY(typeItem->isEqual(QString::fromLatin1("TestString")));
} }
void ConfigLoaderTest::stringListDefaultValue() void ConfigLoaderTest::stringListDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemStringList*, "DefaultStringListItem"); GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemStringList *, "DefaultStringListItem");
// Create a string list with the expected values. // Create a string list with the expected values.
QStringList expected; QStringList expected;
@ -132,28 +132,28 @@ void ConfigLoaderTest::stringListDefaultValue()
void ConfigLoaderTest::uintDefaultValue() void ConfigLoaderTest::uintDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemUInt*, "DefaultUIntItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemUInt *, "DefaultUIntItem");
QVERIFY(typeItem->isEqual(7U)); QVERIFY(typeItem->isEqual(7U));
} }
void ConfigLoaderTest::urlDefaultValue() void ConfigLoaderTest::urlDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemUrl*, "DefaultUrlItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemUrl *, "DefaultUrlItem");
QVERIFY(typeItem->isEqual(QUrl("http://kde.org"))); QVERIFY(typeItem->isEqual(QUrl("http://kde.org")));
} }
void ConfigLoaderTest::doubleDefaultValue() void ConfigLoaderTest::doubleDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemDouble*, "DefaultDoubleItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemDouble *, "DefaultDoubleItem");
QVERIFY(typeItem->isEqual(13.37)); QVERIFY(typeItem->isEqual(13.37));
} }
void ConfigLoaderTest::intListDefaultValue() void ConfigLoaderTest::intListDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemIntList*, "DefaultIntListItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemIntList *, "DefaultIntListItem");
// Create a int list with the expected values. // Create a int list with the expected values.
QList<int> expected; QList<int> expected;
@ -169,21 +169,21 @@ void ConfigLoaderTest::intListDefaultValue()
void ConfigLoaderTest::longLongDefaultValue() void ConfigLoaderTest::longLongDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemLongLong*, "DefaultLongLongItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemLongLong *, "DefaultLongLongItem");
QVERIFY(typeItem->isEqual(Q_INT64_C(-9211372036854775808))); QVERIFY(typeItem->isEqual(Q_INT64_C(-9211372036854775808)));
} }
void ConfigLoaderTest::pointDefaultValue() void ConfigLoaderTest::pointDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemPoint*, "DefaultPointItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemPoint *, "DefaultPointItem");
QVERIFY(typeItem->isEqual(QPoint(185, 857))); QVERIFY(typeItem->isEqual(QPoint(185, 857)));
} }
void ConfigLoaderTest::rectDefaultValue() void ConfigLoaderTest::rectDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemRect*, "DefaultRectItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemRect *, "DefaultRectItem");
// Create a new QRect with the expected value. // Create a new QRect with the expected value.
QRect expected; QRect expected;
@ -194,19 +194,17 @@ void ConfigLoaderTest::rectDefaultValue()
void ConfigLoaderTest::sizeDefaultValue() void ConfigLoaderTest::sizeDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemSize*, "DefaultSizeItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemSize *, "DefaultSizeItem");
QVERIFY(typeItem->isEqual(QSize(640, 480))); QVERIFY(typeItem->isEqual(QSize(640, 480)));
} }
void ConfigLoaderTest::ulongLongDefaultValue() void ConfigLoaderTest::ulongLongDefaultValue()
{ {
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemULongLong*, "DefaultULongLongItem"); GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemULongLong *, "DefaultULongLongItem");
QVERIFY(typeItem->isEqual(Q_UINT64_C(9223372036854775806))); QVERIFY(typeItem->isEqual(Q_UINT64_C(9223372036854775806)));
} }
QTEST_MAIN(ConfigLoaderTest) QTEST_MAIN(ConfigLoaderTest)

View File

@ -24,7 +24,7 @@
namespace Plasma namespace Plasma
{ {
class ConfigLoader; class ConfigLoader;
} }
class QFile; class QFile;
@ -59,8 +59,8 @@ private Q_SLOTS:
void ulongLongDefaultValue(); void ulongLongDefaultValue();
private: private:
Plasma::ConfigLoader* cl; Plasma::ConfigLoader *cl;
QFile* configFile; QFile *configFile;
}; };
#endif #endif

View File

@ -45,10 +45,9 @@
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QTimer> #include <QtCore/QTimer>
DynamicTreeModel::DynamicTreeModel(QObject *parent) DynamicTreeModel::DynamicTreeModel(QObject *parent)
: QAbstractItemModel(parent), : QAbstractItemModel(parent),
nextId(1) nextId(1)
{ {
} }
@ -57,125 +56,130 @@ QModelIndex DynamicTreeModel::index(int row, int column, const QModelIndex &pare
// if (column != 0) // if (column != 0)
// return QModelIndex(); // return QModelIndex();
if (column < 0 || row < 0) {
return QModelIndex();
}
if ( column < 0 || row < 0 ) QList<QList<qint64> > childIdColumns = m_childItems.value(parent.internalId());
return QModelIndex();
QList<QList<qint64> > childIdColumns = m_childItems.value(parent.internalId()); const qint64 grandParent = findParentId(parent.internalId());
if (grandParent >= 0) {
QList<QList<qint64> > parentTable = m_childItems.value(grandParent);
Q_ASSERT(parent.column() < parentTable.size());
QList<qint64> parentSiblings = parentTable.at(parent.column());
Q_ASSERT(parent.row() < parentSiblings.size());
}
const qint64 grandParent = findParentId(parent.internalId()); if (childIdColumns.size() == 0) {
if (grandParent >= 0) { return QModelIndex();
QList<QList<qint64> > parentTable = m_childItems.value(grandParent); }
Q_ASSERT(parent.column() < parentTable.size());
QList<qint64> parentSiblings = parentTable.at(parent.column());
Q_ASSERT(parent.row() < parentSiblings.size());
}
if (childIdColumns.size() == 0) if (column >= childIdColumns.size()) {
return QModelIndex(); return QModelIndex();
}
if (column >= childIdColumns.size()) QList<qint64> rowIds = childIdColumns.at(column);
return QModelIndex();
QList<qint64> rowIds = childIdColumns.at(column); if (row >= rowIds.size()) {
return QModelIndex();
}
if ( row >= rowIds.size()) qint64 id = rowIds.at(row);
return QModelIndex();
qint64 id = rowIds.at(row); return createIndex(row, column, reinterpret_cast<void *>(id));
return createIndex(row, column, reinterpret_cast<void *>(id));
} }
qint64 DynamicTreeModel::findParentId(qint64 searchId) const qint64 DynamicTreeModel::findParentId(qint64 searchId) const
{ {
if (searchId <= 0) if (searchId <= 0) {
return -1; return -1;
QHashIterator<qint64, QList<QList<qint64> > > i(m_childItems);
while (i.hasNext())
{
i.next();
QListIterator<QList<qint64> > j(i.value());
while (j.hasNext())
{
QList<qint64> l = j.next();
if (l.contains(searchId))
{
return i.key();
}
} }
}
return -1; QHashIterator<qint64, QList<QList<qint64> > > i(m_childItems);
while (i.hasNext()) {
i.next();
QListIterator<QList<qint64> > j(i.value());
while (j.hasNext()) {
QList<qint64> l = j.next();
if (l.contains(searchId)) {
return i.key();
}
}
}
return -1;
} }
QModelIndex DynamicTreeModel::parent(const QModelIndex &index) const QModelIndex DynamicTreeModel::parent(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid()) {
return QModelIndex(); return QModelIndex();
}
qint64 searchId = index.internalId(); qint64 searchId = index.internalId();
qint64 parentId = findParentId(searchId); qint64 parentId = findParentId(searchId);
// Will never happen for valid index, but what the hey... // Will never happen for valid index, but what the hey...
if (parentId <= 0) if (parentId <= 0) {
return QModelIndex(); return QModelIndex();
}
qint64 grandParentId = findParentId(parentId); qint64 grandParentId = findParentId(parentId);
if (grandParentId < 0) if (grandParentId < 0) {
grandParentId = 0; grandParentId = 0;
}
int column = 0; int column = 0;
QList<qint64> childList = m_childItems.value(grandParentId).at(column); QList<qint64> childList = m_childItems.value(grandParentId).at(column);
int row = childList.indexOf(parentId); int row = childList.indexOf(parentId);
return createIndex(row, column, reinterpret_cast<void *>(parentId)); return createIndex(row, column, reinterpret_cast<void *>(parentId));
} }
int DynamicTreeModel::rowCount(const QModelIndex &index ) const int DynamicTreeModel::rowCount(const QModelIndex &index) const
{ {
QList<QList<qint64> > cols = m_childItems.value(index.internalId()); QList<QList<qint64> > cols = m_childItems.value(index.internalId());
if (cols.size() == 0 ) if (cols.size() == 0) {
return 0; return 0;
}
if (index.column() > 0) if (index.column() > 0) {
return 0; return 0;
}
return cols.at(0).size(); return cols.at(0).size();
} }
int DynamicTreeModel::columnCount(const QModelIndex &index ) const int DynamicTreeModel::columnCount(const QModelIndex &index) const
{ {
// Q_UNUSED(index); // Q_UNUSED(index);
return m_childItems.value(index.internalId()).size(); return m_childItems.value(index.internalId()).size();
} }
QVariant DynamicTreeModel::data(const QModelIndex &index, int role) const QVariant DynamicTreeModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) if (!index.isValid()) {
return QVariant(); return QVariant();
}
if (Qt::DisplayRole == role) if (Qt::DisplayRole == role) {
{ return m_items.value(index.internalId());
return m_items.value(index.internalId()); }
} return QVariant();
return QVariant();
} }
void DynamicTreeModel::clear() void DynamicTreeModel::clear()
{ {
beginResetModel(); beginResetModel();
m_items.clear(); m_items.clear();
m_childItems.clear(); m_childItems.clear();
nextId = 1; nextId = 1;
endResetModel(); endResetModel();
} }
ModelChangeCommand::ModelChangeCommand(DynamicTreeModel *model, QObject *parent)
ModelChangeCommand::ModelChangeCommand( DynamicTreeModel *model, QObject *parent )
: QObject(parent), m_model(model), m_numCols(1), m_startRow(-1), m_endRow(-1) : QObject(parent), m_model(model), m_numCols(1), m_startRow(-1), m_endRow(-1)
{ {
@ -183,18 +187,17 @@ ModelChangeCommand::ModelChangeCommand( DynamicTreeModel *model, QObject *parent
QModelIndex ModelChangeCommand::findIndex(QList<int> rows) QModelIndex ModelChangeCommand::findIndex(QList<int> rows)
{ {
const int col = 0; const int col = 0;
QModelIndex parent = QModelIndex(); QModelIndex parent = QModelIndex();
QListIterator<int> i(rows); QListIterator<int> i(rows);
while (i.hasNext()) while (i.hasNext()) {
{ parent = m_model->index(i.next(), col, parent);
parent = m_model->index(i.next(), col, parent); Q_ASSERT(parent.isValid());
Q_ASSERT(parent.isValid()); }
} return parent;
return parent;
} }
ModelInsertCommand::ModelInsertCommand(DynamicTreeModel *model, QObject *parent ) ModelInsertCommand::ModelInsertCommand(DynamicTreeModel *model, QObject *parent)
: ModelChangeCommand(model, parent) : ModelChangeCommand(model, parent)
{ {
@ -202,38 +205,34 @@ ModelInsertCommand::ModelInsertCommand(DynamicTreeModel *model, QObject *parent
void ModelInsertCommand::doCommand() void ModelInsertCommand::doCommand()
{ {
QModelIndex parent = findIndex(m_rowNumbers); QModelIndex parent = findIndex(m_rowNumbers);
m_model->beginInsertRows(parent, m_startRow, m_endRow); m_model->beginInsertRows(parent, m_startRow, m_endRow);
qint64 parentId = parent.internalId(); qint64 parentId = parent.internalId();
for (int row = m_startRow; row <= m_endRow; row++) for (int row = m_startRow; row <= m_endRow; row++) {
{ for (int col = 0; col < m_numCols; col++) {
for(int col = 0; col < m_numCols; col++ ) if (m_model->m_childItems[parentId].size() <= col) {
{ m_model->m_childItems[parentId].append(QList<qint64>());
if (m_model->m_childItems[parentId].size() <= col) }
{
m_model->m_childItems[parentId].append(QList<qint64>());
}
// QString name = QUuid::createUuid().toString(); // QString name = QUuid::createUuid().toString();
qint64 id = m_model->newId(); qint64 id = m_model->newId();
QString name = QString::number(id); QString name = QString::number(id);
m_model->m_items.insert(id, name); m_model->m_items.insert(id, name);
m_model->m_childItems[parentId][col].insert(row, id); m_model->m_childItems[parentId][col].insert(row, id);
}
} }
} m_model->endInsertRows();
m_model->endInsertRows();
} }
ModelMoveCommand::ModelMoveCommand(DynamicTreeModel *model, QObject *parent) ModelMoveCommand::ModelMoveCommand(DynamicTreeModel *model, QObject *parent)
: ModelChangeCommand(model, parent) : ModelChangeCommand(model, parent)
{ {
} }
bool ModelMoveCommand::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow) bool ModelMoveCommand::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow)
{ {
return m_model->beginMoveRows(srcParent, srcStart, srcEnd, destParent, destRow); return m_model->beginMoveRows(srcParent, srcStart, srcEnd, destParent, destRow);
} }
void ModelMoveCommand::doCommand() void ModelMoveCommand::doCommand()
@ -241,32 +240,28 @@ void ModelMoveCommand::doCommand()
QModelIndex srcParent = findIndex(m_rowNumbers); QModelIndex srcParent = findIndex(m_rowNumbers);
QModelIndex destParent = findIndex(m_destRowNumbers); QModelIndex destParent = findIndex(m_destRowNumbers);
if (!emitPreSignal(srcParent, m_startRow, m_endRow, destParent, m_destRow)) if (!emitPreSignal(srcParent, m_startRow, m_endRow, destParent, m_destRow)) {
{
return; return;
} }
for (int column = 0; column < m_numCols; ++column) for (int column = 0; column < m_numCols; ++column) {
{ QList<qint64> l = m_model->m_childItems.value(srcParent.internalId())[column].mid(m_startRow, m_endRow - m_startRow + 1);
QList<qint64> l = m_model->m_childItems.value(srcParent.internalId())[column].mid(m_startRow, m_endRow - m_startRow + 1 );
for (int i = m_startRow; i <= m_endRow ; i++) for (int i = m_startRow; i <= m_endRow; i++) {
{
m_model->m_childItems[srcParent.internalId()][column].removeAt(m_startRow); m_model->m_childItems[srcParent.internalId()][column].removeAt(m_startRow);
} }
int d; int d;
if (m_destRow < m_startRow) if (m_destRow < m_startRow) {
d = m_destRow; d = m_destRow;
else } else {
{ if (srcParent == destParent) {
if (srcParent == destParent)
d = m_destRow - (m_endRow - m_startRow + 1); d = m_destRow - (m_endRow - m_startRow + 1);
else } else {
d = m_destRow - (m_endRow - m_startRow) + 1; d = m_destRow - (m_endRow - m_startRow) + 1;
}
} }
foreach(const qint64 id, l) foreach (const qint64 id, l) {
{
m_model->m_childItems[destParent.internalId()][column].insert(d++, id); m_model->m_childItems[destParent.internalId()][column].insert(d++, id);
} }
} }
@ -279,8 +274,8 @@ void ModelMoveCommand::emitPostSignal()
m_model->endMoveRows(); m_model->endMoveRows();
} }
ModelResetCommand::ModelResetCommand(DynamicTreeModel* model, QObject* parent) ModelResetCommand::ModelResetCommand(DynamicTreeModel *model, QObject *parent)
: ModelMoveCommand(model, parent) : ModelMoveCommand(model, parent)
{ {
} }
@ -306,8 +301,8 @@ void ModelResetCommand::emitPostSignal()
m_model->reset(); m_model->reset();
} }
ModelResetCommandFixed::ModelResetCommandFixed(DynamicTreeModel* model, QObject* parent) ModelResetCommandFixed::ModelResetCommandFixed(DynamicTreeModel *model, QObject *parent)
: ModelMoveCommand(model, parent) : ModelMoveCommand(model, parent)
{ {
} }

View File

@ -47,118 +47,136 @@
#include <QtCore/QHash> #include <QtCore/QHash>
#include <QtCore/QList> #include <QtCore/QList>
class DynamicTreeModel : public QAbstractItemModel class DynamicTreeModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
DynamicTreeModel(QObject *parent = 0); DynamicTreeModel(QObject *parent = 0);
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const; QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &index = QModelIndex()) const; int rowCount(const QModelIndex &index = QModelIndex()) const;
int columnCount(const QModelIndex &index = QModelIndex()) const; int columnCount(const QModelIndex &index = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
void clear(); void clear();
protected Q_SLOTS: protected Q_SLOTS:
/** /**
Finds the parent id of the string with id @p searchId. Finds the parent id of the string with id @p searchId.
Returns -1 if not found. Returns -1 if not found.
*/ */
qint64 findParentId(qint64 searchId) const; qint64 findParentId(qint64 searchId) const;
private: private:
QHash<qint64, QString> m_items; QHash<qint64, QString> m_items;
QHash<qint64, QList<QList<qint64> > > m_childItems; QHash<qint64, QList<QList<qint64> > > m_childItems;
qint64 nextId; qint64 nextId;
qint64 newId() { return nextId++; }; qint64 newId()
{
return nextId++;
};
QModelIndex m_nextParentIndex; QModelIndex m_nextParentIndex;
int m_nextRow; int m_nextRow;
int m_depth; int m_depth;
int maxDepth; int maxDepth;
friend class ModelInsertCommand; friend class ModelInsertCommand;
friend class ModelMoveCommand; friend class ModelMoveCommand;
friend class ModelResetCommand; friend class ModelResetCommand;
friend class ModelResetCommandFixed; friend class ModelResetCommandFixed;
}; };
class ModelChangeCommand : public QObject class ModelChangeCommand : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ModelChangeCommand( DynamicTreeModel *model, QObject *parent = 0 ); explicit ModelChangeCommand(DynamicTreeModel *model, QObject *parent = 0);
virtual ~ModelChangeCommand() {} virtual ~ModelChangeCommand() {}
void setAncestorRowNumbers(QList<int> rowNumbers) { m_rowNumbers = rowNumbers; } void setAncestorRowNumbers(QList<int> rowNumbers)
{
m_rowNumbers = rowNumbers;
}
QModelIndex findIndex(QList<int> rows); QModelIndex findIndex(QList<int> rows);
void setStartRow(int row) { m_startRow = row; } void setStartRow(int row)
{
m_startRow = row;
}
void setEndRow(int row) { m_endRow = row; } void setEndRow(int row)
{
m_endRow = row;
}
void setNumCols(int cols) { m_numCols = cols; } void setNumCols(int cols)
{
m_numCols = cols;
}
virtual void doCommand() = 0; virtual void doCommand() = 0;
protected: protected:
DynamicTreeModel* m_model; DynamicTreeModel *m_model;
QList<int> m_rowNumbers; QList<int> m_rowNumbers;
int m_numCols; int m_numCols;
int m_startRow; int m_startRow;
int m_endRow; int m_endRow;
}; };
typedef QList<ModelChangeCommand*> ModelChangeCommandList; typedef QList<ModelChangeCommand *> ModelChangeCommandList;
class ModelInsertCommand : public ModelChangeCommand class ModelInsertCommand : public ModelChangeCommand
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ModelInsertCommand(DynamicTreeModel *model, QObject *parent = 0 ); explicit ModelInsertCommand(DynamicTreeModel *model, QObject *parent = 0);
virtual ~ModelInsertCommand() {} virtual ~ModelInsertCommand() {}
virtual void doCommand(); virtual void doCommand();
}; };
class ModelMoveCommand : public ModelChangeCommand class ModelMoveCommand : public ModelChangeCommand
{ {
Q_OBJECT Q_OBJECT
public: public:
ModelMoveCommand(DynamicTreeModel *model, QObject *parent); ModelMoveCommand(DynamicTreeModel *model, QObject *parent);
virtual ~ModelMoveCommand() {} virtual ~ModelMoveCommand() {}
virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow); virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
virtual void doCommand(); virtual void doCommand();
virtual void emitPostSignal(); virtual void emitPostSignal();
void setDestAncestors( QList<int> rows ) { m_destRowNumbers = rows; } void setDestAncestors(QList<int> rows)
{
m_destRowNumbers = rows;
}
void setDestRow(int row) { m_destRow = row; } void setDestRow(int row)
{
m_destRow = row;
}
protected: protected:
QList<int> m_destRowNumbers; QList<int> m_destRowNumbers;
int m_destRow; int m_destRow;
}; };
/** /**
@ -166,14 +184,14 @@ protected:
*/ */
class ModelResetCommand : public ModelMoveCommand class ModelResetCommand : public ModelMoveCommand
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ModelResetCommand(DynamicTreeModel* model, QObject* parent = 0); explicit ModelResetCommand(DynamicTreeModel *model, QObject *parent = 0);
virtual ~ModelResetCommand(); virtual ~ModelResetCommand();
virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow); virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
virtual void emitPostSignal(); virtual void emitPostSignal();
}; };
@ -182,16 +200,15 @@ public:
*/ */
class ModelResetCommandFixed : public ModelMoveCommand class ModelResetCommandFixed : public ModelMoveCommand
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ModelResetCommandFixed(DynamicTreeModel* model, QObject* parent = 0); explicit ModelResetCommandFixed(DynamicTreeModel *model, QObject *parent = 0);
virtual ~ModelResetCommandFixed(); virtual ~ModelResetCommandFixed();
virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow); virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow);
virtual void emitPostSignal(); virtual void emitPostSignal();
}; };
#endif #endif

View File

@ -39,7 +39,6 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QtGui/QtGui> #include <QtGui/QtGui>
#include "modeltest.h" #include "modeltest.h"
@ -48,61 +47,62 @@
//#undef Q_ASSERT //#undef Q_ASSERT
//#define Q_ASSERT QVERIFY //#define Q_ASSERT QVERIFY
Q_DECLARE_METATYPE ( QModelIndex ) Q_DECLARE_METATYPE(QModelIndex)
/*! /*!
Connect to all of the models signals. Whenever anything happens recheck everything. Connect to all of the models signals. Whenever anything happens recheck everything.
*/ */
ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QObject ( parent ), model ( _model ), fetchingMore ( false ) ModelTest::ModelTest(QAbstractItemModel *_model, QObject *parent) : QObject(parent), model(_model), fetchingMore(false)
{ {
Q_ASSERT ( model ); Q_ASSERT(model);
connect ( model, SIGNAL (columnsAboutToBeInserted(QModelIndex,int,int)), connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
this, SLOT (runAllTests()) ); this, SLOT(runAllTests()));
connect ( model, SIGNAL (columnsAboutToBeRemoved(QModelIndex,int,int)), connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
this, SLOT (runAllTests()) ); this, SLOT(runAllTests()));
connect ( model, SIGNAL (columnsInserted(QModelIndex,int,int)), connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)),
this, SLOT (runAllTests()) ); this, SLOT(runAllTests()));
connect ( model, SIGNAL (columnsRemoved(QModelIndex,int,int)), connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
this, SLOT (runAllTests()) ); this, SLOT(runAllTests()));
connect ( model, SIGNAL (dataChanged(QModelIndex,QModelIndex)), connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT (runAllTests()) ); this, SLOT(runAllTests()));
connect ( model, SIGNAL (headerDataChanged(Qt::Orientation,int,int)), connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
this, SLOT (runAllTests()) ); this, SLOT(runAllTests()));
connect ( model, SIGNAL (layoutAboutToBeChanged()), this, SLOT (runAllTests()) ); connect(model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(runAllTests()));
connect ( model, SIGNAL (layoutChanged()), this, SLOT (runAllTests()) ); connect(model, SIGNAL(layoutChanged()), this, SLOT(runAllTests()));
connect ( model, SIGNAL (modelReset()), this, SLOT (runAllTests()) ); connect(model, SIGNAL(modelReset()), this, SLOT(runAllTests()));
connect ( model, SIGNAL (rowsAboutToBeInserted(QModelIndex,int,int)), connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
this, SLOT (runAllTests()) ); this, SLOT(runAllTests()));
connect ( model, SIGNAL (rowsAboutToBeRemoved(QModelIndex,int,int)), connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
this, SLOT (runAllTests()) ); this, SLOT(runAllTests()));
connect ( model, SIGNAL (rowsInserted(QModelIndex,int,int)), connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT (runAllTests()) ); this, SLOT(runAllTests()));
connect ( model, SIGNAL (rowsRemoved(QModelIndex,int,int)), connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT (runAllTests()) ); this, SLOT(runAllTests()));
// Special checks for inserting/removing // Special checks for inserting/removing
connect ( model, SIGNAL (layoutAboutToBeChanged()), connect(model, SIGNAL(layoutAboutToBeChanged()),
this, SLOT (layoutAboutToBeChanged()) ); this, SLOT(layoutAboutToBeChanged()));
connect ( model, SIGNAL (layoutChanged()), connect(model, SIGNAL(layoutChanged()),
this, SLOT (layoutChanged()) ); this, SLOT(layoutChanged()));
connect ( model, SIGNAL (rowsAboutToBeInserted(QModelIndex,int,int)), connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
this, SLOT (rowsAboutToBeInserted(QModelIndex,int,int)) ); this, SLOT(rowsAboutToBeInserted(QModelIndex,int,int)));
connect ( model, SIGNAL (rowsAboutToBeRemoved(QModelIndex,int,int)), connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
this, SLOT (rowsAboutToBeRemoved(QModelIndex,int,int)) ); this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)));
connect ( model, SIGNAL (rowsInserted(QModelIndex,int,int)), connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT (rowsInserted(QModelIndex,int,int)) ); this, SLOT(rowsInserted(QModelIndex,int,int)));
connect ( model, SIGNAL (rowsRemoved(QModelIndex,int,int)), connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT (rowsRemoved(QModelIndex,int,int)) ); this, SLOT(rowsRemoved(QModelIndex,int,int)));
runAllTests(); runAllTests();
} }
void ModelTest::runAllTests() void ModelTest::runAllTests()
{ {
if ( fetchingMore ) if (fetchingMore) {
return; return;
}
nonDestructiveBasicTest(); nonDestructiveBasicTest();
rowCount(); rowCount();
columnCount(); columnCount();
@ -118,32 +118,32 @@ void ModelTest::runAllTests()
*/ */
void ModelTest::nonDestructiveBasicTest() void ModelTest::nonDestructiveBasicTest()
{ {
Q_ASSERT ( model->buddy ( QModelIndex() ) == QModelIndex() ); Q_ASSERT(model->buddy(QModelIndex()) == QModelIndex());
model->canFetchMore ( QModelIndex() ); model->canFetchMore(QModelIndex());
Q_ASSERT ( model->columnCount ( QModelIndex() ) >= 0 ); Q_ASSERT(model->columnCount(QModelIndex()) >= 0);
Q_ASSERT ( model->data ( QModelIndex() ) == QVariant() ); Q_ASSERT(model->data(QModelIndex()) == QVariant());
fetchingMore = true; fetchingMore = true;
model->fetchMore ( QModelIndex() ); model->fetchMore(QModelIndex());
fetchingMore = false; fetchingMore = false;
Qt::ItemFlags flags = model->flags ( QModelIndex() ); Qt::ItemFlags flags = model->flags(QModelIndex());
Q_ASSERT ( flags == Qt::ItemIsDropEnabled || flags == 0 ); Q_ASSERT(flags == Qt::ItemIsDropEnabled || flags == 0);
model->hasChildren ( QModelIndex() ); model->hasChildren(QModelIndex());
model->hasIndex ( 0, 0 ); model->hasIndex(0, 0);
model->headerData ( 0, Qt::Horizontal ); model->headerData(0, Qt::Horizontal);
model->index ( 0, 0 ); model->index(0, 0);
model->itemData ( QModelIndex() ); model->itemData(QModelIndex());
QVariant cache; QVariant cache;
model->match ( QModelIndex(), -1, cache ); model->match(QModelIndex(), -1, cache);
model->mimeTypes(); model->mimeTypes();
Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() ); Q_ASSERT(model->parent(QModelIndex()) == QModelIndex());
Q_ASSERT ( model->rowCount() >= 0 ); Q_ASSERT(model->rowCount() >= 0);
QVariant variant; QVariant variant;
model->setData ( QModelIndex(), variant, -1 ); model->setData(QModelIndex(), variant, -1);
model->setHeaderData ( -1, Qt::Horizontal, QVariant() ); model->setHeaderData(-1, Qt::Horizontal, QVariant());
model->setHeaderData ( 999999, Qt::Horizontal, QVariant() ); model->setHeaderData(999999, Qt::Horizontal, QVariant());
QMap<int, QVariant> roles; QMap<int, QVariant> roles;
model->sibling ( 0, 0, QModelIndex() ); model->sibling(0, 0, QModelIndex());
model->span ( QModelIndex() ); model->span(QModelIndex());
model->supportedDropActions(); model->supportedDropActions();
} }
@ -156,19 +156,21 @@ void ModelTest::rowCount()
{ {
// qDebug() << "rc"; // qDebug() << "rc";
// check top row // check top row
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); QModelIndex topIndex = model->index(0, 0, QModelIndex());
int rows = model->rowCount ( topIndex ); int rows = model->rowCount(topIndex);
Q_ASSERT ( rows >= 0 ); Q_ASSERT(rows >= 0);
if ( rows > 0 ) if (rows > 0) {
Q_ASSERT ( model->hasChildren ( topIndex ) == true ); Q_ASSERT(model->hasChildren(topIndex) == true);
}
QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex ); QModelIndex secondLevelIndex = model->index(0, 0, topIndex);
if ( secondLevelIndex.isValid() ) { // not the top level if (secondLevelIndex.isValid()) { // not the top level
// check a row count where parent is valid // check a row count where parent is valid
rows = model->rowCount ( secondLevelIndex ); rows = model->rowCount(secondLevelIndex);
Q_ASSERT ( rows >= 0 ); Q_ASSERT(rows >= 0);
if ( rows > 0 ) if (rows > 0) {
Q_ASSERT ( model->hasChildren ( secondLevelIndex ) == true ); Q_ASSERT(model->hasChildren(secondLevelIndex) == true);
}
} }
// The models rowCount() is tested more extensively in checkChildren(), // The models rowCount() is tested more extensively in checkChildren(),
@ -181,13 +183,14 @@ void ModelTest::rowCount()
void ModelTest::columnCount() void ModelTest::columnCount()
{ {
// check top row // check top row
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); QModelIndex topIndex = model->index(0, 0, QModelIndex());
Q_ASSERT ( model->columnCount ( topIndex ) >= 0 ); Q_ASSERT(model->columnCount(topIndex) >= 0);
// check a column count where parent is valid // check a column count where parent is valid
QModelIndex childIndex = model->index ( 0, 0, topIndex ); QModelIndex childIndex = model->index(0, 0, topIndex);
if ( childIndex.isValid() ) if (childIndex.isValid()) {
Q_ASSERT ( model->columnCount ( childIndex ) >= 0 ); Q_ASSERT(model->columnCount(childIndex) >= 0);
}
// columnCount() is tested more extensively in checkChildren(), // columnCount() is tested more extensively in checkChildren(),
// but this catches the big mistakes // but this catches the big mistakes
@ -200,19 +203,20 @@ void ModelTest::hasIndex()
{ {
// qDebug() << "hi"; // qDebug() << "hi";
// Make sure that invalid values returns an invalid index // Make sure that invalid values returns an invalid index
Q_ASSERT ( model->hasIndex ( -2, -2 ) == false ); Q_ASSERT(model->hasIndex(-2, -2) == false);
Q_ASSERT ( model->hasIndex ( -2, 0 ) == false ); Q_ASSERT(model->hasIndex(-2, 0) == false);
Q_ASSERT ( model->hasIndex ( 0, -2 ) == false ); Q_ASSERT(model->hasIndex(0, -2) == false);
int rows = model->rowCount(); int rows = model->rowCount();
int columns = model->columnCount(); int columns = model->columnCount();
// check out of bounds // check out of bounds
Q_ASSERT ( model->hasIndex ( rows, columns ) == false ); Q_ASSERT(model->hasIndex(rows, columns) == false);
Q_ASSERT ( model->hasIndex ( rows + 1, columns + 1 ) == false ); Q_ASSERT(model->hasIndex(rows + 1, columns + 1) == false);
if ( rows > 0 ) if (rows > 0) {
Q_ASSERT ( model->hasIndex ( 0, 0 ) == true ); Q_ASSERT(model->hasIndex(0, 0) == true);
}
// hasIndex() is tested more extensively in checkChildren(), // hasIndex() is tested more extensively in checkChildren(),
// but this catches the big mistakes // but this catches the big mistakes
@ -225,24 +229,25 @@ void ModelTest::index()
{ {
// qDebug() << "i"; // qDebug() << "i";
// Make sure that invalid values returns an invalid index // Make sure that invalid values returns an invalid index
Q_ASSERT ( model->index ( -2, -2 ) == QModelIndex() ); Q_ASSERT(model->index(-2, -2) == QModelIndex());
Q_ASSERT ( model->index ( -2, 0 ) == QModelIndex() ); Q_ASSERT(model->index(-2, 0) == QModelIndex());
Q_ASSERT ( model->index ( 0, -2 ) == QModelIndex() ); Q_ASSERT(model->index(0, -2) == QModelIndex());
int rows = model->rowCount(); int rows = model->rowCount();
int columns = model->columnCount(); int columns = model->columnCount();
if ( rows == 0 ) if (rows == 0) {
return; return;
}
// Catch off by one errors // Catch off by one errors
Q_ASSERT ( model->index ( rows, columns ) == QModelIndex() ); Q_ASSERT(model->index(rows, columns) == QModelIndex());
Q_ASSERT ( model->index ( 0, 0 ).isValid() == true ); Q_ASSERT(model->index(0, 0).isValid() == true);
// Make sure that the same index is *always* returned // Make sure that the same index is *always* returned
QModelIndex a = model->index ( 0, 0 ); QModelIndex a = model->index(0, 0);
QModelIndex b = model->index ( 0, 0 ); QModelIndex b = model->index(0, 0);
Q_ASSERT ( a == b ); Q_ASSERT(a == b);
// index() is tested more extensively in checkChildren(), // index() is tested more extensively in checkChildren(),
// but this catches the big mistakes // but this catches the big mistakes
@ -256,10 +261,11 @@ void ModelTest::parent()
// qDebug() << "p"; // qDebug() << "p";
// Make sure the model wont crash and will return an invalid QModelIndex // Make sure the model wont crash and will return an invalid QModelIndex
// when asked for the parent of an invalid index. // when asked for the parent of an invalid index.
Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() ); Q_ASSERT(model->parent(QModelIndex()) == QModelIndex());
if ( model->rowCount() == 0 ) if (model->rowCount() == 0) {
return; return;
}
// Column 0 | Column 1 | // Column 0 | Column 1 |
// QModelIndex() | | // QModelIndex() | |
@ -268,29 +274,29 @@ void ModelTest::parent()
// Common error test #1, make sure that a top level index has a parent // Common error test #1, make sure that a top level index has a parent
// that is a invalid QModelIndex. // that is a invalid QModelIndex.
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); QModelIndex topIndex = model->index(0, 0, QModelIndex());
Q_ASSERT ( model->parent ( topIndex ) == QModelIndex() ); Q_ASSERT(model->parent(topIndex) == QModelIndex());
// Common error test #2, make sure that a second level index has a parent // Common error test #2, make sure that a second level index has a parent
// that is the first level index. // that is the first level index.
if ( model->rowCount ( topIndex ) > 0 ) { if (model->rowCount(topIndex) > 0) {
QModelIndex childIndex = model->index ( 0, 0, topIndex ); QModelIndex childIndex = model->index(0, 0, topIndex);
Q_ASSERT ( model->parent ( childIndex ) == topIndex ); Q_ASSERT(model->parent(childIndex) == topIndex);
} }
// Common error test #3, the second column should NOT have the same children // Common error test #3, the second column should NOT have the same children
// as the first column in a row. // as the first column in a row.
// Usually the second column shouldn't have children. // Usually the second column shouldn't have children.
QModelIndex topIndex1 = model->index ( 0, 1, QModelIndex() ); QModelIndex topIndex1 = model->index(0, 1, QModelIndex());
if ( model->rowCount ( topIndex1 ) > 0 ) { if (model->rowCount(topIndex1) > 0) {
QModelIndex childIndex = model->index ( 0, 0, topIndex ); QModelIndex childIndex = model->index(0, 0, topIndex);
QModelIndex childIndex1 = model->index ( 0, 0, topIndex1 ); QModelIndex childIndex1 = model->index(0, 0, topIndex1);
Q_ASSERT ( childIndex != childIndex1 ); Q_ASSERT(childIndex != childIndex1);
} }
// Full test, walk n levels deep through the model making sure that all // Full test, walk n levels deep through the model making sure that all
// parent's children correctly specify their parent. // parent's children correctly specify their parent.
checkChildren ( QModelIndex() ); checkChildren(QModelIndex());
} }
/*! /*!
@ -307,62 +313,65 @@ void ModelTest::parent()
found the basic bugs because it is easier to figure out the problem in found the basic bugs because it is easier to figure out the problem in
those tests then this one. those tests then this one.
*/ */
void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth ) void ModelTest::checkChildren(const QModelIndex &parent, int currentDepth)
{ {
// First just try walking back up the tree. // First just try walking back up the tree.
QModelIndex p = parent; QModelIndex p = parent;
while ( p.isValid() ) while (p.isValid()) {
p = p.parent(); p = p.parent();
}
// For models that are dynamically populated // For models that are dynamically populated
if ( model->canFetchMore ( parent ) ) { if (model->canFetchMore(parent)) {
fetchingMore = true; fetchingMore = true;
model->fetchMore ( parent ); model->fetchMore(parent);
fetchingMore = false; fetchingMore = false;
} }
int rows = model->rowCount ( parent ); int rows = model->rowCount(parent);
int columns = model->columnCount ( parent ); int columns = model->columnCount(parent);
if ( rows > 0 ) if (rows > 0) {
Q_ASSERT ( model->hasChildren ( parent ) ); Q_ASSERT(model->hasChildren(parent));
}
// Some further testing against rows(), columns(), and hasChildren() // Some further testing against rows(), columns(), and hasChildren()
Q_ASSERT ( rows >= 0 ); Q_ASSERT(rows >= 0);
Q_ASSERT ( columns >= 0 ); Q_ASSERT(columns >= 0);
if ( rows > 0 ) if (rows > 0) {
Q_ASSERT ( model->hasChildren ( parent ) == true ); Q_ASSERT(model->hasChildren(parent) == true);
}
//qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows //qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows
// << "columns:" << columns << "parent column:" << parent.column(); // << "columns:" << columns << "parent column:" << parent.column();
Q_ASSERT ( model->hasIndex ( rows + 1, 0, parent ) == false ); Q_ASSERT(model->hasIndex(rows + 1, 0, parent) == false);
for ( int r = 0; r < rows; ++r ) { for (int r = 0; r < rows; ++r) {
if ( model->canFetchMore ( parent ) ) { if (model->canFetchMore(parent)) {
fetchingMore = true; fetchingMore = true;
model->fetchMore ( parent ); model->fetchMore(parent);
fetchingMore = false; fetchingMore = false;
} }
Q_ASSERT ( model->hasIndex ( r, columns + 1, parent ) == false ); Q_ASSERT(model->hasIndex(r, columns + 1, parent) == false);
for ( int c = 0; c < columns; ++c ) { for (int c = 0; c < columns; ++c) {
Q_ASSERT ( model->hasIndex ( r, c, parent ) == true ); Q_ASSERT(model->hasIndex(r, c, parent) == true);
QModelIndex index = model->index ( r, c, parent ); QModelIndex index = model->index(r, c, parent);
// rowCount() and columnCount() said that it existed... // rowCount() and columnCount() said that it existed...
Q_ASSERT ( index.isValid() == true ); Q_ASSERT(index.isValid() == true);
// index() should always return the same index when called twice in a row // index() should always return the same index when called twice in a row
QModelIndex modifiedIndex = model->index ( r, c, parent ); QModelIndex modifiedIndex = model->index(r, c, parent);
Q_ASSERT ( index == modifiedIndex ); Q_ASSERT(index == modifiedIndex);
// Make sure we get the same index if we request it twice in a row // Make sure we get the same index if we request it twice in a row
QModelIndex a = model->index ( r, c, parent ); QModelIndex a = model->index(r, c, parent);
QModelIndex b = model->index ( r, c, parent ); QModelIndex b = model->index(r, c, parent);
Q_ASSERT ( a == b ); Q_ASSERT(a == b);
// Some basic checking on the index that is returned // Some basic checking on the index that is returned
Q_ASSERT ( index.model() == model ); Q_ASSERT(index.model() == model);
Q_ASSERT ( index.row() == r ); Q_ASSERT(index.row() == r);
Q_ASSERT ( index.column() == c ); Q_ASSERT(index.column() == c);
// While you can technically return a QVariant usually this is a sign // While you can technically return a QVariant usually this is a sign
// of an bug in data() Disable if this really is ok in your model. // of an bug in data() Disable if this really is ok in your model.
// Q_ASSERT ( model->data ( index, Qt::DisplayRole ).isValid() == true ); // Q_ASSERT ( model->data ( index, Qt::DisplayRole ).isValid() == true );
@ -381,17 +390,17 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
// Check that we can get back our real parent. // Check that we can get back our real parent.
// qDebug() << model->parent ( index ) << parent ; // qDebug() << model->parent ( index ) << parent ;
Q_ASSERT ( model->parent ( index ) == parent ); Q_ASSERT(model->parent(index) == parent);
// recursively go down the children // recursively go down the children
if ( model->hasChildren ( index ) && currentDepth < 10 ) { if (model->hasChildren(index) && currentDepth < 10) {
//qDebug() << r << c << "has children" << model->rowCount(index); //qDebug() << r << c << "has children" << model->rowCount(index);
checkChildren ( index, ++currentDepth ); checkChildren(index, ++currentDepth);
}/* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/ }/* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/
// make sure that after testing the children that the index doesn't change. // make sure that after testing the children that the index doesn't change.
QModelIndex newerIndex = model->index ( r, c, parent ); QModelIndex newerIndex = model->index(r, c, parent);
Q_ASSERT ( index == newerIndex ); Q_ASSERT(index == newerIndex);
} }
} }
} }
@ -402,68 +411,69 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
void ModelTest::data() void ModelTest::data()
{ {
// Invalid index should return an invalid qvariant // Invalid index should return an invalid qvariant
Q_ASSERT ( !model->data ( QModelIndex() ).isValid() ); Q_ASSERT(!model->data(QModelIndex()).isValid());
if ( model->rowCount() == 0 ) if (model->rowCount() == 0) {
return; return;
}
// A valid index should have a valid QVariant data // A valid index should have a valid QVariant data
Q_ASSERT ( model->index ( 0, 0 ).isValid() ); Q_ASSERT(model->index(0, 0).isValid());
// shouldn't be able to set data on an invalid index // shouldn't be able to set data on an invalid index
Q_ASSERT ( model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt::DisplayRole ) == false ); Q_ASSERT(model->setData(QModelIndex(), QLatin1String("foo"), Qt::DisplayRole) == false);
// General Purpose roles that should return a QString // General Purpose roles that should return a QString
QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole ); QVariant variant = model->data(model->index(0, 0), Qt::ToolTipRole);
if ( variant.isValid() ) { if (variant.isValid()) {
Q_ASSERT ( qVariantCanConvert<QString> ( variant ) ); Q_ASSERT(qVariantCanConvert<QString> (variant));
} }
variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole ); variant = model->data(model->index(0, 0), Qt::StatusTipRole);
if ( variant.isValid() ) { if (variant.isValid()) {
Q_ASSERT ( qVariantCanConvert<QString> ( variant ) ); Q_ASSERT(qVariantCanConvert<QString> (variant));
} }
variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole ); variant = model->data(model->index(0, 0), Qt::WhatsThisRole);
if ( variant.isValid() ) { if (variant.isValid()) {
Q_ASSERT ( qVariantCanConvert<QString> ( variant ) ); Q_ASSERT(qVariantCanConvert<QString> (variant));
} }
// General Purpose roles that should return a QSize // General Purpose roles that should return a QSize
variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole ); variant = model->data(model->index(0, 0), Qt::SizeHintRole);
if ( variant.isValid() ) { if (variant.isValid()) {
Q_ASSERT ( qVariantCanConvert<QSize> ( variant ) ); Q_ASSERT(qVariantCanConvert<QSize> (variant));
} }
// General Purpose roles that should return a QFont // General Purpose roles that should return a QFont
QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole ); QVariant fontVariant = model->data(model->index(0, 0), Qt::FontRole);
if ( fontVariant.isValid() ) { if (fontVariant.isValid()) {
Q_ASSERT ( qVariantCanConvert<QFont> ( fontVariant ) ); Q_ASSERT(qVariantCanConvert<QFont> (fontVariant));
} }
// Check that the alignment is one we know about // Check that the alignment is one we know about
QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole ); QVariant textAlignmentVariant = model->data(model->index(0, 0), Qt::TextAlignmentRole);
if ( textAlignmentVariant.isValid() ) { if (textAlignmentVariant.isValid()) {
int alignment = textAlignmentVariant.toInt(); int alignment = textAlignmentVariant.toInt();
Q_ASSERT ( alignment == ( alignment & ( Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask ) ) ); Q_ASSERT(alignment == (alignment & (Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask)));
} }
// General Purpose roles that should return a QColor // General Purpose roles that should return a QColor
QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole ); QVariant colorVariant = model->data(model->index(0, 0), Qt::BackgroundColorRole);
if ( colorVariant.isValid() ) { if (colorVariant.isValid()) {
Q_ASSERT ( qVariantCanConvert<QColor> ( colorVariant ) ); Q_ASSERT(qVariantCanConvert<QColor> (colorVariant));
} }
colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole ); colorVariant = model->data(model->index(0, 0), Qt::TextColorRole);
if ( colorVariant.isValid() ) { if (colorVariant.isValid()) {
Q_ASSERT ( qVariantCanConvert<QColor> ( colorVariant ) ); Q_ASSERT(qVariantCanConvert<QColor> (colorVariant));
} }
// Check that the "check state" is one we know about. // Check that the "check state" is one we know about.
QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole ); QVariant checkStateVariant = model->data(model->index(0, 0), Qt::CheckStateRole);
if ( checkStateVariant.isValid() ) { if (checkStateVariant.isValid()) {
int state = checkStateVariant.toInt(); int state = checkStateVariant.toInt();
Q_ASSERT ( state == Qt::Unchecked || Q_ASSERT(state == Qt::Unchecked ||
state == Qt::PartiallyChecked || state == Qt::PartiallyChecked ||
state == Qt::Checked ); state == Qt::Checked);
} }
} }
@ -472,7 +482,7 @@ void ModelTest::data()
\sa rowsInserted() \sa rowsInserted()
*/ */
void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int end ) void ModelTest::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
{ {
// Q_UNUSED(end); // Q_UNUSED(end);
// qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).toString() // qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).toString()
@ -480,10 +490,10 @@ void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, in
// qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) ); // qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) );
Changing c; Changing c;
c.parent = parent; c.parent = parent;
c.oldSize = model->rowCount ( parent ); c.oldSize = model->rowCount(parent);
c.last = model->data ( model->index ( start - 1, 0, parent ) ); c.last = model->data(model->index(start - 1, 0, parent));
c.next = model->data ( model->index ( start, 0, parent ) ); c.next = model->data(model->index(start, 0, parent));
insert.push ( c ); insert.push(c);
} }
/*! /*!
@ -491,10 +501,10 @@ void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, in
\sa rowsAboutToBeInserted() \sa rowsAboutToBeInserted()
*/ */
void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end ) void ModelTest::rowsInserted(const QModelIndex &parent, int start, int end)
{ {
Changing c = insert.pop(); Changing c = insert.pop();
Q_ASSERT ( c.parent == parent ); Q_ASSERT(c.parent == parent);
// qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize // qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize
// << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent ); // << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent );
@ -504,30 +514,32 @@ void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
// } // }
// qDebug(); // qDebug();
Q_ASSERT ( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) ); Q_ASSERT(c.oldSize + (end - start + 1) == model->rowCount(parent));
Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); Q_ASSERT(c.last == model->data(model->index(start - 1, 0, c.parent)));
if (c.next != model->data(model->index(end + 1, 0, c.parent))) { if (c.next != model->data(model->index(end + 1, 0, c.parent))) {
qDebug() << start << end; qDebug() << start << end;
for (int i=0; i < model->rowCount(); ++i) for (int i = 0; i < model->rowCount(); ++i) {
qDebug() << model->index(i, 0).data().toString(); qDebug() << model->index(i, 0).data().toString();
}
qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent)); qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent));
} }
Q_ASSERT ( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) ); Q_ASSERT(c.next == model->data(model->index(end + 1, 0, c.parent)));
} }
void ModelTest::layoutAboutToBeChanged() void ModelTest::layoutAboutToBeChanged()
{ {
for ( int i = 0; i < qBound ( 0, model->rowCount(), 100 ); ++i ) for (int i = 0; i < qBound(0, model->rowCount(), 100); ++i) {
changing.append ( QPersistentModelIndex ( model->index ( i, 0 ) ) ); changing.append(QPersistentModelIndex(model->index(i, 0)));
}
} }
void ModelTest::layoutChanged() void ModelTest::layoutChanged()
{ {
for ( int i = 0; i < changing.count(); ++i ) { for (int i = 0; i < changing.count(); ++i) {
QPersistentModelIndex p = changing[i]; QPersistentModelIndex p = changing[i];
Q_ASSERT ( p == model->index ( p.row(), p.column(), p.parent() ) ); Q_ASSERT(p == model->index(p.row(), p.column(), p.parent()));
} }
changing.clear(); changing.clear();
} }
@ -537,15 +549,15 @@ void ModelTest::layoutChanged()
\sa rowsRemoved() \sa rowsRemoved()
*/ */
void ModelTest::rowsAboutToBeRemoved ( const QModelIndex &parent, int start, int end ) void ModelTest::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
{ {
qDebug() << "ratbr" << parent << start << end; qDebug() << "ratbr" << parent << start << end;
Changing c; Changing c;
c.parent = parent; c.parent = parent;
c.oldSize = model->rowCount ( parent ); c.oldSize = model->rowCount(parent);
c.last = model->data ( model->index ( start - 1, 0, parent ) ); c.last = model->data(model->index(start - 1, 0, parent));
c.next = model->data ( model->index ( end + 1, 0, parent ) ); c.next = model->data(model->index(end + 1, 0, parent));
remove.push ( c ); remove.push(c);
} }
/*! /*!
@ -553,14 +565,13 @@ qDebug() << "ratbr" << parent << start << end;
\sa rowsAboutToBeRemoved() \sa rowsAboutToBeRemoved()
*/ */
void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end ) void ModelTest::rowsRemoved(const QModelIndex &parent, int start, int end)
{ {
qDebug() << "rr" << parent << start << end; qDebug() << "rr" << parent << start << end;
Changing c = remove.pop(); Changing c = remove.pop();
Q_ASSERT ( c.parent == parent ); Q_ASSERT(c.parent == parent);
Q_ASSERT ( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) ); Q_ASSERT(c.oldSize - (end - start + 1) == model->rowCount(parent));
Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); Q_ASSERT(c.last == model->data(model->index(start - 1, 0, c.parent)));
Q_ASSERT ( c.next == model->data ( model->index ( start, 0, c.parent ) ) ); Q_ASSERT(c.next == model->data(model->index(start, 0, c.parent)));
} }

View File

@ -39,7 +39,6 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef MODELTEST_H #ifndef MODELTEST_H
#define MODELTEST_H #define MODELTEST_H
@ -49,46 +48,46 @@
class ModelTest : public QObject class ModelTest : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ModelTest( QAbstractItemModel *model, QObject *parent = 0 ); explicit ModelTest(QAbstractItemModel *model, QObject *parent = 0);
private Q_SLOTS: private Q_SLOTS:
void nonDestructiveBasicTest(); void nonDestructiveBasicTest();
void rowCount(); void rowCount();
void columnCount(); void columnCount();
void hasIndex(); void hasIndex();
void index(); void index();
void parent(); void parent();
void data(); void data();
protected Q_SLOTS: protected Q_SLOTS:
void runAllTests(); void runAllTests();
void layoutAboutToBeChanged(); void layoutAboutToBeChanged();
void layoutChanged(); void layoutChanged();
void rowsAboutToBeInserted( const QModelIndex &parent, int start, int end ); void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
void rowsInserted( const QModelIndex & parent, int start, int end ); void rowsInserted(const QModelIndex &parent, int start, int end);
void rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end ); void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
void rowsRemoved( const QModelIndex & parent, int start, int end ); void rowsRemoved(const QModelIndex &parent, int start, int end);
private: private:
void checkChildren( const QModelIndex &parent, int currentDepth = 0 ); void checkChildren(const QModelIndex &parent, int currentDepth = 0);
QAbstractItemModel *model; QAbstractItemModel *model;
struct Changing { struct Changing {
QModelIndex parent; QModelIndex parent;
int oldSize; int oldSize;
QVariant last; QVariant last;
QVariant next; QVariant next;
}; };
QStack<Changing> insert; QStack<Changing> insert;
QStack<Changing> remove; QStack<Changing> remove;
bool fetchingMore; bool fetchingMore;
QList<QPersistentModelIndex> changing; QList<QPersistentModelIndex> changing;
}; };
#endif #endif

View File

@ -42,7 +42,6 @@ public:
} }
}; };
void PackageStructureTest::initTestCase() void PackageStructureTest::initTestCase()
{ {
m_packagePath = QFINDTESTDATA("data/testpackage"); m_packagePath = QFINDTESTDATA("data/testpackage");
@ -82,10 +81,10 @@ void PackageStructureTest::multiplePaths()
void PackageStructureTest::directories() void PackageStructureTest::directories()
{ {
QList<const char*> dirs; QList<const char *> dirs;
dirs << "config" << "data" << "images" << "theme" << "scripts" << "translations" << "ui"; dirs << "config" << "data" << "images" << "theme" << "scripts" << "translations" << "ui";
QList<const char*> psDirs = ps.directories(); QList<const char *> psDirs = ps.directories();
QCOMPARE(dirs.count(), psDirs.count()); QCOMPARE(dirs.count(), psDirs.count());
@ -114,16 +113,16 @@ void PackageStructureTest::directories()
void PackageStructureTest::requiredDirectories() void PackageStructureTest::requiredDirectories()
{ {
QList<const char*> dirs; QList<const char *> dirs;
QCOMPARE(ps.requiredDirectories(), dirs); QCOMPARE(ps.requiredDirectories(), dirs);
} }
void PackageStructureTest::files() void PackageStructureTest::files()
{ {
QList<const char*> files; QList<const char *> files;
files << "mainconfigui" << "mainconfigxml" << "mainscript"; files << "mainconfigui" << "mainconfigxml" << "mainscript";
QList<const char*> psFiles = ps.files(); QList<const char *> psFiles = ps.files();
//for (int i = 0; i < psFiles.count(); ++i) { //for (int i = 0; i < psFiles.count(); ++i) {
// qDebug() << psFiles[i]; // qDebug() << psFiles[i];
@ -142,10 +141,10 @@ void PackageStructureTest::files()
void PackageStructureTest::requiredFiles() void PackageStructureTest::requiredFiles()
{ {
QList<const char*> files; QList<const char *> files;
files << "mainscript"; files << "mainscript";
QList<const char*> psFiles = ps.requiredFiles(); QList<const char *> psFiles = ps.requiredFiles();
QCOMPARE(files.count(), psFiles.count()); QCOMPARE(files.count(), psFiles.count());
for (int i = 0; i < files.count(); ++i) { for (int i = 0; i < files.count(); ++i) {
@ -181,4 +180,3 @@ void PackageStructureTest::mimeTypes()
QTEST_MAIN(PackageStructureTest) QTEST_MAIN(PackageStructureTest)

View File

@ -25,11 +25,11 @@
class PackageUrlInterceptorTest : public QObject class PackageUrlInterceptorTest : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
PackageUrlInterceptorTest() {} PackageUrlInterceptorTest() {}
private Q_SLOTS: private Q_SLOTS:
void loadAccessManager(); void loadAccessManager();
}; };
#endif #endif

View File

@ -90,7 +90,6 @@ void PlasmoidPackageTest::createTestPackage(const QString &packageName)
file.flush(); file.flush();
file.close(); file.close();
qDebug() << "THIS IS A PLASMOID SCRIPT THING"; qDebug() << "THIS IS A PLASMOID SCRIPT THING";
// Now we have a minimal plasmoid package which is valid. Let's add some // Now we have a minimal plasmoid package which is valid. Let's add some
// files to it for test purposes. // files to it for test purposes.
@ -274,31 +273,29 @@ void PlasmoidPackageTest::createAndInstallPackage()
qDebug() << "Installing " << archivePath; qDebug() << "Installing " << archivePath;
//const QString packageRoot = "plasma/plasmoids/"; //const QString packageRoot = "plasma/plasmoids/";
//const QString servicePrefix = "plasma-applet-"; //const QString servicePrefix = "plasma-applet-";
KJob* job = p->install(archivePath, m_packageRoot); KJob *job = p->install(archivePath, m_packageRoot);
connect(job, SIGNAL(finished(KJob*)), SLOT(packageInstalled(KJob*))); connect(job, SIGNAL(finished(KJob*)), SLOT(packageInstalled(KJob*)));
//QVERIFY(p->isValid()); //QVERIFY(p->isValid());
delete p; delete p;
} }
void PlasmoidPackageTest::packageInstalled(KJob* j) void PlasmoidPackageTest::packageInstalled(KJob *j)
{ {
qDebug() << "!!!!!!!!!!!!!!!!!!!! package installed" << (j->error() == KJob::NoError); qDebug() << "!!!!!!!!!!!!!!!!!!!! package installed" << (j->error() == KJob::NoError);
QVERIFY(j->error() == KJob::NoError); QVERIFY(j->error() == KJob::NoError);
//QVERIFY(p->path()); //QVERIFY(p->path());
Plasma::Package *p = new Plasma::Package(m_defaultPackageStructure); Plasma::Package *p = new Plasma::Package(m_defaultPackageStructure);
KJob* jj = p->uninstall("org.kde.microblog-qml", m_packageRoot); KJob *jj = p->uninstall("org.kde.microblog-qml", m_packageRoot);
//QObject::disconnect(j, SIGNAL(finished(KJob*)), this, SLOT(packageInstalled(KJob*))); //QObject::disconnect(j, SIGNAL(finished(KJob*)), this, SLOT(packageInstalled(KJob*)));
connect(jj, SIGNAL(finished(KJob*)), SLOT(packageInstalled(KJob*))); connect(jj, SIGNAL(finished(KJob*)), SLOT(packageInstalled(KJob*)));
} }
void PlasmoidPackageTest::packageUninstalled(KJob *j)
void PlasmoidPackageTest::packageUninstalled(KJob* j)
{ {
qDebug() << "!!!!!!!!!!!!!!!!!!!!! package uninstalled"; qDebug() << "!!!!!!!!!!!!!!!!!!!!! package uninstalled";
QVERIFY(j->error() == KJob::NoError); QVERIFY(j->error() == KJob::NoError);
} }
QTEST_MAIN(PlasmoidPackageTest) QTEST_MAIN(PlasmoidPackageTest)

View File

@ -39,17 +39,17 @@ private Q_SLOTS:
void filePath(); void filePath();
void entryList(); void entryList();
void packageInstalled(KJob* j); void packageInstalled(KJob *j);
void packageUninstalled(KJob* j); void packageUninstalled(KJob *j);
private: private:
void createTestPackage(const QString &packageName); void createTestPackage(const QString &packageName);
QString m_packageRoot; QString m_packageRoot;
QString m_package; QString m_package;
KJob* m_packageJob; KJob *m_packageJob;
Plasma::Package m_defaultPackage; Plasma::Package m_defaultPackage;
Plasma::PackageStructure* m_defaultPackageStructure; Plasma::PackageStructure *m_defaultPackageStructure;
}; };
#endif #endif

View File

@ -75,6 +75,5 @@ void PluginTest::loadDataEngine()
} }
#include "moc_pluginloadertest.cpp" #include "moc_pluginloadertest.cpp"

View File

@ -25,18 +25,18 @@
class PluginTest : public QObject class PluginTest : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
PluginTest() {} PluginTest() {}
private Q_SLOTS: private Q_SLOTS:
void listEngines(); void listEngines();
void listAppletCategories(); void listAppletCategories();
void listContainmentActions(); void listContainmentActions();
void listContainmentsOfType(); void listContainmentsOfType();
void loadDataEngine(); void loadDataEngine();
private: private:
}; };
#endif #endif

View File

@ -43,7 +43,7 @@ void SortFilterModelTest::setModel()
filterModel.setModel(&model); filterModel.setModel(&model);
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
QList<QVariant> arguments = spy.takeFirst(); QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(arguments.at(0).value<QObject*>(), static_cast<QObject*>(&model)); QCOMPARE(arguments.at(0).value<QObject *>(), static_cast<QObject *>(&model));
filterModel.setModel(&model); filterModel.setModel(&model);
QCOMPARE(spy.count(), 0); QCOMPARE(spy.count(), 0);
@ -54,9 +54,9 @@ void SortFilterModelTest::setEmptyModel()
SortFilterModel filterModel; SortFilterModel filterModel;
QStandardItemModel model; QStandardItemModel model;
filterModel.setModel(&model); filterModel.setModel(&model);
QCOMPARE(filterModel.sourceModel(), static_cast<QAbstractItemModel*>(&model)); QCOMPARE(filterModel.sourceModel(), static_cast<QAbstractItemModel *>(&model));
filterModel.setModel(0); filterModel.setModel(0);
QCOMPARE(filterModel.sourceModel(), static_cast<QAbstractItemModel*>(0)); QCOMPARE(filterModel.sourceModel(), static_cast<QAbstractItemModel *>(0));
} }
void SortFilterModelTest::setFilterRegExp() void SortFilterModelTest::setFilterRegExp()

View File

@ -34,7 +34,6 @@ private Q_SLOTS:
void retrieve(); void retrieve();
void deleteEntry(); void deleteEntry();
private: private:
QVariantMap m_data; QVariantMap m_data;
}; };

View File

@ -31,7 +31,7 @@
#include "httpContainer.h" #include "httpContainer.h"
/* /*
This DataEngine shows how to use a subclass of DataContainer to create and This DataEngine shows how to use a subclass of DataContainer to create and
manage sources. This is particularly useful when managing asynchronous requests, manage sources. This is particularly useful when managing asynchronous requests,
such as sources that reflect network, D-Bus, etc. results. such as sources that reflect network, D-Bus, etc. results.
*/ */

View File

@ -32,7 +32,7 @@
namespace KIO namespace KIO
{ {
class Job; class Job;
}; };
class HttpContainer : public Plasma::DataContainer class HttpContainer : public Plasma::DataContainer

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2010 Aleix Pol Gonzalez <aleixpol@kde.org> * Copyright 2010 Aleix Pol Gonzalez <aleixpol@kde.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -23,13 +23,13 @@
#include <plasma/applet.h> #include <plasma/applet.h>
#include <QStandardItemModel> #include <QStandardItemModel>
AppletSelector::AppletSelector(QObject* parent, const QVariantList& args) AppletSelector::AppletSelector(QObject *parent, const QVariantList &args)
: KDialog() : KDialog()
{ {
Q_UNUSED(args); Q_UNUSED(args);
setButtons(Close); setButtons(Close);
QWidget* w = new QWidget(this); QWidget *w = new QWidget(this);
m_ui = new Ui::AppletSelector; m_ui = new Ui::AppletSelector;
m_ui->setupUi(w); m_ui->setupUi(w);
@ -38,13 +38,13 @@ AppletSelector::AppletSelector(QObject* parent, const QVariantList& args)
setMainWidget(w); setMainWidget(w);
QStandardItemModel* model = new QStandardItemModel(this); QStandardItemModel *model = new QStandardItemModel(this);
const KPluginInfo::List list= Plasma::Applet::listAppletInfo(); const KPluginInfo::List list = Plasma::Applet::listAppletInfo();
foreach(const KPluginInfo& info, list) { foreach (const KPluginInfo &info, list) {
QStandardItem* item = new QStandardItem(KIcon(info.icon()), info.name()); QStandardItem *item = new QStandardItem(KIcon(info.icon()), info.name());
item->setEditable(false); item->setEditable(false);
item->setToolTip(info.comment()); item->setToolTip(info.comment());
item->setData(info.pluginName(), Qt::UserRole+1); item->setData(info.pluginName(), Qt::UserRole + 1);
model->appendRow(item); model->appendRow(item);
} }
@ -59,9 +59,9 @@ AppletSelector::~AppletSelector()
delete m_ui; delete m_ui;
} }
void AppletSelector::selected(const QModelIndex& idx) void AppletSelector::selected(const QModelIndex &idx)
{ {
emit addApplet(idx.data(Qt::UserRole+1).toString()); emit addApplet(idx.data(Qt::UserRole + 1).toString());
} }
#include "appletselector.moc" #include "appletselector.moc"

View File

@ -23,22 +23,25 @@
#include <KDE/KDialog> #include <KDE/KDialog>
class QModelIndex; class QModelIndex;
namespace Ui { class AppletSelector; } namespace Ui
{
class AppletSelector;
}
class AppletSelector : public KDialog class AppletSelector : public KDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AppletSelector(QObject* parent = 0, const QVariantList& args = QVariantList()); explicit AppletSelector(QObject *parent = 0, const QVariantList &args = QVariantList());
~AppletSelector(); ~AppletSelector();
public slots: public slots:
void selected(const QModelIndex& idx); void selected(const QModelIndex &idx);
signals: signals:
void addApplet(const QString& name); void addApplet(const QString &name);
private: private:
Ui::AppletSelector* m_ui; Ui::AppletSelector *m_ui;
}; };
#endif // APPLETSELECTOR_H #endif // APPLETSELECTOR_H

View File

@ -27,13 +27,12 @@
#include <KStandardAction> #include <KStandardAction>
#include <KActionCollection> #include <KActionCollection>
#include <Plasma/Containment> #include <Plasma/Containment>
#include <QApplication> #include <QApplication>
ContainmentShell::ContainmentShell() ContainmentShell::ContainmentShell()
: KParts::MainWindow( ), : KParts::MainWindow(),
m_dialog(0) m_dialog(0)
{ {
setXMLFile("plasma-kpart-shellui.rc"); setXMLFile("plasma-kpart-shellui.rc");
@ -46,7 +45,7 @@ ContainmentShell::ContainmentShell()
// this routine will find and load our Part. it finds the Part by // this routine will find and load our Part. it finds the Part by
// name which is a bad idea usually.. but it's alright in this // name which is a bad idea usually.. but it's alright in this
// case since our Part is made for this Shell // case since our Part is made for this Shell
KService::Ptr service = KService::serviceByDesktopPath( "plasma-kpart.desktop" ); KService::Ptr service = KService::serviceByDesktopPath("plasma-kpart.desktop");
if (service) { if (service) {
Plasma::PluginLoader *loader = new TestShellPluginLoader(); Plasma::PluginLoader *loader = new TestShellPluginLoader();
@ -86,8 +85,8 @@ ContainmentShell::~ContainmentShell()
void ContainmentShell::optionsPreferences() void ContainmentShell::optionsPreferences()
{ {
if (!m_dialog) { if (!m_dialog) {
m_dialog = new AppletSelector( m_part ); m_dialog = new AppletSelector(m_part);
connect( m_dialog, SIGNAL(addApplet(QString)), m_part, SLOT(addApplet(QString)) ); connect(m_dialog, SIGNAL(addApplet(QString)), m_part, SLOT(addApplet(QString)));
} }
m_dialog->show(); m_dialog->show();
} }

View File

@ -33,7 +33,7 @@
*/ */
class ContainmentShell : public KParts::MainWindow class ContainmentShell : public KParts::MainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
ContainmentShell(); ContainmentShell();
virtual ~ContainmentShell(); virtual ~ContainmentShell();
@ -42,8 +42,8 @@ public Q_SLOTS:
void optionsPreferences(); void optionsPreferences();
private: private:
KParts::Part* m_part; KParts::Part *m_part;
KDialog* m_dialog; KDialog *m_dialog;
}; };
#endif // CONTAINMENTSHELL_H #endif // CONTAINMENTSHELL_H

View File

@ -23,10 +23,10 @@
static const char version[] = "0.1"; static const char version[] = "0.1";
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
KAboutData about("plasma-kpart-shell", 0, ki18n("Plasma KPart Shell"), version, ki18n("A KDE KPart Application"), KAboutData::License_GPL, ki18n("(C) 2010 Ryan Rix"), KLocalizedString(), 0, "ry@n.rix.si"); KAboutData about("plasma-kpart-shell", 0, ki18n("Plasma KPart Shell"), version, ki18n("A KDE KPart Application"), KAboutData::License_GPL, ki18n("(C) 2010 Ryan Rix"), KLocalizedString(), 0, "ry@n.rix.si");
about.addAuthor( ki18n("Ryan Rix"), KLocalizedString(), "ry@n.rix.si" ); about.addAuthor(ki18n("Ryan Rix"), KLocalizedString(), "ry@n.rix.si");
KCmdLineArgs::init(argc, argv, &about); KCmdLineArgs::init(argc, argv, &about);
KApplication app; KApplication app;

View File

@ -29,19 +29,19 @@ TestShellPluginLoader::~TestShellPluginLoader()
{ {
} }
Plasma::Applet* TestShellPluginLoader::internalLoadApplet (const QString &name, uint appletId, const QVariantList &args) Plasma::Applet *TestShellPluginLoader::internalLoadApplet(const QString &name, uint appletId, const QVariantList &args)
{ {
kDebug() << "loadApplet called with" << name << appletId << args; kDebug() << "loadApplet called with" << name << appletId << args;
return 0; return 0;
} }
Plasma::DataEngine* TestShellPluginLoader::internalLoadDataEngine(const QString &name) Plasma::DataEngine *TestShellPluginLoader::internalLoadDataEngine(const QString &name)
{ {
kDebug() << "loadEngine called with" << name; kDebug() << "loadEngine called with" << name;
return 0; return 0;
} }
Plasma::Service* TestShellPluginLoader::internalLoadService(const QString &name, const QVariantList &args, QObject *parent) Plasma::Service *TestShellPluginLoader::internalLoadService(const QString &name, const QVariantList &args, QObject *parent)
{ {
kDebug() << "loadService called with" << name << args << parent; kDebug() << "loadService called with" << name << args << parent;
return 0; return 0;

View File

@ -26,10 +26,10 @@ class TestShellPluginLoader : public Plasma::PluginLoader
public: public:
~TestShellPluginLoader(); ~TestShellPluginLoader();
Plasma::Applet* internalLoadApplet (const QString &name, uint appletId = 0, Plasma::Applet *internalLoadApplet(const QString &name, uint appletId = 0,
const QVariantList &args = QVariantList()); const QVariantList &args = QVariantList());
Plasma::DataEngine* internalLoadDataEngine(const QString &name); Plasma::DataEngine *internalLoadDataEngine(const QString &name);
Plasma::Service* internalLoadService(const QString &name, const QVariantList &args, QObject *parent = 0); Plasma::Service *internalLoadService(const QString &name, const QVariantList &args, QObject *parent = 0);
}; };
#endif #endif

View File

@ -19,7 +19,6 @@
#include <QDebug> #include <QDebug>
#include "calendar.h" #include "calendar.h"
Calendar::Calendar(QObject *parent) Calendar::Calendar(QObject *parent)
@ -35,8 +34,8 @@ Calendar::Calendar(QObject *parent)
m_daysModel = new DaysModel(this); m_daysModel = new DaysModel(this);
m_daysModel->setSourceData(&m_dayList); m_daysModel->setSourceData(&m_dayList);
// m_dayHelper = new CalendarDayHelper(this); // m_dayHelper = new CalendarDayHelper(this);
// connect(m_dayHelper, SIGNAL(calendarChanged()), this, SLOT(updateData())); // connect(m_dayHelper, SIGNAL(calendarChanged()), this, SLOT(updateData()));
} }
QDate Calendar::startDate() const QDate Calendar::startDate() const
@ -46,11 +45,11 @@ QDate Calendar::startDate() const
void Calendar::setStartDate(const QDate &dateTime) void Calendar::setStartDate(const QDate &dateTime)
{ {
if(m_startDate == dateTime) { if (m_startDate == dateTime) {
return; return;
} }
m_startDate = dateTime; m_startDate = dateTime;
// m_dayHelper->setDate(m_startDate.year(), m_startDate.month()); // m_dayHelper->setDate(m_startDate.year(), m_startDate.month());
updateData(); updateData();
emit startDateChanged(); emit startDateChanged();
} }
@ -62,8 +61,9 @@ int Calendar::types() const
void Calendar::setTypes(int types) void Calendar::setTypes(int types)
{ {
if (m_types == types) if (m_types == types) {
return; return;
}
// m_types = static_cast<Types>(types); // m_types = static_cast<Types>(types);
// updateTypes(); // updateTypes();
@ -78,7 +78,7 @@ int Calendar::days()
void Calendar::setDays(int days) void Calendar::setDays(int days)
{ {
if(m_days != days) { if (m_days != days) {
m_days = days; m_days = days;
updateData(); updateData();
emit daysChanged(); emit daysChanged();
@ -92,7 +92,7 @@ int Calendar::weeks()
void Calendar::setWeeks(int weeks) void Calendar::setWeeks(int weeks)
{ {
if(m_weeks != weeks) { if (m_weeks != weeks) {
m_weeks = weeks; m_weeks = weeks;
updateData(); updateData();
emit weeksChanged(); emit weeksChanged();
@ -168,7 +168,7 @@ QList<int> Calendar::weeksModel() const
void Calendar::updateData() void Calendar::updateData()
{ {
if(m_days == 0 || m_weeks == 0) { if (m_days == 0 || m_weeks == 0) {
return; return;
} }
@ -182,7 +182,6 @@ void Calendar::updateData()
QDate firstDay(m_startDate.year(), m_startDate.month(), 1); QDate firstDay(m_startDate.year(), m_startDate.month(), 1);
// If the first day is the same as the starting day then we add a complete row before it. // If the first day is the same as the starting day then we add a complete row before it.
if (m_firstDayOfWeek < firstDay.dayOfWeek()) { if (m_firstDayOfWeek < firstDay.dayOfWeek()) {
daysBeforeCurrentMonth = firstDay.dayOfWeek() - m_firstDayOfWeek; daysBeforeCurrentMonth = firstDay.dayOfWeek() - m_firstDayOfWeek;
@ -191,48 +190,48 @@ void Calendar::updateData()
} }
int daysThusFar = daysBeforeCurrentMonth + m_startDate.daysInMonth(); int daysThusFar = daysBeforeCurrentMonth + m_startDate.daysInMonth();
if(daysThusFar < totalDays) { if (daysThusFar < totalDays) {
daysAfterCurrentMonth = totalDays - daysThusFar; daysAfterCurrentMonth = totalDays - daysThusFar;
} }
if(daysBeforeCurrentMonth > 0) { if (daysBeforeCurrentMonth > 0) {
QDate previousMonth = m_startDate.addMonths(-1); QDate previousMonth = m_startDate.addMonths(-1);
//QDate previousMonth(m_startDate.year(), m_startDate.month() - 1, 1); //QDate previousMonth(m_startDate.year(), m_startDate.month() - 1, 1);
for(int i = 0; i < daysBeforeCurrentMonth; i++) { for (int i = 0; i < daysBeforeCurrentMonth; i++) {
DayData day; DayData day;
day.isCurrentMonth = false; day.isCurrentMonth = false;
day.isNextMonth = false; day.isNextMonth = false;
day.isPreviousMonth = true; day.isPreviousMonth = true;
day.dayNumber = previousMonth.daysInMonth() - (daysBeforeCurrentMonth - (i + 1)); day.dayNumber = previousMonth.daysInMonth() - (daysBeforeCurrentMonth - (i + 1));
day.monthNumber =previousMonth.month(); day.monthNumber = previousMonth.month();
day.yearNumber =previousMonth.year(); day.yearNumber = previousMonth.year();
// day.containsEventItems = false; // day.containsEventItems = false;
m_dayList << day; m_dayList << day;
} }
} }
for(int i = 0; i < m_startDate.daysInMonth(); i++) { for (int i = 0; i < m_startDate.daysInMonth(); i++) {
DayData day; DayData day;
day.isCurrentMonth = true; day.isCurrentMonth = true;
day.isNextMonth = false; day.isNextMonth = false;
day.isPreviousMonth = false; day.isPreviousMonth = false;
day.dayNumber = i + 1; // +1 to go form 0 based index to 1 based calendar dates day.dayNumber = i + 1; // +1 to go form 0 based index to 1 based calendar dates
// day.containsEventItems = m_dayHelper->containsEventItems(i + 1); // day.containsEventItems = m_dayHelper->containsEventItems(i + 1);
day.monthNumber = m_startDate.month(); day.monthNumber = m_startDate.month();
day.yearNumber = m_startDate.year(); day.yearNumber = m_startDate.year();
m_dayList << day; m_dayList << day;
} }
if(daysAfterCurrentMonth > 0) { if (daysAfterCurrentMonth > 0) {
for(int i = 0; i < daysAfterCurrentMonth; i++) { for (int i = 0; i < daysAfterCurrentMonth; i++) {
DayData day; DayData day;
day.isCurrentMonth = false; day.isCurrentMonth = false;
day.isNextMonth = true; day.isNextMonth = true;
day.isPreviousMonth = false; day.isPreviousMonth = false;
day.dayNumber = i + 1; // +1 to go form 0 based index to 1 based calendar dates day.dayNumber = i + 1; // +1 to go form 0 based index to 1 based calendar dates
// day.containsEventItems = false; // day.containsEventItems = false;
day.monthNumber = m_startDate.addMonths(1).month(); day.monthNumber = m_startDate.addMonths(1).month();
day.yearNumber = m_startDate.addMonths(1).year(); day.yearNumber = m_startDate.addMonths(1).year();
m_dayList << day; m_dayList << day;
} }
@ -240,12 +239,11 @@ void Calendar::updateData()
const int numOfDaysInCalendar = m_dayList.count(); const int numOfDaysInCalendar = m_dayList.count();
// Fill weeksModel (just a QList<int>) with the week numbers. This needs some tweaking! // Fill weeksModel (just a QList<int>) with the week numbers. This needs some tweaking!
for(int i = 0; i < numOfDaysInCalendar; i += 7) { for (int i = 0; i < numOfDaysInCalendar; i += 7) {
const DayData& data = m_dayList.at(i); const DayData &data = m_dayList.at(i);
m_weekList << QDate(data.yearNumber, data.monthNumber, data.dayNumber).weekNumber(); m_weekList << QDate(data.yearNumber, data.monthNumber, data.dayNumber).weekNumber();
} }
m_daysModel->update(); m_daysModel->update();
// qDebug() << "---------------------------------------------------------------"; // qDebug() << "---------------------------------------------------------------";

View File

@ -27,7 +27,6 @@
#include "daydata.h" #include "daydata.h"
#include "daysmodel.h" #include "daysmodel.h"
class Calendar : public QObject class Calendar : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -111,7 +110,7 @@ class Calendar : public QObject
* metadata about the current day. The exact metadata can be found in "daysmodel.cpp" * metadata about the current day. The exact metadata can be found in "daysmodel.cpp"
* where the exact names usable in QML are being set. * where the exact names usable in QML are being set.
*/ */
Q_PROPERTY(QAbstractListModel* daysModel READ daysModel CONSTANT) Q_PROPERTY(QAbstractListModel *daysModel READ daysModel CONSTANT)
Q_ENUMS(Type) Q_ENUMS(Type)
@ -124,7 +123,6 @@ public:
}; };
Q_DECLARE_FLAGS(Types, Type) Q_DECLARE_FLAGS(Types, Type)
explicit Calendar(QObject *parent = 0); explicit Calendar(QObject *parent = 0);
// Start date // Start date
@ -155,18 +153,17 @@ public:
int year() const; int year() const;
// Models // Models
QAbstractListModel* daysModel() const; QAbstractListModel *daysModel() const;
QList<int> weeksModel() const; QList<int> weeksModel() const;
// QML invokables // QML invokables
Q_INVOKABLE void nextMonth(); Q_INVOKABLE void nextMonth();
Q_INVOKABLE void previousMonth(); Q_INVOKABLE void previousMonth();
Q_INVOKABLE void nextYear(); Q_INVOKABLE void nextYear();
Q_INVOKABLE void previousYear(); Q_INVOKABLE void previousYear();
Q_INVOKABLE QString dayName(int weekday) const ; Q_INVOKABLE QString dayName(int weekday) const;
Q_INVOKABLE int currentWeek() const; Q_INVOKABLE int currentWeek() const;
Q_SIGNALS: Q_SIGNALS:
void startDateChanged(); void startDateChanged();
void typesChanged(); void typesChanged();
@ -179,12 +176,12 @@ Q_SIGNALS:
public Q_SLOTS: public Q_SLOTS:
void updateData(); void updateData();
private: private:
QDate m_startDate; QDate m_startDate;
Types m_types; Types m_types;
QList<DayData> m_dayList; QList<DayData> m_dayList;
DaysModel* m_daysModel; DaysModel *m_daysModel;
QList<int> m_weekList; QList<int> m_weekList;
int m_days; int m_days;

View File

@ -19,32 +19,28 @@
#include "calendardata.h" #include "calendardata.h"
CalendarData::CalendarData(QObject *parent) CalendarData::CalendarData(QObject *parent)
: QObject(parent) : QObject(parent)
, m_types(Holiday | Event | Todo | Journal) , m_types(Holiday | Event | Todo | Journal)
{ {
// m_etmCalendar = new ETMCalendar(); // m_etmCalendar = new ETMCalendar();
// m_etmCalendar->setParent(this); //TODO: hit sergio // m_etmCalendar->setParent(this); //TODO: hit sergio
// EntityTreeModel *model = m_etmCalendar->entityTreeModel(); // EntityTreeModel *model = m_etmCalendar->entityTreeModel();
// model->setCollectionFetchStrategy(EntityTreeModel::InvisibleCollectionFetch); // model->setCollectionFetchStrategy(EntityTreeModel::InvisibleCollectionFetch);
// m_itemList = new EntityMimeTypeFilterModel(this); // m_itemList = new EntityMimeTypeFilterModel(this);
// m_itemList->setSourceModel(model); // m_itemList->setSourceModel(model);
// CalendarRoleProxyModel *roleModel = new CalendarRoleProxyModel(this); // CalendarRoleProxyModel *roleModel = new CalendarRoleProxyModel(this);
// roleModel->setSourceModel(m_itemList); // roleModel->setSourceModel(m_itemList);
// m_filteredList = new DateTimeRangeFilterModel(this); // m_filteredList = new DateTimeRangeFilterModel(this);
// m_filteredList->setSourceModel(roleModel); // m_filteredList->setSourceModel(roleModel);
// updateTypes(); // updateTypes();
} }
QDate CalendarData::startDate() const QDate CalendarData::startDate() const
{ {
return m_startDate; return m_startDate;
@ -52,11 +48,12 @@ QDate CalendarData::startDate() const
void CalendarData::setStartDate(const QDate &dateTime) void CalendarData::setStartDate(const QDate &dateTime)
{ {
if (m_startDate == dateTime) if (m_startDate == dateTime) {
return; return;
}
m_startDate = dateTime; m_startDate = dateTime;
// m_filteredList->setStartDate(m_startDate); // m_filteredList->setStartDate(m_startDate);
emit startDateChanged(); emit startDateChanged();
} }
@ -67,11 +64,12 @@ QDate CalendarData::endDate() const
void CalendarData::setEndDate(const QDate &dateTime) void CalendarData::setEndDate(const QDate &dateTime)
{ {
if (m_endDate == dateTime) if (m_endDate == dateTime) {
return; return;
}
m_endDate = dateTime; m_endDate = dateTime;
// m_filteredList->setEndDate(m_endDate); // m_filteredList->setEndDate(m_endDate);
emit endDateChanged(); emit endDateChanged();
} }

View File

@ -24,9 +24,6 @@
#include <QFlags> #include <QFlags>
#include <QDate> #include <QDate>
class QAbstractItemModel; class QAbstractItemModel;
class CalendarData : public QObject class CalendarData : public QObject
@ -35,10 +32,10 @@ class CalendarData : public QObject
Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged) Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged)
Q_PROPERTY(QDate endDate READ endDate WRITE setEndDate NOTIFY endDateChanged) Q_PROPERTY(QDate endDate READ endDate WRITE setEndDate NOTIFY endDateChanged)
// Q_PROPERTY(int types READ types WRITE setTypes NOTIFY typesChanged) // Q_PROPERTY(int types READ types WRITE setTypes NOTIFY typesChanged)
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
// Q_PROPERTY(QAbstractItemModel* model READ model CONSTANT) // Q_PROPERTY(QAbstractItemModel* model READ model CONSTANT)
Q_ENUMS(Type) Q_ENUMS(Type)
@ -66,20 +63,20 @@ private:
QDate endDate() const; QDate endDate() const;
void setEndDate(const QDate &dateTime); void setEndDate(const QDate &dateTime);
int types() const; int types() const;
// void setTypes(int types); // void setTypes(int types);
QString errorMessage() const; QString errorMessage() const;
bool loading() const; bool loading() const;
// QAbstractItemModel* model() const; // QAbstractItemModel* model() const;
// void updateTypes(); // void updateTypes();
QDate m_startDate; QDate m_startDate;
QDate m_endDate; QDate m_endDate;
Types m_types; Types m_types;
// Akonadi::ETMCalendar *m_etmCalendar; // Akonadi::ETMCalendar *m_etmCalendar;
// Akonadi::EntityMimeTypeFilterModel *m_itemList; // Akonadi::EntityMimeTypeFilterModel *m_itemList;
// DateTimeRangeFilterModel *m_filteredList; // DateTimeRangeFilterModel *m_filteredList;
}; };
#endif // CALENDARDATA_H #endif // CALENDARDATA_H

View File

@ -24,15 +24,12 @@
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QAbstractListModel> #include <QAbstractListModel>
void CalendarPlugin::registerTypes(const char *uri) void CalendarPlugin::registerTypes(const char *uri)
{ {
Q_ASSERT(uri == QLatin1String("org.kde.plasma.calendar")); Q_ASSERT(uri == QLatin1String("org.kde.plasma.calendar"));
qmlRegisterType<CalendarData>(uri, 2, 0, "CalendarData"); qmlRegisterType<CalendarData>(uri, 2, 0, "CalendarData");
qmlRegisterType<Calendar>(uri, 2, 0, "Calendar"); qmlRegisterType<Calendar>(uri, 2, 0, "Calendar");
// qmlRegisterType<CalendarData>(uri, 1, 0, "CalendarData"); // qmlRegisterType<CalendarData>(uri, 1, 0, "CalendarData");
// qmlRegisterType<CalendarData>(uri, 1, 0, "Calendar"); // qmlRegisterType<CalendarData>(uri, 1, 0, "Calendar");
qmlRegisterType<QAbstractItemModel>(); qmlRegisterType<QAbstractItemModel>();
qmlRegisterType<QAbstractListModel>(); qmlRegisterType<QAbstractListModel>();

View File

@ -20,8 +20,6 @@
#ifndef CALENDARPLUGIN_H #ifndef CALENDARPLUGIN_H
#define CALENDARPLUGIN_H #define CALENDARPLUGIN_H
#include <QQmlExtensionPlugin> #include <QQmlExtensionPlugin>
class QQmlEngine; class QQmlEngine;
@ -29,7 +27,7 @@ class QQmlEngine;
class CalendarPlugin : public QQmlExtensionPlugin class CalendarPlugin : public QQmlExtensionPlugin
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public: public:
void registerTypes(const char *uri); void registerTypes(const char *uri);

View File

@ -7,14 +7,13 @@ public:
bool isPreviousMonth; bool isPreviousMonth;
bool isCurrentMonth; bool isCurrentMonth;
bool isNextMonth; bool isNextMonth;
// bool containsHolidayItems; // bool containsHolidayItems;
// bool containsEventItems; // bool containsEventItems;
// bool containsTodoItems; // bool containsTodoItems;
// bool containsJournalItems; // bool containsJournalItems;
int dayNumber; int dayNumber;
int monthNumber; int monthNumber;
int yearNumber; int yearNumber;
}; };
#endif // DAYDATA_H #endif // DAYDATA_H

View File

@ -31,8 +31,8 @@ DaysModel::DaysModel(QObject *parent) :
roleNames.insert(isNextMonth, "isNextMonth"); roleNames.insert(isNextMonth, "isNextMonth");
//roleNames.insert(containsHolidayItems, "containsHolidayItems"); //roleNames.insert(containsHolidayItems, "containsHolidayItems");
//roleNames.insert(containsEventItems, "containsEventItems"); //roleNames.insert(containsEventItems, "containsEventItems");
// roleNames.insert(containsTodoItems, "containsTodoItems"); // roleNames.insert(containsTodoItems, "containsTodoItems");
// roleNames.insert(containsJournalItems, "containsJournalItems"); // roleNames.insert(containsJournalItems, "containsJournalItems");
roleNames.insert(dayNumber, "dayNumber"); roleNames.insert(dayNumber, "dayNumber");
roleNames.insert(monthNumber, "monthNumber"); roleNames.insert(monthNumber, "monthNumber");
roleNames.insert(yearNumber, "yearNumber"); roleNames.insert(yearNumber, "yearNumber");
@ -43,7 +43,7 @@ DaysModel::DaysModel(QObject *parent) :
void DaysModel::setSourceData(QList<DayData> *data) void DaysModel::setSourceData(QList<DayData> *data)
{ {
if(m_data != data) { if (m_data != data) {
m_data = data; m_data = data;
reset(); reset();
} }
@ -52,7 +52,7 @@ void DaysModel::setSourceData(QList<DayData> *data)
int DaysModel::rowCount(const QModelIndex &parent) const int DaysModel::rowCount(const QModelIndex &parent) const
{ {
Q_UNUSED(parent) Q_UNUSED(parent)
if(m_data->size() <= 0) { if (m_data->size() <= 0) {
return 0; return 0;
} else { } else {
return m_data->size(); return m_data->size();
@ -65,19 +65,19 @@ QVariant DaysModel::data(const QModelIndex &index, int role) const
DayData currentData = m_data->at(index.row()); DayData currentData = m_data->at(index.row());
switch(role) { switch (role) {
case isPreviousMonth: case isPreviousMonth:
return currentData.isPreviousMonth; return currentData.isPreviousMonth;
case isNextMonth: case isNextMonth:
return currentData.isNextMonth; return currentData.isNextMonth;
// case containsHolidayItems: // case containsHolidayItems:
// return currentData.containsHolidayItems; // return currentData.containsHolidayItems;
/* case containsEventItems: /* case containsEventItems:
return currentData.containsEventItems; return currentData.containsEventItems;
case containsTodoItems: case containsTodoItems:
return currentData.containsTodoItems; return currentData.containsTodoItems;
case containsJournalItems: case containsJournalItems:
return currentData.containsJournalItems;*/ return currentData.containsJournalItems;*/
case dayNumber: case dayNumber:
return currentData.dayNumber; return currentData.dayNumber;
case monthNumber: case monthNumber:
@ -91,7 +91,7 @@ QVariant DaysModel::data(const QModelIndex &index, int role) const
void DaysModel::update() void DaysModel::update()
{ {
if(m_data->size() <= 0) { if (m_data->size() <= 0) {
return; return;
} }

View File

@ -41,7 +41,7 @@ public:
}; };
explicit DaysModel(QObject *parent = 0); explicit DaysModel(QObject *parent = 0);
void setSourceData(QList<DayData>* data); void setSourceData(QList<DayData> *data);
virtual int rowCount(const QModelIndex &parent) const; virtual int rowCount(const QModelIndex &parent) const;
virtual QVariant data(const QModelIndex &index, int role) const; virtual QVariant data(const QModelIndex &index, int role) const;
void update(); void update();

View File

@ -46,7 +46,6 @@
// #include "dataenginebindings_p.h" // #include "dataenginebindings_p.h"
#include <QDebug> #include <QDebug>
void CoreBindingsPlugin::initializeEngine(QQmlEngine *engine, const char *uri) void CoreBindingsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
@ -61,7 +60,6 @@ void CoreBindingsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
Units *units = new Units(context); Units *units = new Units(context);
context->setContextProperty("units", units); context->setContextProperty("units", units);
if (!engine->rootContext()->contextObject()) { if (!engine->rootContext()->contextObject()) {
KDeclarative::KDeclarative kdeclarative; KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine); kdeclarative.setDeclarativeEngine(engine);
@ -92,9 +90,9 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
qmlRegisterType<ToolTip>(uri, 2, 0, "ToolTipArea"); qmlRegisterType<ToolTip>(uri, 2, 0, "ToolTipArea");
qmlRegisterInterface<Plasma::Service>("Service"); qmlRegisterInterface<Plasma::Service>("Service");
qRegisterMetaType<Plasma::Service*>("Service"); qRegisterMetaType<Plasma::Service *>("Service");
qmlRegisterInterface<Plasma::ServiceJob>("ServiceJob"); qmlRegisterInterface<Plasma::ServiceJob>("ServiceJob");
qRegisterMetaType<Plasma::ServiceJob*>("ServiceJob"); qRegisterMetaType<Plasma::ServiceJob *>("ServiceJob");
qmlRegisterType<ServiceOperationStatus>(uri, 2, 0, "ServiceOperationStatus"); qmlRegisterType<ServiceOperationStatus>(uri, 2, 0, "ServiceOperationStatus");
qmlRegisterType<QAbstractItemModel>(); qmlRegisterType<QAbstractItemModel>();
@ -102,11 +100,10 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
qmlRegisterType<IconItem>(uri, 2, 0, "IconItem"); qmlRegisterType<IconItem>(uri, 2, 0, "IconItem");
qmlRegisterInterface<Plasma::DataSource>("DataSource"); qmlRegisterInterface<Plasma::DataSource>("DataSource");
qRegisterMetaType<Plasma::DataSource*>("DataSource"); qRegisterMetaType<Plasma::DataSource *>("DataSource");
qmlRegisterType<Plasma::WindowThumbnail>(uri, 2, 0, "WindowThumbnail"); qmlRegisterType<Plasma::WindowThumbnail>(uri, 2, 0, "WindowThumbnail");
} }
#include "corebindingsplugin.moc" #include "corebindingsplugin.moc"

View File

@ -38,5 +38,4 @@ public:
void registerTypes(const char *uri); void registerTypes(const char *uri);
}; };
#endif #endif

View File

@ -67,7 +67,7 @@ int qScriptRegisterMapMetaType(
QScriptEngine *engine, QScriptEngine *engine,
const QScriptValue &prototype = QScriptValue() const QScriptValue &prototype = QScriptValue()
#ifndef qdoc #ifndef qdoc
, T * /* dummy */ = 0 , T * /* dummy */ = 0
#endif #endif
) )
{ {

View File

@ -27,14 +27,14 @@
namespace Plasma namespace Plasma
{ {
SortFilterModel::SortFilterModel(QObject* parent) SortFilterModel::SortFilterModel(QObject *parent)
: QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)
{ {
setObjectName("SortFilterModel"); setObjectName("SortFilterModel");
setDynamicSortFilter(true); setDynamicSortFilter(true);
connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SIGNAL(countChanged())); this, SIGNAL(countChanged()));
connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SIGNAL(countChanged())); this, SIGNAL(countChanged()));
connect(this, SIGNAL(modelReset()), connect(this, SIGNAL(modelReset()),
this, SIGNAL(countChanged())); this, SIGNAL(countChanged()));
@ -70,7 +70,7 @@ int SortFilterModel::roleNameToId(const QString &name)
return m_roleIds.value(name); return m_roleIds.value(name);
} }
void SortFilterModel::setModel(QAbstractItemModel* model) void SortFilterModel::setModel(QAbstractItemModel *model)
{ {
if (model == sourceModel()) { if (model == sourceModel()) {
return; return;
@ -165,10 +165,10 @@ int SortFilterModel::mapRowFromSource(int row) const
return mapFromSource(idx).row(); return mapFromSource(idx).row();
} }
DataModel::DataModel(QObject* parent) DataModel::DataModel(QObject *parent)
: QAbstractItemModel(parent), : QAbstractItemModel(parent),
m_dataSource(0), m_dataSource(0),
m_maxRoleId(Qt::UserRole+1) m_maxRoleId(Qt::UserRole + 1)
{ {
//There is one reserved role name: DataEngineSource //There is one reserved role name: DataEngineSource
m_roleNames[m_maxRoleId] = "DataEngineSource"; m_roleNames[m_maxRoleId] = "DataEngineSource";
@ -176,9 +176,9 @@ DataModel::DataModel(QObject* parent)
++m_maxRoleId; ++m_maxRoleId;
setObjectName("DataModel"); setObjectName("DataModel");
connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SIGNAL(countChanged())); this, SIGNAL(countChanged()));
connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SIGNAL(countChanged())); this, SIGNAL(countChanged()));
connect(this, SIGNAL(modelReset()), connect(this, SIGNAL(modelReset()),
this, SIGNAL(countChanged())); this, SIGNAL(countChanged()));
@ -215,7 +215,7 @@ void DataModel::dataUpdated(const QString &sourceName, const QVariantMap &data)
} else { } else {
//a key that matches the one we want exists and is a list of DataEngine::Data //a key that matches the one we want exists and is a list of DataEngine::Data
if (data.contains(m_keyRoleFilter) && if (data.contains(m_keyRoleFilter) &&
data.value(m_keyRoleFilter).canConvert<QVariantList>()) { data.value(m_keyRoleFilter).canConvert<QVariantList>()) {
setItems(sourceName, data.value(m_keyRoleFilter).value<QVariantList>()); setItems(sourceName, data.value(m_keyRoleFilter).value<QVariantList>());
} else if (m_keyRoleFilterRE.isValid()) { } else if (m_keyRoleFilterRE.isValid()) {
//try to match the key we want with a regular expression if set //try to match the key we want with a regular expression if set
@ -265,7 +265,7 @@ QObject *DataModel::dataSource() const
return m_dataSource; return m_dataSource;
} }
void DataModel::setKeyRoleFilter(const QString& key) void DataModel::setKeyRoleFilter(const QString &key)
{ {
// the "key role filter" can be used in one of three ways: // the "key role filter" can be used in one of three ways:
// //
@ -287,7 +287,7 @@ QString DataModel::keyRoleFilter() const
return m_keyRoleFilter; return m_keyRoleFilter;
} }
void DataModel::setSourceFilter(const QString& key) void DataModel::setSourceFilter(const QString &key)
{ {
if (m_sourceFilter == key) { if (m_sourceFilter == key) {
return; return;
@ -410,7 +410,7 @@ void DataModel::removeSource(const QString &sourceName)
QVariant DataModel::data(const QModelIndex &index, int role) const QVariant DataModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || index.column() > 0 || if (!index.isValid() || index.column() > 0 ||
index.row() < 0 || index.row() >= countItems()){ index.row() < 0 || index.row() >= countItems()) {
return QVariant(); return QVariant();
} }

View File

@ -34,7 +34,6 @@ namespace Plasma
class DataSource; class DataSource;
class DataModel; class DataModel;
class SortFilterModel : public QSortFilterProxyModel class SortFilterModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
@ -71,7 +70,7 @@ class SortFilterModel : public QSortFilterProxyModel
friend class DataModel; friend class DataModel;
public: public:
SortFilterModel(QObject* parent=0); SortFilterModel(QObject *parent = 0);
~SortFilterModel(); ~SortFilterModel();
void setModel(QAbstractItemModel *source); void setModel(QAbstractItemModel *source);
@ -87,7 +86,10 @@ public:
void setSortOrder(const Qt::SortOrder order); void setSortOrder(const Qt::SortOrder order);
int count() const {return QSortFilterProxyModel::rowCount();} int count() const
{
return QSortFilterProxyModel::rowCount();
}
/** /**
* Returns the item at index in the list model. * Returns the item at index in the list model.
@ -145,7 +147,7 @@ class DataModel : public QAbstractItemModel
Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(int count READ count NOTIFY countChanged)
public: public:
DataModel(QObject* parent=0); DataModel(QObject *parent = 0);
~DataModel(); ~DataModel();
void setDataSource(QObject *source); void setDataSource(QObject *source);
@ -154,13 +156,13 @@ public:
/** /**
* Include only items with a key that matches this regexp in the model * Include only items with a key that matches this regexp in the model
*/ */
void setKeyRoleFilter(const QString& key); void setKeyRoleFilter(const QString &key);
QString keyRoleFilter() const; QString keyRoleFilter() const;
/** /**
* Include only sources that matches this regexp in the model * Include only sources that matches this regexp in the model
*/ */
void setSourceFilter(const QString& key); void setSourceFilter(const QString &key);
QString sourceFilter() const; QString sourceFilter() const;
int roleNameToId(const QString &name); int roleNameToId(const QString &name);
@ -175,7 +177,10 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const;
int count() const {return countItems();} int count() const
{
return countItems();
}
/** /**
* Returns the item at index in the list model. * Returns the item at index in the list model.

View File

@ -24,7 +24,7 @@
namespace Plasma namespace Plasma
{ {
DataSource::DataSource(QObject* parent) DataSource::DataSource(QObject *parent)
: QObject(parent), : QObject(parent),
m_interval(0), m_interval(0),
m_dataEngine(0), m_dataEngine(0),
@ -120,7 +120,7 @@ void DataSource::setupData()
* It is due little explanation why this is a queued connection: * It is due little explanation why this is a queued connection:
* If sourceAdded arrives immediately, in the case we have a datamodel * If sourceAdded arrives immediately, in the case we have a datamodel
* with items at source level we connect too soon (before setData for * with items at source level we connect too soon (before setData for
* all roles is done), having a dataupdated in the datamodel with only * all roles is done), having a dataupdated in the datamodel with only
* the first role, killing off the other roles. * the first role, killing off the other roles.
* Besides causing a model reset more, unfortunately setRoleNames can be done a single time, so is not possible adding new roles after the * Besides causing a model reset more, unfortunately setRoleNames can be done a single time, so is not possible adding new roles after the
* first setRoleNames() is called. * first setRoleNames() is called.
@ -128,12 +128,12 @@ void DataSource::setupData()
* recommendations engine. * recommendations engine.
*/ */
m_dataEngine = engine; m_dataEngine = engine;
connect(m_dataEngine, SIGNAL(sourceAdded(const QString&)), this, SIGNAL(sourcesChanged()), Qt::QueuedConnection); connect(m_dataEngine, SIGNAL(sourceAdded(QString)), this, SIGNAL(sourcesChanged()), Qt::QueuedConnection);
connect(m_dataEngine, SIGNAL(sourceRemoved(const QString&)), this, SIGNAL(sourcesChanged())); connect(m_dataEngine, SIGNAL(sourceRemoved(QString)), this, SIGNAL(sourcesChanged()));
connect(m_dataEngine, SIGNAL(sourceAdded(const QString&)), this, SIGNAL(sourceAdded(const QString&)), Qt::QueuedConnection); connect(m_dataEngine, SIGNAL(sourceAdded(QString)), this, SIGNAL(sourceAdded(QString)), Qt::QueuedConnection);
connect(m_dataEngine, SIGNAL(sourceRemoved(const QString&)), this, SLOT(removeSource(const QString&))); connect(m_dataEngine, SIGNAL(sourceRemoved(QString)), this, SLOT(removeSource(QString)));
connect(m_dataEngine, SIGNAL(sourceRemoved(const QString&)), this, SIGNAL(sourceRemoved(const QString&))); connect(m_dataEngine, SIGNAL(sourceRemoved(QString)), this, SIGNAL(sourceRemoved(QString)));
} }
foreach (const QString &source, m_connectedSources) { foreach (const QString &source, m_connectedSources) {
@ -163,7 +163,7 @@ void DataSource::modelChanged(const QString &sourceName, QAbstractItemModel *mod
m_models->insert(sourceName, QVariant::fromValue(model)); m_models->insert(sourceName, QVariant::fromValue(model));
//FIXME: this will break in the case a second model is set //FIXME: this will break in the case a second model is set
connect(model, &QObject::destroyed, [=]() { connect(model, &QObject::destroyed, [ = ]() {
m_models->clear(sourceName); m_models->clear(sourceName);
}); });
} }
@ -189,7 +189,7 @@ void DataSource::removeSource(const QString &source)
} }
} }
QObject* DataSource::serviceForSource(const QString &source) QObject *DataSource::serviceForSource(const QString &source)
{ {
if (!m_services.contains(source)) { if (!m_services.contains(source)) {
Plasma::Service *service = m_dataEngine->serviceForSource(source); Plasma::Service *service = m_dataEngine->serviceForSource(source);

View File

@ -30,10 +30,8 @@
#include <Plasma/DataEngineConsumer> #include <Plasma/DataEngineConsumer>
#include <Plasma/DataEngine> #include <Plasma/DataEngine>
class QQmlPropertyMap; class QQmlPropertyMap;
namespace Plasma namespace Plasma
{ {
class DataEngine; class DataEngine;
@ -51,19 +49,25 @@ public:
typedef QMap<QString, QVariant> Data; typedef QMap<QString, QVariant> Data;
DataSource(QObject* parent=0); DataSource(QObject *parent = 0);
/** /**
* true if the connection to the Plasma DataEngine is valid * true if the connection to the Plasma DataEngine is valid
*/ */
Q_PROPERTY(bool valid READ valid) Q_PROPERTY(bool valid READ valid)
bool valid() const {return m_dataEngine && m_dataEngine->isValid();} bool valid() const
{
return m_dataEngine && m_dataEngine->isValid();
}
/** /**
* Polling interval in milliseconds when the data will be fetched again. If 0 no polling will be done. * Polling interval in milliseconds when the data will be fetched again. If 0 no polling will be done.
*/ */
Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged) Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
int interval() const {return m_interval;} int interval() const
{
return m_interval;
}
void setInterval(const int interval); void setInterval(const int interval);
/** /**
@ -71,28 +75,44 @@ public:
*/ */
Q_PROPERTY(QString dataEngine READ engine WRITE setEngine NOTIFY engineChanged) Q_PROPERTY(QString dataEngine READ engine WRITE setEngine NOTIFY engineChanged)
Q_PROPERTY(QString engine READ engine WRITE setEngine NOTIFY engineChanged) Q_PROPERTY(QString engine READ engine WRITE setEngine NOTIFY engineChanged)
QString engine() const {return m_engine;} QString engine() const
{
return m_engine;
}
void setEngine(const QString &e); void setEngine(const QString &e);
/** /**
* String array of all the source names connected to the DataEngine * String array of all the source names connected to the DataEngine
*/ */
Q_PROPERTY(QStringList connectedSources READ connectedSources WRITE setConnectedSources NOTIFY connectedSourcesChanged) Q_PROPERTY(QStringList connectedSources READ connectedSources WRITE setConnectedSources NOTIFY connectedSourcesChanged)
QStringList connectedSources() const {return m_connectedSources;} QStringList connectedSources() const
{
return m_connectedSources;
}
void setConnectedSources(const QStringList &s); void setConnectedSources(const QStringList &s);
/** /**
* Read only string array of all the sources available from the DataEngine (connected or not) * Read only string array of all the sources available from the DataEngine (connected or not)
*/ */
Q_PROPERTY(QStringList sources READ sources NOTIFY sourcesChanged) Q_PROPERTY(QStringList sources READ sources NOTIFY sourcesChanged)
QStringList sources() const {if (m_dataEngine) return m_dataEngine->sources(); else return QStringList();} QStringList sources() const
{
if (m_dataEngine) {
return m_dataEngine->sources();
} else {
return QStringList();
}
}
/** /**
* All the data fetched by this dataengine. * All the data fetched by this dataengine.
* This is a map of maps. At the first level, there are the source names, at the second, they keys set by the DataEngine * This is a map of maps. At the first level, there are the source names, at the second, they keys set by the DataEngine
*/ */
Q_PROPERTY(QQmlPropertyMap *data READ data CONSTANT); Q_PROPERTY(QQmlPropertyMap *data READ data CONSTANT);
QQmlPropertyMap *data() const {return m_data;} QQmlPropertyMap *data() const
{
return m_data;
}
/** /**
* All the models associated to this DataEngine, indexed by source. * All the models associated to this DataEngine, indexed by source.
@ -100,13 +120,16 @@ public:
* The user has to be connected to its source, so the source name has to be present in the connectedSources property. * The user has to be connected to its source, so the source name has to be present in the connectedSources property.
*/ */
Q_PROPERTY(QQmlPropertyMap *models READ models CONSTANT); Q_PROPERTY(QQmlPropertyMap *models READ models CONSTANT);
QQmlPropertyMap *models() const {return m_models;} QQmlPropertyMap *models() const
{
return m_models;
}
/** /**
* @returns a Plasma::Service given a source name * @returns a Plasma::Service given a source name
* @arg QString source source name we want a service of * @arg QString source source name we want a service of
*/ */
Q_INVOKABLE QObject* serviceForSource(const QString &source); Q_INVOKABLE QObject *serviceForSource(const QString &source);
/** /**
* Connect a new source. It adds it to connectedSources * Connect a new source. It adds it to connectedSources
@ -142,8 +165,8 @@ private:
QString m_engine; QString m_engine;
QQmlPropertyMap *m_data; QQmlPropertyMap *m_data;
QQmlPropertyMap *m_models; QQmlPropertyMap *m_models;
Plasma::DataEngine* m_dataEngine; Plasma::DataEngine *m_dataEngine;
Plasma::DataEngineConsumer* m_dataEngineConsumer; Plasma::DataEngineConsumer *m_dataEngineConsumer;
QStringList m_connectedSources; QStringList m_connectedSources;
QStringList m_oldSources; QStringList m_oldSources;
QStringList m_newSources; QStringList m_newSources;

View File

@ -96,7 +96,7 @@ bool FrameSvgItemMargins::isFixed() const
FrameSvgItem::FrameSvgItem(QQuickItem *parent) FrameSvgItem::FrameSvgItem(QQuickItem *parent)
: QQuickItem(parent), : QQuickItem(parent),
m_textureChanged(false) m_textureChanged(false)
{ {
m_frameSvg = new Plasma::FrameSvg(this); m_frameSvg = new Plasma::FrameSvg(this);
m_margins = new FrameSvgItemMargins(m_frameSvg, this); m_margins = new FrameSvgItemMargins(m_frameSvg, this);
@ -107,7 +107,6 @@ FrameSvgItem::FrameSvgItem(QQuickItem *parent)
connect(&m_units, &Units::devicePixelRatioChanged, this, &FrameSvgItem::updateDevicePixelRatio); connect(&m_units, &Units::devicePixelRatioChanged, this, &FrameSvgItem::updateDevicePixelRatio);
} }
FrameSvgItem::~FrameSvgItem() FrameSvgItem::~FrameSvgItem()
{ {
} }
@ -145,7 +144,6 @@ QString FrameSvgItem::imagePath() const
return m_frameSvg->imagePath(); return m_frameSvg->imagePath();
} }
void FrameSvgItem::setPrefix(const QString &prefix) void FrameSvgItem::setPrefix(const QString &prefix)
{ {
if (m_prefix == prefix) { if (m_prefix == prefix) {
@ -190,8 +188,9 @@ FrameSvgItemMargins *FrameSvgItem::fixedMargins() const
void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders) void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders)
{ {
if (m_frameSvg->enabledBorders() == borders) if (m_frameSvg->enabledBorders() == borders) {
return; return;
}
m_frameSvg->setEnabledBorders(borders); m_frameSvg->setEnabledBorders(borders);
emit enabledBordersChanged(); emit enabledBordersChanged();
@ -210,7 +209,7 @@ bool FrameSvgItem::hasElementPrefix(const QString &prefix) const
} }
void FrameSvgItem::geometryChanged(const QRectF &newGeometry, void FrameSvgItem::geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry) const QRectF &oldGeometry)
{ {
if (isComponentComplete()) { if (isComponentComplete()) {
m_frameSvg->resizeFrame(newGeometry.size()); m_frameSvg->resizeFrame(newGeometry.size());
@ -270,7 +269,7 @@ Plasma::FrameSvg *FrameSvgItem::frameSvg() const
return m_frameSvg; return m_frameSvg;
} }
QSGNode* FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData*) QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *)
{ {
if (!window() || !m_frameSvg || !m_frameSvg->hasElementPrefix(m_prefix)) { if (!window() || !m_frameSvg || !m_frameSvg->hasElementPrefix(m_prefix)) {
delete oldNode; delete oldNode;
@ -303,7 +302,6 @@ void FrameSvgItem::componentComplete()
m_textureChanged = true; m_textureChanged = true;
} }
void FrameSvgItem::updateDevicePixelRatio() void FrameSvgItem::updateDevicePixelRatio()
{ {
//devicepixelratio is always set integer in the svg, so needs at least 192dpi to double up. //devicepixelratio is always set integer in the svg, so needs at least 192dpi to double up.

View File

@ -27,9 +27,10 @@
#include "units.h" #include "units.h"
namespace Plasma { namespace Plasma
{
class FrameSvg; class FrameSvg;
class FrameSvgItemMargins : public QObject class FrameSvgItemMargins : public QObject
{ {
@ -128,7 +129,7 @@ class FrameSvgItem : public QQuickItem
Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged) Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
public: public:
FrameSvgItem(QQuickItem *parent=0); FrameSvgItem(QQuickItem *parent = 0);
~FrameSvgItem(); ~FrameSvgItem();
void setImagePath(const QString &path); void setImagePath(const QString &path);
@ -144,7 +145,7 @@ public:
FrameSvgItemMargins *fixedMargins() const; FrameSvgItemMargins *fixedMargins() const;
void geometryChanged(const QRectF &newGeometry, void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry); const QRectF &oldGeometry);
void setImplicitWidth(qreal width); void setImplicitWidth(qreal width);
qreal implicitWidth() const; qreal implicitWidth() const;
@ -162,9 +163,9 @@ public:
* to draw a frame * to draw a frame
* @param prefix the given prefix we want to check if drawable * @param prefix the given prefix we want to check if drawable
*/ */
Q_INVOKABLE bool hasElementPrefix(const QString & prefix) const; Q_INVOKABLE bool hasElementPrefix(const QString &prefix) const;
virtual QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*); virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
protected: protected:
virtual void componentComplete(); virtual void componentComplete();

View File

@ -29,7 +29,6 @@
#include <plasma/svg.h> #include <plasma/svg.h>
QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount) QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount)
{ {
if (from.isNull() && to.isNull()) { if (from.isNull() && to.isNull()) {
@ -43,7 +42,7 @@ QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount)
QRect startRect(from.rect()); QRect startRect(from.rect());
QRect targetRect(to.rect()); QRect targetRect(to.rect());
QSize pixmapSize = startRect.size().expandedTo(targetRect.size()); QSize pixmapSize = startRect.size().expandedTo(targetRect.size());
QRect toRect = QRect(QPoint(0,0), pixmapSize); QRect toRect = QRect(QPoint(0, 0), pixmapSize);
targetRect.moveCenter(toRect.center()); targetRect.moveCenter(toRect.center());
startRect.moveCenter(toRect.center()); startRect.moveCenter(toRect.center());
@ -54,8 +53,8 @@ QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount)
// If the native paint engine supports Porter/Duff compositing and CompositionMode_Plus // If the native paint engine supports Porter/Duff compositing and CompositionMode_Plus
QPaintEngine *paintEngine = from.paintEngine(); QPaintEngine *paintEngine = from.paintEngine();
if (paintEngine && if (paintEngine &&
paintEngine->hasFeature(QPaintEngine::PorterDuff) && paintEngine->hasFeature(QPaintEngine::PorterDuff) &&
paintEngine->hasFeature(QPaintEngine::BlendModes)) { paintEngine->hasFeature(QPaintEngine::BlendModes)) {
QPixmap startPixmap(pixmapSize); QPixmap startPixmap(pixmapSize);
startPixmap.fill(Qt::transparent); startPixmap.fill(Qt::transparent);
@ -163,7 +162,7 @@ IconItem::IconItem(QQuickItem *parent)
{ {
m_loadPixmapTimer.setSingleShot(true); m_loadPixmapTimer.setSingleShot(true);
m_loadPixmapTimer.setInterval(150); m_loadPixmapTimer.setInterval(150);
connect(&m_loadPixmapTimer, &QTimer::timeout, [=] () { connect(&m_loadPixmapTimer, &QTimer::timeout, [ = ]() {
loadPixmap(); loadPixmap();
}); });
@ -183,7 +182,6 @@ IconItem::IconItem(QQuickItem *parent)
connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()), connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()),
this, SIGNAL(implicitHeightChanged())); this, SIGNAL(implicitHeightChanged()));
connect(this, SIGNAL(enabledChanged()), connect(this, SIGNAL(enabledChanged()),
&m_loadPixmapTimer, SLOT(start())); &m_loadPixmapTimer, SLOT(start()));
@ -192,7 +190,6 @@ IconItem::IconItem(QQuickItem *parent)
setImplicitHeight(KIconLoader::global()->currentSize(KIconLoader::Dialog)); setImplicitHeight(KIconLoader::global()->currentSize(KIconLoader::Dialog));
} }
IconItem::~IconItem() IconItem::~IconItem()
{ {
} }
@ -226,7 +223,7 @@ void IconItem::setSource(const QVariant &source)
m_icon = QIcon(); m_icon = QIcon();
connect(m_svgIcon, SIGNAL(repaintNeeded()), this, SLOT(loadPixmap())); connect(m_svgIcon, SIGNAL(repaintNeeded()), this, SLOT(loadPixmap()));
//ok, svg not available //ok, svg not available
} else { } else {
m_icon = QIcon::fromTheme(source.toString()); m_icon = QIcon::fromTheme(source.toString());
delete m_svgIcon; delete m_svgIcon;
@ -318,7 +315,7 @@ void IconItem::paint(QPainter *painter)
const int iconSize = adjustedSize(qMin(boundingRect().size().width(), boundingRect().size().height())); const int iconSize = adjustedSize(qMin(boundingRect().size().width(), boundingRect().size().height()));
const QRect destRect(QPointF(boundingRect().center() - QPointF(iconSize/2, iconSize/2)).toPoint(), const QRect destRect(QPointF(boundingRect().center() - QPointF(iconSize / 2, iconSize / 2)).toPoint(),
QSize(iconSize, iconSize)); QSize(iconSize, iconSize));
if (m_animation->state() == QAbstractAnimation::Running) { if (m_animation->state() == QAbstractAnimation::Running) {
@ -326,7 +323,7 @@ void IconItem::paint(QPainter *painter)
result = transition(result, result = transition(result,
m_iconPixmaps.last(), m_animValue); m_iconPixmaps.last(), m_animValue);
painter->drawPixmap(destRect, result); painter->drawPixmap(destRect, result);
//simpler logic for just paint //simpler logic for just paint
} else { } else {
painter->drawPixmap(destRect, m_iconPixmaps.first()); painter->drawPixmap(destRect, m_iconPixmaps.first());
} }
@ -349,13 +346,13 @@ void IconItem::valueChanged(const QVariant &value)
int IconItem::adjustedSize(int size) int IconItem::adjustedSize(int size)
{ {
//FIXME: Heuristic: allow 24x24 for icons/ that are in the systray(ugly) //FIXME: Heuristic: allow 24x24 for icons/ that are in the systray(ugly)
if (m_svgIcon && m_svgIcon->imagePath().contains("icons/") && if (m_svgIcon && m_svgIcon->imagePath().contains("icons/") &&
size > KIconLoader::SizeSmallMedium && size > KIconLoader::SizeSmallMedium &&
size < KIconLoader::SizeMedium) { size < KIconLoader::SizeMedium) {
return 24; return 24;
//if size is less than 16, leave as is //if size is less than 16, leave as is
} else if (size < KIconLoader::SizeSmall) { } else if (size < KIconLoader::SizeSmall) {
//do nothing //do nothing
} else if (size < KIconLoader::SizeSmallMedium) { } else if (size < KIconLoader::SizeSmallMedium) {
@ -366,7 +363,7 @@ int IconItem::adjustedSize(int size)
return KIconLoader::SizeMedium; return KIconLoader::SizeMedium;
} else if (size < KIconLoader::SizeHuge) { } else if (size < KIconLoader::SizeHuge) {
return KIconLoader::SizeLarge; return KIconLoader::SizeLarge;
//if size is more than 64, leave as is //if size is more than 64, leave as is
} }
return size; return size;
@ -378,7 +375,7 @@ void IconItem::loadPixmap()
//final pixmap to paint //final pixmap to paint
QPixmap result; QPixmap result;
if (size<=0) { if (size <= 0) {
//m_iconPixmaps.clear(); //m_iconPixmaps.clear();
m_animation->stop(); m_animation->stop();
update(); update();

View File

@ -28,8 +28,9 @@
class QPropertyAnimation; class QPropertyAnimation;
namespace Plasma { namespace Plasma
class Svg; {
class Svg;
} }
class IconItem : public QQuickPaintedItem class IconItem : public QQuickPaintedItem
@ -43,7 +44,7 @@ class IconItem : public QQuickPaintedItem
public: public:
IconItem(QQuickItem *parent=0); IconItem(QQuickItem *parent = 0);
~IconItem(); ~IconItem();
void setSource(const QVariant &source); void setSource(const QVariant &source);

View File

@ -19,8 +19,6 @@
#include "serviceoperationstatus.h" #include "serviceoperationstatus.h"
ServiceOperationStatus::ServiceOperationStatus(QObject *parent) ServiceOperationStatus::ServiceOperationStatus(QObject *parent)
: QObject(parent), : QObject(parent),
m_enabled(false) m_enabled(false)

View File

@ -23,8 +23,9 @@
#include "plasma/service.h" #include "plasma/service.h"
namespace Plasma { namespace Plasma
class Service; {
class Service;
} }
class ServiceOperationStatus : public QObject class ServiceOperationStatus : public QObject
@ -47,7 +48,7 @@ class ServiceOperationStatus : public QObject
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
public: public:
ServiceOperationStatus(QObject *parent=0); ServiceOperationStatus(QObject *parent = 0);
~ServiceOperationStatus(); ~ServiceOperationStatus();
void setService(Plasma::Service *service); void setService(Plasma::Service *service);
@ -73,5 +74,4 @@ private:
bool m_enabled; bool m_enabled;
}; };
#endif #endif

View File

@ -43,7 +43,6 @@ SvgItem::SvgItem(QQuickItem *parent)
connect(&m_units, &Units::devicePixelRatioChanged, this, &SvgItem::updateDevicePixelRatio); connect(&m_units, &Units::devicePixelRatioChanged, this, &SvgItem::updateDevicePixelRatio);
} }
SvgItem::~SvgItem() SvgItem::~SvgItem()
{ {
} }
@ -85,7 +84,6 @@ QSizeF SvgItem::naturalSize() const
return m_svg.data()->size(); return m_svg.data()->size();
} }
void SvgItem::setSvg(Plasma::Svg *svg) void SvgItem::setSvg(Plasma::Svg *svg)
{ {
if (m_svg) { if (m_svg) {
@ -100,7 +98,6 @@ void SvgItem::setSvg(Plasma::Svg *svg)
connect(svg, SIGNAL(sizeChanged()), this, SIGNAL(naturalSizeChanged())); connect(svg, SIGNAL(sizeChanged()), this, SIGNAL(naturalSizeChanged()));
} }
if (implicitWidth() <= 0) { if (implicitWidth() <= 0) {
setImplicitWidth(naturalSize().width()); setImplicitWidth(naturalSize().width());
} }

View File

@ -24,9 +24,10 @@
#include "units.h" #include "units.h"
namespace Plasma { namespace Plasma
{
class Svg; class Svg;
class SvgItem : public QQuickItem class SvgItem : public QQuickItem
{ {
@ -47,7 +48,7 @@ class SvgItem : public QQuickItem
* </code> * </code>
* Instead of a Svg declaration it can also be the id of a Svg declared elsewhere, useful to share Svg instances. * Instead of a Svg declaration it can also be the id of a Svg declared elsewhere, useful to share Svg instances.
*/ */
Q_PROPERTY(Plasma::Svg * svg READ svg WRITE setSvg NOTIFY svgChanged) Q_PROPERTY(Plasma::Svg *svg READ svg WRITE setSvg NOTIFY svgChanged)
/** /**
* The natural, unscaled size of the svg document or the element. useful if a pixel perfect rendering of outlines is needed. * The natural, unscaled size of the svg document or the element. useful if a pixel perfect rendering of outlines is needed.
@ -70,7 +71,7 @@ class SvgItem : public QQuickItem
Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged) Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
public: public:
SvgItem(QQuickItem *parent=0); SvgItem(QQuickItem *parent = 0);
~SvgItem(); ~SvgItem();
void setElementId(const QString &elementID); void setElementId(const QString &elementID);
@ -90,7 +91,7 @@ public:
void setImplicitHeight(qreal height); void setImplicitHeight(qreal height);
qreal implicitHeight() const; qreal implicitHeight() const;
QSGNode* updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData); QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData);
Q_SIGNALS: Q_SIGNALS:
void elementIdChanged(); void elementIdChanged();

View File

@ -22,7 +22,8 @@
#include <QSGSimpleTextureNode> #include <QSGSimpleTextureNode>
namespace Plasma { namespace Plasma
{
/** /**
* This class wraps QSGSimpleTextureNode * This class wraps QSGSimpleTextureNode
@ -31,18 +32,19 @@ namespace Plasma {
class SVGTextureNode : public QSGSimpleTextureNode class SVGTextureNode : public QSGSimpleTextureNode
{ {
public: public:
SVGTextureNode() {} SVGTextureNode() {}
/** /**
* Set the current texture * Set the current texture
* the object takes ownership of the texture * the object takes ownership of the texture
*/ */
void setTexture(QSGTexture *texture) { void setTexture(QSGTexture *texture)
m_texture.reset(texture); {
QSGSimpleTextureNode::setTexture(texture); m_texture.reset(texture);
} QSGSimpleTextureNode::setTexture(texture);
private: }
QScopedPointer<QSGTexture> m_texture; private:
QScopedPointer<QSGTexture> m_texture;
}; };
} }

View File

@ -316,7 +316,7 @@ void ToolTip::hoverEnterEvent(QHoverEvent *event)
//FIXME: showToolTip needs to be renamed in sync or something like that //FIXME: showToolTip needs to be renamed in sync or something like that
showToolTip(); showToolTip();
} else if (m_mainItem || } else if (m_mainItem ||
(!mainText().isEmpty() && !subText().isEmpty())) { (!mainText().isEmpty() && !subText().isEmpty())) {
m_showTimer->start(m_interval); m_showTimer->start(m_interval);
} }
} }

View File

@ -109,7 +109,7 @@ class ToolTip : public QQuickItem
Q_PROPERTY(bool active MEMBER m_active WRITE setActive NOTIFY activeChanged) Q_PROPERTY(bool active MEMBER m_active WRITE setActive NOTIFY activeChanged)
/** /**
* if interactive is false (default), the tooltip will automatically hide * if interactive is false (default), the tooltip will automatically hide
* itself as soon as the mouse leaves the tooltiparea, if is true, if the mouse leaves tooltiparea and goes over the tooltip itself, the tooltip won't hide, so it will be possible to interact with tooltip contents * itself as soon as the mouse leaves the tooltiparea, if is true, if the mouse leaves tooltiparea and goes over the tooltip itself, the tooltip won't hide, so it will be possible to interact with tooltip contents
*/ */
Q_PROPERTY(bool interactive MEMBER m_interactive WRITE setInteractive NOTIFY interactiveChanged) Q_PROPERTY(bool interactive MEMBER m_interactive WRITE setInteractive NOTIFY interactiveChanged)

View File

@ -47,7 +47,7 @@ ToolTipDialog::ToolTipDialog(QQuickItem *parent)
m_showTimer = new QTimer(this); m_showTimer = new QTimer(this);
m_showTimer->setSingleShot(true); m_showTimer->setSingleShot(true);
connect(m_showTimer, &QTimer::timeout, [=]() { connect(m_showTimer, &QTimer::timeout, [ = ]() {
setVisible(false); setVisible(false);
}); });
} }

View File

@ -33,7 +33,7 @@ class QPropertyAnimation;
namespace KDeclarative namespace KDeclarative
{ {
class QmlObject; class QmlObject;
} }
/** /**

View File

@ -36,7 +36,7 @@ const QString plasmarc = QStringLiteral("plasmarc");
const QString groupName = QStringLiteral("Units"); const QString groupName = QStringLiteral("Units");
const int defaultLongDuration = 250; const int defaultLongDuration = 250;
Units::Units (QObject *parent) Units::Units(QObject *parent)
: QObject(parent), : QObject(parent),
m_gridUnit(-1), m_gridUnit(-1),
m_devicePixelRatio(-1), m_devicePixelRatio(-1),
@ -194,7 +194,6 @@ void Units::updateSpacing()
} }
} }
int Units::longDuration() const int Units::longDuration() const
{ {
return m_longDuration; return m_longDuration;

View File

@ -30,18 +30,19 @@
#include <xcb/composite.h> #include <xcb/composite.h>
#if HAVE_GLX #if HAVE_GLX
#include <GL/glx.h> #include <GL/glx.h>
typedef void (*glXBindTexImageEXT_func)(Display* dpy, GLXDrawable drawable, typedef void (*glXBindTexImageEXT_func)(Display *dpy, GLXDrawable drawable,
int buffer, const int* attrib_list); int buffer, const int *attrib_list);
typedef void (*glXReleaseTexImageEXT_func)(Display* dpy, GLXDrawable drawable, int buffer); typedef void (*glXReleaseTexImageEXT_func)(Display *dpy, GLXDrawable drawable, int buffer);
#endif #endif
#if HAVE_EGL #if HAVE_EGL
typedef EGLImageKHR(*eglCreateImageKHR_func)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*); typedef EGLImageKHR(*eglCreateImageKHR_func)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint *);
typedef EGLBoolean(*eglDestroyImageKHR_func)(EGLDisplay, EGLImageKHR); typedef EGLBoolean(*eglDestroyImageKHR_func)(EGLDisplay, EGLImageKHR);
typedef GLvoid(*glEGLImageTargetTexture2DOES_func)(GLenum, GLeglImageOES); typedef GLvoid(*glEGLImageTargetTexture2DOES_func)(GLenum, GLeglImageOES);
#endif // HAVE_EGL #endif // HAVE_EGL
#endif #endif
namespace Plasma { namespace Plasma
{
WindowTextureNode::WindowTextureNode() WindowTextureNode::WindowTextureNode()
: QSGSimpleTextureNode() : QSGSimpleTextureNode()
@ -58,7 +59,7 @@ void WindowTextureNode::reset(QSGTexture *texture)
m_texture.reset(texture); m_texture.reset(texture);
} }
WindowThumbnail::WindowThumbnail(QQuickItem* parent) WindowThumbnail::WindowThumbnail(QQuickItem *parent)
: QQuickItem(parent) : QQuickItem(parent)
, QAbstractNativeEventFilter() , QAbstractNativeEventFilter()
, m_xcb(false) , m_xcb(false)
@ -80,7 +81,7 @@ WindowThumbnail::WindowThumbnail(QQuickItem* parent)
#endif #endif
{ {
setFlag(ItemHasContents); setFlag(ItemHasContents);
connect(this, &QQuickItem::windowChanged, [this](QQuickWindow *window) { connect(this, &QQuickItem::windowChanged, [this](QQuickWindow * window) {
if (!window) { if (!window) {
return; return;
} }
@ -88,7 +89,7 @@ WindowThumbnail::WindowThumbnail(QQuickItem* parent)
stopRedirecting(); stopRedirecting();
startRedirecting(); startRedirecting();
}); });
if (QGuiApplication *gui = dynamic_cast<QGuiApplication*>(QCoreApplication::instance())) { if (QGuiApplication *gui = dynamic_cast<QGuiApplication *>(QCoreApplication::instance())) {
m_xcb = (gui->platformName() == QStringLiteral("xcb")); m_xcb = (gui->platformName() == QStringLiteral("xcb"));
if (m_xcb) { if (m_xcb) {
gui->installNativeEventFilter(this); gui->installNativeEventFilter(this);
@ -141,7 +142,7 @@ void WindowThumbnail::setWinId(uint32_t winId)
QSGNode *WindowThumbnail::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) QSGNode *WindowThumbnail::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
{ {
Q_UNUSED(updatePaintNodeData) Q_UNUSED(updatePaintNodeData)
auto *node = static_cast<WindowTextureNode*>(oldNode); auto *node = static_cast<WindowTextureNode *>(oldNode);
if (!node) { if (!node) {
node = new WindowTextureNode(); node = new WindowTextureNode();
node->setFiltering(QSGTexture::Linear); node->setFiltering(QSGTexture::Linear);
@ -153,8 +154,8 @@ QSGNode *WindowThumbnail::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
} }
node->setRect(boundingRect()); node->setRect(boundingRect());
const QSize size(node->texture()->textureSize().scaled(boundingRect().size().toSize(), Qt::KeepAspectRatio)); const QSize size(node->texture()->textureSize().scaled(boundingRect().size().toSize(), Qt::KeepAspectRatio));
const qreal x = boundingRect().x() + (boundingRect().width() - size.width())/2; const qreal x = boundingRect().x() + (boundingRect().width() - size.width()) / 2;
const qreal y = boundingRect().y() + (boundingRect().height() - size.height())/2; const qreal y = boundingRect().y() + (boundingRect().height() - size.height()) / 2;
node->setRect(QRectF(QPointF(x, y), size)); node->setRect(QRectF(QPointF(x, y), size));
return node; return node;
} }
@ -167,15 +168,15 @@ bool WindowThumbnail::nativeEventFilter(const QByteArray &eventType, void *messa
return false; return false;
} }
#if HAVE_XCB_COMPOSITE #if HAVE_XCB_COMPOSITE
xcb_generic_event_t *event = static_cast<xcb_generic_event_t*>(message); xcb_generic_event_t *event = static_cast<xcb_generic_event_t *>(message);
const uint8_t responseType = event->response_type & ~0x80; const uint8_t responseType = event->response_type & ~0x80;
if (responseType == m_damageEventBase + XCB_DAMAGE_NOTIFY) { if (responseType == m_damageEventBase + XCB_DAMAGE_NOTIFY) {
if (reinterpret_cast<xcb_damage_notify_event_t*>(event)->drawable == m_winId) { if (reinterpret_cast<xcb_damage_notify_event_t *>(event)->drawable == m_winId) {
m_damaged = true; m_damaged = true;
update(); update();
} }
} else if (responseType == XCB_CONFIGURE_NOTIFY) { } else if (responseType == XCB_CONFIGURE_NOTIFY) {
if (reinterpret_cast<xcb_configure_notify_event_t*>(event)->window == m_winId) { if (reinterpret_cast<xcb_configure_notify_event_t *>(event)->window == m_winId) {
// TODO: only discard if size changes // TODO: only discard if size changes
discardPixmap(); discardPixmap();
} }
@ -253,8 +254,8 @@ bool WindowThumbnail::xcbWindowToTextureEGL(WindowTextureNode *textureNode)
EGL_NONE EGL_NONE
}; };
m_image = ((eglCreateImageKHR_func)(m_eglCreateImageKHR))(eglGetCurrentDisplay(), EGL_NO_CONTEXT, m_image = ((eglCreateImageKHR_func)(m_eglCreateImageKHR))(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
EGL_NATIVE_PIXMAP_KHR, EGL_NATIVE_PIXMAP_KHR,
(EGLClientBuffer)m_pixmap, attribs); (EGLClientBuffer)m_pixmap, attribs);
if (m_image == EGL_NO_IMAGE_KHR) { if (m_image == EGL_NO_IMAGE_KHR) {
qDebug() << "failed to create egl image"; qDebug() << "failed to create egl image";
@ -402,10 +403,11 @@ bool WindowThumbnail::loadGLXTexture()
XVisualInfo *vi = glXGetVisualFromFBConfig(d, fbConfigs[0]); XVisualInfo *vi = glXGetVisualFromFBConfig(d, fbConfigs[0]);
int textureFormat; int textureFormat;
if (window()->openglContext()->format().hasAlpha()) if (window()->openglContext()->format().hasAlpha()) {
textureFormat = bindRgba ? GLX_TEXTURE_FORMAT_RGBA_EXT : GLX_TEXTURE_FORMAT_RGB_EXT; textureFormat = bindRgba ? GLX_TEXTURE_FORMAT_RGBA_EXT : GLX_TEXTURE_FORMAT_RGB_EXT;
else } else {
textureFormat = bindRgb ? GLX_TEXTURE_FORMAT_RGB_EXT : GLX_TEXTURE_FORMAT_RGBA_EXT; textureFormat = bindRgb ? GLX_TEXTURE_FORMAT_RGB_EXT : GLX_TEXTURE_FORMAT_RGBA_EXT;
}
XFree(vi); XFree(vi);
// we assume that Texture_2D is supported as we have a QtQuick OpenGL context // we assume that Texture_2D is supported as we have a QtQuick OpenGL context

View File

@ -37,7 +37,8 @@
#endif // HAVE_XCB_COMPOSITE #endif // HAVE_XCB_COMPOSITE
class KWindowInfo; class KWindowInfo;
namespace Plasma { namespace Plasma
{
class WindowTextureNode; class WindowTextureNode;

View File

@ -19,6 +19,4 @@
#include "enums.h" #include "enums.h"
#include "moc_enums.cpp" #include "moc_enums.cpp"

View File

@ -22,7 +22,6 @@
#include <QObject> #include <QObject>
class DialogStatus : public QObject class DialogStatus : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -66,5 +65,4 @@ public:
}; };
}; };
#endif // ENUMS_H #endif // ENUMS_H

View File

@ -138,6 +138,5 @@ void FullScreenSheet::open()
} }
} }
#include "fullscreensheet.moc" #include "fullscreensheet.moc"

View File

@ -41,18 +41,17 @@
#include <Plasma/Corona> #include <Plasma/Corona>
#include <Plasma/WindowEffects> #include <Plasma/WindowEffects>
uint FullScreenWindow::s_numItems = 0; uint FullScreenWindow::s_numItems = 0;
class Background : public QWidget class Background : public QWidget
{ {
public: public:
Background(FullScreenWindow *dialog) Background(FullScreenWindow *dialog)
: QWidget( 0L ), : QWidget(0L),
m_dialog(dialog) m_dialog(dialog)
{ {
setAttribute( Qt::WA_NoSystemBackground ); setAttribute(Qt::WA_NoSystemBackground);
setAttribute( Qt::WA_TranslucentBackground ); setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::FramelessWindowHint | Qt::CustomizeWindowHint); setWindowFlags(Qt::FramelessWindowHint | Qt::CustomizeWindowHint);
KWindowSystem::setOnAllDesktops(winId(), true); KWindowSystem::setOnAllDesktops(winId(), true);
@ -63,9 +62,9 @@ public:
~Background() ~Background()
{} {}
void paintEvent( QPaintEvent *e ) void paintEvent(QPaintEvent *e)
{ {
QPainter painter( this ); QPainter painter(this);
painter.setCompositionMode(QPainter::CompositionMode_Source); painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(e->rect(), QColor(0, 0, 0, 80)); painter.fillRect(e->rect(), QColor(0, 0, 0, 80));
} }
@ -151,7 +150,7 @@ void FullScreenWindow::init(const QString &componentName)
QDeclarativeContext *creationContext = component->creationContext(); QDeclarativeContext *creationContext = component->creationContext();
m_rootObject = component->create(creationContext); m_rootObject = component->create(creationContext);
if (component->status() == QDeclarativeComponent::Error) { if (component->status() == QDeclarativeComponent::Error) {
qWarning()<<component->errors(); qWarning() << component->errors();
} }
if (m_rootObject) { if (m_rootObject) {
@ -220,8 +219,8 @@ void FullScreenWindow::syncViewToMainItem()
} }
m_declarativeItemContainer->setDeclarativeItem(di); m_declarativeItemContainer->setDeclarativeItem(di);
} else { } else {
m_mainItem.data()->setY(-10000*s_numItems); m_mainItem.data()->setY(-10000 * s_numItems);
m_mainItem.data()->setY(10000*s_numItems); m_mainItem.data()->setY(10000 * s_numItems);
} }
break; break;
} }
@ -235,7 +234,6 @@ void FullScreenWindow::syncViewToMainItem()
m_view->setScene(scene); m_view->setScene(scene);
QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()), QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()),
QSizeF(m_mainItem.data()->boundingRect().size())); QSizeF(m_mainItem.data()->boundingRect().size()));
if (m_declarativeItemContainer) { if (m_declarativeItemContainer) {
@ -244,12 +242,12 @@ void FullScreenWindow::syncViewToMainItem()
} else { } else {
QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()), QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()),
QSizeF(m_mainItem.data()->boundingRect().size())); QSizeF(m_mainItem.data()->boundingRect().size()));
m_view->resize(itemGeometry.size().toSize()); m_view->resize(itemGeometry.size().toSize());
m_view->setSceneRect(itemGeometry); m_view->setSceneRect(itemGeometry);
} }
m_view->move(QApplication::desktop()->availableGeometry().center() - QPoint(m_view->width()/2, m_view->height()/2)); m_view->move(QApplication::desktop()->availableGeometry().center() - QPoint(m_view->width() / 2, m_view->height() / 2));
} }
void FullScreenWindow::syncMainItemToView() void FullScreenWindow::syncMainItemToView()
@ -266,7 +264,7 @@ void FullScreenWindow::syncMainItemToView()
m_view->setSceneRect(m_declarativeItemContainer->geometry()); m_view->setSceneRect(m_declarativeItemContainer->geometry());
} else { } else {
QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()), QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()),
QSizeF(m_mainItem.data()->boundingRect().size())); QSizeF(m_mainItem.data()->boundingRect().size()));
m_view->setSceneRect(itemGeometry); m_view->setSceneRect(itemGeometry);
} }
} }
@ -297,7 +295,6 @@ QGraphicsView *FullScreenWindow::view() const
return m_view; return m_view;
} }
QDeclarativeListProperty<QGraphicsObject> FullScreenWindow::title() QDeclarativeListProperty<QGraphicsObject> FullScreenWindow::title()
{ {
if (m_rootObject) { if (m_rootObject) {
@ -334,7 +331,6 @@ DialogStatus::Status FullScreenWindow::status() const
} }
} }
void FullScreenWindow::statusHasChanged() void FullScreenWindow::statusHasChanged()
{ {
if (status() == DialogStatus::Closed) { if (status() == DialogStatus::Closed) {
@ -373,22 +369,17 @@ void FullScreenWindow::close()
} }
} }
bool FullScreenWindow::eventFilter(QObject *watched, QEvent *event) bool FullScreenWindow::eventFilter(QObject *watched, QEvent *event)
{ {
if (watched == m_mainItem.data() && if (watched == m_mainItem.data() &&
(event->type() == QEvent::GraphicsSceneResize)) { (event->type() == QEvent::GraphicsSceneResize)) {
syncViewToMainItem(); syncViewToMainItem();
} else if (watched == m_view && } else if (watched == m_view &&
(event->type() == QEvent::Resize)) { (event->type() == QEvent::Resize)) {
syncMainItemToView(); syncMainItemToView();
} }
return false; return false;
} }
#include "fullscreenwindow.moc" #include "fullscreenwindow.moc"

View File

@ -43,7 +43,6 @@ class FullScreenWindow : public QDeclarativeItem
Q_PROPERTY(QDeclarativeListProperty<QGraphicsObject> buttons READ buttons DESIGNABLE false) Q_PROPERTY(QDeclarativeListProperty<QGraphicsObject> buttons READ buttons DESIGNABLE false)
Q_PROPERTY(DialogStatus::Status status READ status NOTIFY statusChanged) Q_PROPERTY(DialogStatus::Status status READ status NOTIFY statusChanged)
public: public:
FullScreenWindow(QDeclarativeItem *parent = 0); FullScreenWindow(QDeclarativeItem *parent = 0);
~FullScreenWindow(); ~FullScreenWindow();
@ -73,7 +72,6 @@ Q_SIGNALS:
void clickedOutside(); void clickedOutside();
void statusChanged(); void statusChanged();
private Q_SLOTS: private Q_SLOTS:
void syncViewToMainItem(); void syncViewToMainItem();
void syncMainItemToView(); void syncMainItemToView();

View File

@ -37,7 +37,7 @@
class BKSingleton class BKSingleton
{ {
public: public:
EngineBookKeeping self; EngineBookKeeping self;
}; };
Q_GLOBAL_STATIC(BKSingleton, privateBKSelf) Q_GLOBAL_STATIC(BKSingleton, privateBKSelf)
@ -63,8 +63,8 @@ QQmlEngine *EngineBookKeeping::engine() const
void EngineBookKeeping::insertEngine(QQmlEngine *engine) void EngineBookKeeping::insertEngine(QQmlEngine *engine)
{ {
connect(engine, SIGNAL(destroyed(QObject *)), connect(engine, SIGNAL(destroyed(QObject*)),
this, SLOT(engineDestroyed(QObject *))); this, SLOT(engineDestroyed(QObject*)));
m_engines.insert(engine); m_engines.insert(engine);
} }
@ -73,8 +73,6 @@ void EngineBookKeeping::engineDestroyed(QObject *deleted)
m_engines.remove(static_cast<QQmlEngine *>(deleted)); m_engines.remove(static_cast<QQmlEngine *>(deleted));
} }
void PlasmaComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri) void PlasmaComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{ {
QQmlExtensionPlugin::initializeEngine(engine, uri); QQmlExtensionPlugin::initializeEngine(engine, uri);
@ -91,7 +89,7 @@ void PlasmaComponentsPlugin::registerTypes(const char *uri)
qmlRegisterType<QMenuProxy>(uri, 2, 0, "Menu"); qmlRegisterType<QMenuProxy>(uri, 2, 0, "Menu");
qmlRegisterType<QMenuItem>(uri, 2, 0, "MenuItem"); qmlRegisterType<QMenuItem>(uri, 2, 0, "MenuItem");
} else { } else {
// qmlRegisterType<FullScreenSheet>(uri, 2, 0, "Sheet"); // qmlRegisterType<FullScreenSheet>(uri, 2, 0, "Sheet");
} }
qmlRegisterType<Plasma::QRangeModel>(uri, 2, 0, "RangeModel"); qmlRegisterType<Plasma::QRangeModel>(uri, 2, 0, "RangeModel");
@ -101,6 +99,5 @@ void PlasmaComponentsPlugin::registerTypes(const char *uri)
qmlRegisterUncreatableType<PageStatus>(uri, 2, 0, "PageStatus", ""); qmlRegisterUncreatableType<PageStatus>(uri, 2, 0, "PageStatus", "");
} }
#include "moc_plasmacomponentsplugin.cpp" #include "moc_plasmacomponentsplugin.cpp"

View File

@ -42,7 +42,7 @@ private Q_SLOTS:
void engineDestroyed(QObject *deleted); void engineDestroyed(QObject *deleted);
private: private:
QSet <QQmlEngine*> m_engines; QSet <QQmlEngine *> m_engines;
}; };
class PlasmaComponentsPlugin : public QQmlExtensionPlugin class PlasmaComponentsPlugin : public QQmlExtensionPlugin

View File

@ -26,13 +26,13 @@
#include <QQuickItem> #include <QQuickItem>
#include "plasmacomponentsplugin.h" #include "plasmacomponentsplugin.h"
QMenuProxy::QMenuProxy (QObject *parent) QMenuProxy::QMenuProxy(QObject *parent)
: QObject(parent), : QObject(parent),
m_status(DialogStatus::Closed) m_status(DialogStatus::Closed)
{ {
m_menu = new QMenu(0); m_menu = new QMenu(0);
connect(m_menu, &QMenu::triggered, this, &QMenuProxy::itemTriggered); connect(m_menu, &QMenu::triggered, this, &QMenuProxy::itemTriggered);
connect(m_menu, &QMenu::aboutToHide, [=]() { connect(m_menu, &QMenu::aboutToHide, [ = ]() {
m_status = DialogStatus::Closed; m_status = DialogStatus::Closed;
emit statusChanged(); emit statusChanged();
}); });
@ -85,7 +85,7 @@ void QMenuProxy::setVisualParent(QObject *parent)
if (action) { if (action) {
action->setMenu(m_menu); action->setMenu(m_menu);
m_menu->clear(); m_menu->clear();
foreach(QMenuItem* item, m_items) { foreach (QMenuItem *item, m_items) {
m_menu->addAction(item->action()); m_menu->addAction(item->action());
} }
m_menu->updateGeometry(); m_menu->updateGeometry();
@ -179,8 +179,8 @@ void QMenuProxy::open(int x, int y)
{ {
qDebug() << "opening menu at " << x << y; qDebug() << "opening menu at " << x << y;
m_menu->clear(); m_menu->clear();
foreach(QMenuItem* item, m_items) { foreach (QMenuItem *item, m_items) {
qDebug() <<"Adding action: " << item->text(); qDebug() << "Adding action: " << item->text();
m_menu->addAction(item->action()); m_menu->addAction(item->action());
} }
@ -200,7 +200,6 @@ void QMenuProxy::open(int x, int y)
emit statusChanged(); emit statusChanged();
} }
void QMenuProxy::close() void QMenuProxy::close()
{ {
m_menu->hide(); m_menu->hide();

View File

@ -82,7 +82,7 @@ private Q_SLOTS:
void itemTriggered(QAction *item); void itemTriggered(QAction *item);
private: private:
QList<QMenuItem*> m_items; QList<QMenuItem *> m_items;
QMenu *m_menu; QMenu *m_menu;
DialogStatus::Status m_status; DialogStatus::Status m_status;
QWeakPointer<QObject> m_visualParent; QWeakPointer<QObject> m_visualParent;

View File

@ -20,22 +20,21 @@
#include "qmenuitem.h" #include "qmenuitem.h"
QMenuItem::QMenuItem(QQuickItem *parent) QMenuItem::QMenuItem(QQuickItem *parent)
: QQuickItem(parent), : QQuickItem(parent),
m_action(0) m_action(0)
{ {
setAction(new QAction(this)); setAction(new QAction(this));
connect(m_action, &QAction::triggered, this, &QMenuItem::clicked); connect(m_action, &QAction::triggered, this, &QMenuItem::clicked);
} }
QAction* QMenuItem::action() const QAction *QMenuItem::action() const
{ {
return m_action; return m_action;
} }
void QMenuItem::setAction(QAction* a) void QMenuItem::setAction(QAction *a)
{ {
if (m_action != a) { if (m_action != a) {
if (m_action) { if (m_action) {
@ -54,7 +53,7 @@ QVariant QMenuItem::icon() const
return m_icon; return m_icon;
} }
void QMenuItem::setIcon(const QVariant& i) void QMenuItem::setIcon(const QVariant &i)
{ {
m_icon = i; m_icon = i;
if (i.canConvert<QIcon>()) { if (i.canConvert<QIcon>()) {
@ -80,7 +79,7 @@ QString QMenuItem::text() const
return m_action->text(); return m_action->text();
} }
void QMenuItem::setText(const QString& t) void QMenuItem::setText(const QString &t)
{ {
if (m_action->text() != t) { if (m_action->text() != t) {
m_action->setText(t); m_action->setText(t);

View File

@ -39,17 +39,17 @@ class QMenuItem : public QQuickItem
Q_PROPERTY(bool separator READ separator WRITE setSeparator NOTIFY separatorChanged) Q_PROPERTY(bool separator READ separator WRITE setSeparator NOTIFY separatorChanged)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QVariant icon READ icon WRITE setIcon NOTIFY iconChanged) Q_PROPERTY(QVariant icon READ icon WRITE setIcon NOTIFY iconChanged)
Q_PROPERTY(QAction* action READ action WRITE setAction NOTIFY actionChanged) Q_PROPERTY(QAction *action READ action WRITE setAction NOTIFY actionChanged)
Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY checkableChanged) Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY checkableChanged)
Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY toggled) Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY toggled)
public: public:
QMenuItem(QQuickItem *parent = 0); QMenuItem(QQuickItem *parent = 0);
QAction* action() const; QAction *action() const;
void setAction(QAction* a); void setAction(QAction *a);
QVariant icon() const; QVariant icon() const;
void setIcon(const QVariant& i); void setIcon(const QVariant &i);
bool separator() const; bool separator() const;
void setSeparator(bool s); void setSeparator(bool s);
QString text() const; QString text() const;
@ -72,7 +72,7 @@ Q_SIGNALS:
void checkableChanged(); void checkableChanged();
private: private:
QAction* m_action; QAction *m_action;
QVariant m_icon; QVariant m_icon;
}; };

View File

@ -104,14 +104,16 @@ qreal QRangeModelPrivate::publicPosition(qreal position) const
const qreal positionValueRatio = valueRange ? (max - min) / valueRange : 0; const qreal positionValueRatio = valueRange ? (max - min) / valueRange : 0;
const qreal positionStep = stepSize * positionValueRatio; const qreal positionStep = stepSize * positionValueRatio;
if (positionStep == 0) if (positionStep == 0) {
return (min < max) ? qBound(min, position, max) : qBound(max, position, min); return (min < max) ? qBound(min, position, max) : qBound(max, position, min);
}
const int stepSizeMultiplier = (position - min) / positionStep; const int stepSizeMultiplier = (position - min) / positionStep;
// Test whether value is below minimum range // Test whether value is below minimum range
if (stepSizeMultiplier < 0) if (stepSizeMultiplier < 0) {
return min; return min;
}
qreal leftEdge = (stepSizeMultiplier * positionStep) + min; qreal leftEdge = (stepSizeMultiplier * positionStep) + min;
qreal rightEdge = ((stepSizeMultiplier + 1) * positionStep) + min; qreal rightEdge = ((stepSizeMultiplier + 1) * positionStep) + min;
@ -124,8 +126,9 @@ qreal QRangeModelPrivate::publicPosition(qreal position) const
rightEdge = qMax(rightEdge, max); rightEdge = qMax(rightEdge, max);
} }
if (qAbs(leftEdge - position) <= qAbs(rightEdge - position)) if (qAbs(leftEdge - position) <= qAbs(rightEdge - position)) {
return leftEdge; return leftEdge;
}
return rightEdge; return rightEdge;
} }
@ -143,14 +146,16 @@ qreal QRangeModelPrivate::publicValue(qreal value) const
// QML bindings; a position that is initially invalid because it lays // QML bindings; a position that is initially invalid because it lays
// outside the range, might become valid later if the range changes. // outside the range, might become valid later if the range changes.
if (stepSize == 0) if (stepSize == 0) {
return qBound(minimum, value, maximum); return qBound(minimum, value, maximum);
}
const int stepSizeMultiplier = (value - minimum) / stepSize; const int stepSizeMultiplier = (value - minimum) / stepSize;
// Test whether value is below minimum range // Test whether value is below minimum range
if (stepSizeMultiplier < 0) if (stepSizeMultiplier < 0) {
return minimum; return minimum;
}
const qreal leftEdge = qMin(maximum, (stepSizeMultiplier * stepSize) + minimum); const qreal leftEdge = qMin(maximum, (stepSizeMultiplier * stepSize) + minimum);
const qreal rightEdge = qMin(maximum, ((stepSizeMultiplier + 1) * stepSize) + minimum); const qreal rightEdge = qMin(maximum, ((stepSizeMultiplier + 1) * stepSize) + minimum);
@ -172,10 +177,12 @@ void QRangeModelPrivate::emitValueAndPositionIfChanged(const qreal oldValue, con
// unchanged. This will be the case when operating with values outside range: // unchanged. This will be the case when operating with values outside range:
const qreal newValue = q->value(); const qreal newValue = q->value();
const qreal newPosition = q->position(); const qreal newPosition = q->position();
if (!qFuzzyCompare(newValue, oldValue)) if (!qFuzzyCompare(newValue, oldValue)) {
emit q->valueChanged(newValue); emit q->valueChanged(newValue);
if (!qFuzzyCompare(newPosition, oldPosition)) }
if (!qFuzzyCompare(newPosition, oldPosition)) {
emit q->positionChanged(newPosition); emit q->positionChanged(newPosition);
}
} }
/*! /*!
@ -224,8 +231,9 @@ void QRangeModel::setPositionRange(qreal min, qreal max)
bool emitPosAtMinChanged = !qFuzzyCompare(min, d->posatmin); bool emitPosAtMinChanged = !qFuzzyCompare(min, d->posatmin);
bool emitPosAtMaxChanged = !qFuzzyCompare(max, d->posatmax); bool emitPosAtMaxChanged = !qFuzzyCompare(max, d->posatmax);
if (!(emitPosAtMinChanged || emitPosAtMaxChanged)) if (!(emitPosAtMinChanged || emitPosAtMaxChanged)) {
return; return;
}
const qreal oldPosition = position(); const qreal oldPosition = position();
d->posatmin = min; d->posatmin = min;
@ -239,10 +247,12 @@ void QRangeModel::setPositionRange(qreal min, qreal max)
// the positionChanged signal. // the positionChanged signal.
d->pos = d->equivalentPosition(d->value); d->pos = d->equivalentPosition(d->value);
if (emitPosAtMinChanged) if (emitPosAtMinChanged) {
emit positionAtMinimumChanged(d->posatmin); emit positionAtMinimumChanged(d->posatmin);
if (emitPosAtMaxChanged) }
if (emitPosAtMaxChanged) {
emit positionAtMaximumChanged(d->posatmax); emit positionAtMaximumChanged(d->posatmax);
}
d->emitValueAndPositionIfChanged(value(), oldPosition); d->emitValueAndPositionIfChanged(value(), oldPosition);
} }
@ -259,8 +269,9 @@ void QRangeModel::setRange(qreal min, qreal max)
bool emitMinimumChanged = !qFuzzyCompare(min, d->minimum); bool emitMinimumChanged = !qFuzzyCompare(min, d->minimum);
bool emitMaximumChanged = !qFuzzyCompare(max, d->maximum); bool emitMaximumChanged = !qFuzzyCompare(max, d->maximum);
if (!(emitMinimumChanged || emitMaximumChanged)) if (!(emitMinimumChanged || emitMaximumChanged)) {
return; return;
}
const qreal oldValue = value(); const qreal oldValue = value();
const qreal oldPosition = position(); const qreal oldPosition = position();
@ -271,10 +282,12 @@ void QRangeModel::setRange(qreal min, qreal max)
// Update internal position if it was changed. It can occurs if internal value changes, due to range update // Update internal position if it was changed. It can occurs if internal value changes, due to range update
d->pos = d->equivalentPosition(d->value); d->pos = d->equivalentPosition(d->value);
if (emitMinimumChanged) if (emitMinimumChanged) {
emit minimumChanged(d->minimum); emit minimumChanged(d->minimum);
if (emitMaximumChanged) }
if (emitMaximumChanged) {
emit maximumChanged(d->maximum); emit maximumChanged(d->maximum);
}
d->emitValueAndPositionIfChanged(oldValue, oldPosition); d->emitValueAndPositionIfChanged(oldValue, oldPosition);
} }
@ -332,8 +345,9 @@ void QRangeModel::setStepSize(qreal stepSize)
Q_D(QRangeModel); Q_D(QRangeModel);
stepSize = qMax(qreal(0.0), stepSize); stepSize = qMax(qreal(0.0), stepSize);
if (qFuzzyCompare(stepSize, d->stepSize)) if (qFuzzyCompare(stepSize, d->stepSize)) {
return; return;
}
const qreal oldValue = value(); const qreal oldValue = value();
const qreal oldPosition = position(); const qreal oldPosition = position();
@ -386,8 +400,9 @@ void QRangeModel::setPosition(qreal newPosition)
{ {
Q_D(QRangeModel); Q_D(QRangeModel);
if (qFuzzyCompare(newPosition, d->pos)) if (qFuzzyCompare(newPosition, d->pos)) {
return; return;
}
const qreal oldPosition = position(); const qreal oldPosition = position();
const qreal oldValue = value(); const qreal oldValue = value();
@ -473,8 +488,9 @@ void QRangeModel::setValue(qreal newValue)
{ {
Q_D(QRangeModel); Q_D(QRangeModel);
if (qFuzzyCompare(newValue, d->value)) if (qFuzzyCompare(newValue, d->value)) {
return; return;
}
const qreal oldValue = value(); const qreal oldValue = value();
const qreal oldPosition = position(); const qreal oldPosition = position();
@ -497,8 +513,9 @@ void QRangeModel::setValue(qreal newValue)
void QRangeModel::setInverted(bool inverted) void QRangeModel::setInverted(bool inverted)
{ {
Q_D(QRangeModel); Q_D(QRangeModel);
if (inverted == d->inverted) if (inverted == d->inverted) {
return; return;
}
d->inverted = inverted; d->inverted = inverted;
emit invertedChanged(d->inverted); emit invertedChanged(d->inverted);

View File

@ -113,7 +113,7 @@ Q_SIGNALS:
protected: protected:
QRangeModel(QRangeModelPrivate &dd, QObject *parent); QRangeModel(QRangeModelPrivate &dd, QObject *parent);
QRangeModelPrivate* d_ptr; QRangeModelPrivate *d_ptr;
private: private:
Q_DISABLE_COPY(QRangeModel) Q_DISABLE_COPY(QRangeModel)

View File

@ -59,29 +59,35 @@ public:
QRangeModel *q_ptr; QRangeModel *q_ptr;
inline qreal effectivePosAtMin() const { inline qreal effectivePosAtMin() const
{
return inverted ? posatmax : posatmin; return inverted ? posatmax : posatmin;
} }
inline qreal effectivePosAtMax() const { inline qreal effectivePosAtMax() const
{
return inverted ? posatmin : posatmax; return inverted ? posatmin : posatmax;
} }
inline qreal equivalentPosition(qreal value) const { inline qreal equivalentPosition(qreal value) const
{
// Return absolute position from absolute value // Return absolute position from absolute value
const qreal valueRange = maximum - minimum; const qreal valueRange = maximum - minimum;
if (valueRange == 0) if (valueRange == 0) {
return effectivePosAtMin(); return effectivePosAtMin();
}
const qreal scale = (effectivePosAtMax() - effectivePosAtMin()) / valueRange; const qreal scale = (effectivePosAtMax() - effectivePosAtMin()) / valueRange;
return (value - minimum) * scale + effectivePosAtMin(); return (value - minimum) * scale + effectivePosAtMin();
} }
inline qreal equivalentValue(qreal pos) const { inline qreal equivalentValue(qreal pos) const
{
// Return absolute value from absolute position // Return absolute value from absolute position
const qreal posRange = effectivePosAtMax() - effectivePosAtMin(); const qreal posRange = effectivePosAtMax() - effectivePosAtMin();
if (posRange == 0) if (posRange == 0) {
return minimum; return minimum;
}
const qreal scale = (maximum - minimum) / posRange; const qreal scale = (maximum - minimum) / posRange;
return (pos - effectivePosAtMin()) * scale + minimum; return (pos - effectivePosAtMin()) * scale + minimum;

View File

@ -27,7 +27,7 @@
#include <Plasma/Theme> #include <Plasma/Theme>
AppBackgroundProvider::AppBackgroundProvider() AppBackgroundProvider::AppBackgroundProvider()
: QQuickImageProvider(QQuickImageProvider::Image) : QQuickImageProvider(QQuickImageProvider::Image)
{ {
m_theme = new Plasma::Theme(); m_theme = new Plasma::Theme();
} }

View File

@ -24,7 +24,7 @@
namespace Plasma namespace Plasma
{ {
class Theme; class Theme;
} }
class AppBackgroundProvider : public QQuickImageProvider class AppBackgroundProvider : public QQuickImageProvider

View File

@ -25,7 +25,6 @@
#include <QDebug> #include <QDebug>
FallbackComponent::FallbackComponent(QObject *parent) FallbackComponent::FallbackComponent(QObject *parent)
: QObject(parent) : QObject(parent)
{ {

View File

@ -20,7 +20,6 @@
#ifndef FALLBACKCOMPONENT_H #ifndef FALLBACKCOMPONENT_H
#define FALLBACKCOMPONENT_H #define FALLBACKCOMPONENT_H
#include <QObject> #include <QObject>
#include <QCache> #include <QCache>
#include <QStringList> #include <QStringList>
@ -55,16 +54,14 @@ public:
* *
* @param key the name of the file to search for * @param key the name of the file to search for
**/ **/
Q_INVOKABLE QString filePath(const QString& key = QString()); Q_INVOKABLE QString filePath(const QString &key = QString());
QString basePath() const; QString basePath() const;
void setBasePath(const QString &basePath); void setBasePath(const QString &basePath);
QStringList candidates() const; QStringList candidates() const;
void setCandidates(const QStringList &candidates); void setCandidates(const QStringList &candidates);
Q_SIGNALS: Q_SIGNALS:
void basePathChanged(); void basePathChanged();
void candidatesChanged(); void candidatesChanged();

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2012 by Sebastian Kügler <sebas@kde.org> * Copyright 2012 by Sebastian Kügler <sebas@kde.org>
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or * published by the Free Software Foundation; either version 2, or
@ -26,7 +26,6 @@
#include <QtQml> #include <QtQml>
#include <QQmlEngine> #include <QQmlEngine>
// #include <KSharedConfig> // #include <KSharedConfig>
// #include <KConfigGroup> // #include <KConfigGroup>
@ -43,6 +42,5 @@ void PlasmaExtraComponentsPlugin::registerTypes(const char *uri)
qmlRegisterType<FallbackComponent>(uri, 2, 0, "FallbackComponent"); qmlRegisterType<FallbackComponent>(uri, 2, 0, "FallbackComponent");
} }
#include "plasmaextracomponentsplugin.moc" #include "plasmaextracomponentsplugin.moc"

View File

@ -26,7 +26,6 @@
#include <KActivities/ResourceInstance> #include <KActivities/ResourceInstance>
#include <QDebug> #include <QDebug>
ResourceInstance::ResourceInstance(QQuickItem *parent) ResourceInstance::ResourceInstance(QQuickItem *parent)
: QQuickItem(parent) : QQuickItem(parent)
{ {
@ -56,7 +55,7 @@ void ResourceInstance::syncWid()
} else { } else {
if (m_uri.scheme().startsWith(QLatin1String("http")) && !m_uri.hasQuery() && m_uri.path().endsWith('/')) { if (m_uri.scheme().startsWith(QLatin1String("http")) && !m_uri.hasQuery() && m_uri.path().endsWith('/')) {
const QString & oldPath = m_uri.path(); const QString &oldPath = m_uri.path();
m_uri.setPath(oldPath.left(oldPath.length() - 1)); m_uri.setPath(oldPath.left(oldPath.length() - 1));
// qDebug() << "Old and new path" << oldPath << m_uri; // qDebug() << "Old and new path" << oldPath << m_uri;
@ -129,7 +128,6 @@ void ResourceInstance::notifyFocusedIn()
m_resourceInstance->notifyFocusedIn(); m_resourceInstance->notifyFocusedIn();
} }
void ResourceInstance::notifyFocusedOut() void ResourceInstance::notifyFocusedOut()
{ {
//ensure the resource instance exists //ensure the resource instance exists

View File

@ -22,8 +22,9 @@
#include <QQuickItem> #include <QQuickItem>
#include <QUrl> #include <QUrl>
namespace KActivities { namespace KActivities
class ResourceInstance; {
class ResourceInstance;
} }
class QTimer; class QTimer;

View File

@ -24,13 +24,13 @@
#include <QDebug> #include <QDebug>
Application::Private::Private(Application * parent) Application::Private::Private(Application *parent)
: q(parent) : q(parent)
{ {
connect( connect(
&process, SIGNAL(stateChanged(QProcess::ProcessState)), &process, SIGNAL(stateChanged(QProcess::ProcessState)),
this, SLOT(stateChanged(QProcess::ProcessState)) this, SLOT(stateChanged(QProcess::ProcessState))
); );
process.setProcessChannelMode(QProcess::MergedChannels); process.setProcessChannelMode(QProcess::MergedChannels);
} }
@ -40,7 +40,7 @@ void Application::Private::stateChanged(QProcess::ProcessState newState)
//q->runningChanged(running); //q->runningChanged(running);
} }
Application::Application(QObject * parent) Application::Application(QObject *parent)
: QObject(parent), d(this) : QObject(parent), d(this)
{ {
} }
@ -60,7 +60,7 @@ QString Application::application() const
return d->application; return d->application;
} }
void Application::setApplication(const QString & application) void Application::setApplication(const QString &application)
{ {
qDebug() << "setting the application to" << application; qDebug() << "setting the application to" << application;
@ -87,10 +87,11 @@ void Application::setRunning(bool run)
qDebug() << "running?" << run; qDebug() << "running?" << run;
d->running = run; d->running = run;
if (run) if (run) {
start(); start();
else } else {
terminate(); terminate();
}
} }
void Application::start() void Application::start()
@ -107,7 +108,7 @@ void Application::start()
qDebug() << "Starting" << d->application; qDebug() << "Starting" << d->application;
d->process.start(d->application); d->process.start(d->application);
if(!d->process.waitForStarted()) { if (!d->process.waitForStarted()) {
qWarning() << "Error" << d->process.error() << "while starting" << d->application; qWarning() << "Error" << d->process.error() << "while starting" << d->application;
} }

View File

@ -36,7 +36,8 @@
* } * }
* </code> * </code>
*/ */
class Application: public QObject { class Application: public QObject
{
Q_OBJECT Q_OBJECT
/** /**
@ -51,14 +52,14 @@ class Application: public QObject {
Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged); Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged);
public: public:
Application(QObject * parent = Q_NULLPTR); Application(QObject *parent = Q_NULLPTR);
~Application(); ~Application();
QString application() const; QString application() const;
bool running() const; bool running() const;
public: public:
void setApplication(const QString & application); void setApplication(const QString &application);
void setRunning(bool run); void setRunning(bool run);
public Q_SLOTS: public Q_SLOTS:
@ -66,7 +67,7 @@ public Q_SLOTS:
void terminate(); void terminate();
Q_SIGNALS: Q_SIGNALS:
void applicationChanged(const QString & application); void applicationChanged(const QString &application);
void runningChanged(bool running); void runningChanged(bool running);
private: private:

View File

@ -24,7 +24,8 @@
#include <QProcess> #include <QProcess>
class Application::Private: public QObject { class Application::Private: public QObject
{
Q_OBJECT Q_OBJECT
public: public:
Private(Application *); Private(Application *);
@ -37,7 +38,7 @@ private Q_SLOTS:
void stateChanged(QProcess::ProcessState newState); void stateChanged(QProcess::ProcessState newState);
private: private:
Application * const q; Application *const q;
}; };
#endif /* APPLICATION_P_H */ #endif /* APPLICATION_P_H */

View File

@ -31,13 +31,14 @@
/** /**
* *
*/ */
class IconDialog::Private { class IconDialog::Private
{
public: public:
utils::SharedSingleton<KIconDialog> dialog; utils::SharedSingleton<KIconDialog> dialog;
}; };
IconDialog::IconDialog(QObject * parent) IconDialog::IconDialog(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
} }

View File

@ -39,11 +39,12 @@
* icon = iconDialog.openDialog() * icon = iconDialog.openDialog()
* </code> * </code>
*/ */
class IconDialog: public QObject { class IconDialog: public QObject
{
Q_OBJECT Q_OBJECT
public: public:
IconDialog(QObject * parent = Q_NULLPTR); IconDialog(QObject *parent = Q_NULLPTR);
~IconDialog(); ~IconDialog();
Q_INVOKABLE QString openDialog(); Q_INVOKABLE QString openDialog();

View File

@ -24,25 +24,25 @@
#include "application.h" #include "application.h"
#include "icondialog.h" #include "icondialog.h"
class PlatformComponentsPlugin: public QQmlExtensionPlugin { class PlatformComponentsPlugin: public QQmlExtensionPlugin
{
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kde.plasma.platformcomponents") Q_PLUGIN_METADATA(IID "org.kde.plasma.platformcomponents")
public: public:
PlatformComponentsPlugin(QObject * parent = Q_NULLPTR) PlatformComponentsPlugin(QObject *parent = Q_NULLPTR)
: QQmlExtensionPlugin(parent) : QQmlExtensionPlugin(parent)
{ {
qDebug() << "instantiated plugin object"; qDebug() << "instantiated plugin object";
} }
void registerTypes(const char * uri) Q_DECL_OVERRIDE void registerTypes(const char *uri) Q_DECL_OVERRIDE {
{
qDebug() << "plugin loaded, registering types " << uri; qDebug() << "plugin loaded, registering types " << uri;
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.platformcomponents")); Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.platformcomponents"));
qmlRegisterType<Application> (uri, 2, 0, "Application"); qmlRegisterType<Application> (uri, 2, 0, "Application");
qmlRegisterType<IconDialog> (uri, 2, 0, "IconDialog"); qmlRegisterType<IconDialog> (uri, 2, 0, "IconDialog");
} }
}; };

View File

@ -22,10 +22,12 @@
#include <memory> #include <memory>
namespace utils { namespace utils
{
template <typename T> template <typename T>
class d_ptr { class d_ptr
{
private: private:
std::unique_ptr<T> d; std::unique_ptr<T> d;
@ -33,18 +35,18 @@ public:
d_ptr(); d_ptr();
template <typename ...Args> template <typename ...Args>
d_ptr(Args && ...); d_ptr(Args &&...);
~d_ptr(); ~d_ptr();
T * operator->() const; T *operator->() const;
}; };
#define D_PTR \ #define D_PTR \
class Private; \ class Private; \
friend class Private; \ friend class Private; \
const ::utils::d_ptr<Private> d \ const ::utils::d_ptr<Private> d \
} // namespace utils } // namespace utils
#endif #endif

View File

@ -22,7 +22,8 @@
#include <utility> #include <utility>
namespace utils { namespace utils
{
template <typename T> template <typename T>
d_ptr<T>::d_ptr() : d(new T()) d_ptr<T>::d_ptr() : d(new T())
@ -31,8 +32,8 @@ d_ptr<T>::d_ptr() : d(new T())
template <typename T> template <typename T>
template <typename ...Args> template <typename ...Args>
d_ptr<T>::d_ptr(Args && ... args) d_ptr<T>::d_ptr(Args &&... args)
: d(new T(std::forward<Args>(args)... )) : d(new T(std::forward<Args>(args)...))
{ {
} }
@ -42,7 +43,7 @@ d_ptr<T>::~d_ptr()
} }
template<typename T> template<typename T>
T * d_ptr<T>::operator->() const T *d_ptr<T>::operator->() const
{ {
return d.get(); return d.get();
} }

View File

@ -22,10 +22,12 @@
#include <memory> #include <memory>
namespace utils { namespace utils
{
template <typename Target> template <typename Target>
class SharedSingleton { class SharedSingleton
{
public: public:
static std::shared_ptr<Target> instance() static std::shared_ptr<Target> instance()
{ {

View File

@ -88,14 +88,14 @@ PlasmaKPart::~PlasmaKPart()
void PlasmaKPart::setThemeDefaults() void PlasmaKPart::setThemeDefaults()
{ {
KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "Theme-plasma-kpart" ); KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "Theme-plasma-kpart");
const QString themeName = cg.readEntry("name", "appdashboard"); const QString themeName = cg.readEntry("name", "appdashboard");
Plasma::Theme::defaultTheme()->setUseGlobalSettings(false); Plasma::Theme::defaultTheme()->setUseGlobalSettings(false);
Plasma::Theme::defaultTheme()->setThemeName(themeName); Plasma::Theme::defaultTheme()->setThemeName(themeName);
cg = KConfigGroup(KSharedConfig::openConfig(), "General"); cg = KConfigGroup(KSharedConfig::openConfig(), "General");
Plasma::Theme::defaultTheme()->setFont(cg.readEntry("desktopFont", QFont("Sans") )); Plasma::Theme::defaultTheme()->setFont(cg.readEntry("desktopFont", QFont("Sans")));
} }
void PlasmaKPart::syncConfig() void PlasmaKPart::syncConfig()
@ -119,7 +119,7 @@ void PlasmaKPart::initCorona()
m_view->show(); m_view->show();
} }
PlasmaKPartCorona* PlasmaKPart::corona() const PlasmaKPartCorona *PlasmaKPart::corona() const
{ {
Q_ASSERT(m_corona); Q_ASSERT(m_corona);
return m_corona; return m_corona;
@ -131,7 +131,7 @@ void PlasmaKPart::createView(Plasma::Containment *containment)
m_view->setContainment(containment); m_view->setContainment(containment);
} }
void PlasmaKPart::addApplet(const QString& name, const QVariantList& args, const QRectF& geometry ) void PlasmaKPart::addApplet(const QString &name, const QVariantList &args, const QRectF &geometry)
{ {
Q_ASSERT(containment()); Q_ASSERT(containment());
containment()->createApplet(name, args, geometry); containment()->createApplet(name, args, geometry);
@ -155,7 +155,7 @@ void PlasmaKPart::setConfigFile(const QString &file)
} }
} }
Plasma::Containment* PlasmaKPart::containment() const Plasma::Containment *PlasmaKPart::containment() const
{ {
Q_ASSERT(corona()); Q_ASSERT(corona());
Q_ASSERT(!corona()->containments().isEmpty()); Q_ASSERT(!corona()->containments().isEmpty());

View File

@ -30,8 +30,8 @@ class PlasmaKPartCorona;
Q_DECLARE_METATYPE(Plasma::Containment *) Q_DECLARE_METATYPE(Plasma::Containment *)
namespace Plasma namespace Plasma
{ {
class Applet; class Applet;
class PluginLoader; class PluginLoader;
} }
#include <KDE/KParts/Part> #include <KDE/KParts/Part>
@ -85,14 +85,14 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void initCorona(); void initCorona();
void syncConfig(); void syncConfig();
void createView(Plasma::Containment* containment); void createView(Plasma::Containment *containment);
void setThemeDefaults(); void setThemeDefaults();
private: private:
PlasmaKPartCorona* m_corona; PlasmaKPartCorona *m_corona;
PlasmaKPartView* m_view; PlasmaKPartView *m_view;
QHash<QString,Plasma::Applet*>* m_appletList; QHash<QString, Plasma::Applet *> *m_appletList;
QVBoxLayout* m_configLayout; QVBoxLayout *m_configLayout;
QString m_configFile; QString m_configFile;
}; };

View File

@ -2,7 +2,7 @@
* Copyright 2008 Aaron Seigo <aseigo@kde.org> * Copyright 2008 Aaron Seigo <aseigo@kde.org>
* Copyright 2010 Ryan Rix <ry@n.rix.si> * Copyright 2010 Ryan Rix <ry@n.rix.si>
* Copyright 2010 Siddharth Sharma <siddharth.kde@gmail.com> * Copyright 2010 Siddharth Sharma <siddharth.kde@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or * published by the Free Software Foundation; either version 2, or
@ -61,7 +61,7 @@ void PlasmaKPartCorona::evaluateScripts(const QStringList &scripts)
connect(&scriptEngine, SIGNAL(print(QString)), this, SLOT(printScriptMessage(QString))); connect(&scriptEngine, SIGNAL(print(QString)), this, SLOT(printScriptMessage(QString)));
QFile file(script); QFile file(script);
if (file.open(QIODevice::ReadOnly | QIODevice::Text) ) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QString code = file.readAll(); QString code = file.readAll();
// qDebug() << "evaluating startup script:" << script; // qDebug() << "evaluating startup script:" << script;
scriptEngine.evaluateScript(code); scriptEngine.evaluateScript(code);

View File

@ -26,7 +26,7 @@
namespace Plasma namespace Plasma
{ {
class Applet; class Applet;
} // namespace Plasma } // namespace Plasma
/** /**
@ -34,9 +34,9 @@ namespace Plasma
*/ */
class PlasmaKPartCorona : public Plasma::Corona class PlasmaKPartCorona : public Plasma::Corona
{ {
Q_OBJECT Q_OBJECT
public: public:
PlasmaKPartCorona(QObject* parent); PlasmaKPartCorona(QObject *parent);
protected: protected:
void loadDefaultLayout(); void loadDefaultLayout();

View File

@ -26,7 +26,7 @@
#include <Plasma/Applet> #include <Plasma/Applet>
#include <Plasma/Containment> #include <Plasma/Containment>
PlasmaKPartView::PlasmaKPartView(Plasma::Containment* containment, int uid, QWidget* parent) PlasmaKPartView::PlasmaKPartView(Plasma::Containment *containment, int uid, QWidget *parent)
: Plasma::View(containment, uid, parent), : Plasma::View(containment, uid, parent),
m_configurationMode(false) m_configurationMode(false)
{ {
@ -41,7 +41,7 @@ PlasmaKPartView::~PlasmaKPartView()
{ {
} }
void PlasmaKPartView::connectContainment(Plasma::Containment* containment) void PlasmaKPartView::connectContainment(Plasma::Containment *containment)
{ {
if (!containment) { if (!containment) {
return; return;
@ -51,7 +51,7 @@ void PlasmaKPartView::connectContainment(Plasma::Containment* containment)
connect(containment, SIGNAL(toolBoxVisibilityChanged(bool)), this, SLOT(updateConfigurationMode(bool))); connect(containment, SIGNAL(toolBoxVisibilityChanged(bool)), this, SLOT(updateConfigurationMode(bool)));
} }
void PlasmaKPartView::setContainment(Plasma::Containment* c) void PlasmaKPartView::setContainment(Plasma::Containment *c)
{ {
if (containment()) { if (containment()) {
disconnect(containment(), 0, this, 0); disconnect(containment(), 0, this, 0);
@ -71,7 +71,7 @@ void PlasmaKPartView::resizeEvent(QResizeEvent *event)
void PlasmaKPartView::updateGeometry() void PlasmaKPartView::updateGeometry()
{ {
Plasma::Containment* c = containment(); Plasma::Containment *c = containment();
if (!c) { if (!c) {
return; return;
} }
@ -85,5 +85,4 @@ void PlasmaKPartView::updateGeometry()
} }
} }
#include "plasmakpartview.moc" #include "plasmakpartview.moc"

View File

@ -27,12 +27,12 @@
namespace Plasma namespace Plasma
{ {
class Containment; class Containment;
} // namespace Plasma } // namespace Plasma
class PlasmaKPartView : public Plasma::View class PlasmaKPartView : public Plasma::View
{ {
Q_OBJECT Q_OBJECT
public: public:
typedef Plasma::Types::ImmutabilityType ImmutabilityType; typedef Plasma::Types::ImmutabilityType ImmutabilityType;
PlasmaKPartView(Plasma::Containment *containment, int uid, QWidget *parent = 0); PlasmaKPartView(Plasma::Containment *containment, int uid, QWidget *parent = 0);
@ -55,7 +55,7 @@ Q_SIGNALS:
void geometryChanged(); void geometryChanged();
protected: protected:
void resizeEvent( QResizeEvent* event ); void resizeEvent(QResizeEvent *event);
private: private:
bool m_configurationMode; bool m_configurationMode;

View File

@ -28,7 +28,7 @@
** functionality provided by Qt Designer and its related libraries. ** functionality provided by Qt Designer and its related libraries.
** **
** Trolltech reserves all rights not expressly granted herein. ** Trolltech reserves all rights not expressly granted herein.
** **
** Trolltech ASA (c) 2007 ** Trolltech ASA (c) 2007
** **
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
@ -45,21 +45,19 @@
Class* self = qscriptvalue_cast<Class*>(ctx->thisObject()); \ Class* self = qscriptvalue_cast<Class*>(ctx->thisObject()); \
if (!self) { \ if (!self) { \
return ctx->throwError(QScriptContext::TypeError, \ return ctx->throwError(QScriptContext::TypeError, \
QString::fromLatin1("%0.prototype.%1: this object is not a %0") \ QString::fromLatin1("%0.prototype.%1: this object is not a %0") \
.arg(#Class).arg(#__fn__)); \ .arg(#Class).arg(#__fn__)); \
} }
#define DECLARE_SELF2(Class, __fn__, __ret__) \ #define DECLARE_SELF2(Class, __fn__, __ret__) \
Class* self = qscriptvalue_cast<Class*>(thisObject()); \ Class* self = qscriptvalue_cast<Class*>(thisObject()); \
if (!self) { \ if (!self) { \
context()->throwError(QScriptContext::TypeError, \ context()->throwError(QScriptContext::TypeError, \
QString::fromLatin1("%0.prototype.%1: this object is not a %0") \ QString::fromLatin1("%0.prototype.%1: this object is not a %0") \
.arg(#Class).arg(#__fn__)); \ .arg(#Class).arg(#__fn__)); \
return __ret__; \ return __ret__; \
} }
#define ADD_METHOD(__p__, __f__) \ #define ADD_METHOD(__p__, __f__) \
__p__.setProperty(#__f__, __p__.engine()->newFunction(__f__)) __p__.setProperty(#__f__, __p__.engine()->newFunction(__f__))
@ -67,53 +65,49 @@
ADD_METHOD(__p__, __get__) ADD_METHOD(__p__, __get__)
#define ADD_GET_SET_METHODS(__p__, __get__, __set__) \ #define ADD_GET_SET_METHODS(__p__, __get__, __set__) \
do { \ do { \
ADD_METHOD(__p__, __get__); \ ADD_METHOD(__p__, __get__); \
ADD_METHOD(__p__, __set__); \ ADD_METHOD(__p__, __set__); \
} while (0); } while (0);
#define ADD_CTOR_FUNCTION(__c__, __f__) ADD_METHOD(__c__, __f__) #define ADD_CTOR_FUNCTION(__c__, __f__) ADD_METHOD(__c__, __f__)
#define ADD_ENUM_VALUE(__c__, __ns__, __v__) \ #define ADD_ENUM_VALUE(__c__, __ns__, __v__) \
__c__.setProperty(#__v__, QScriptValue(__c__.engine(), __ns__::__v__)) __c__.setProperty(#__v__, QScriptValue(__c__.engine(), __ns__::__v__))
#define BEGIN_DECLARE_METHOD(Class, __mtd__) \ #define BEGIN_DECLARE_METHOD(Class, __mtd__) \
static QScriptValue __mtd__(QScriptContext *ctx, QScriptEngine *eng) \ static QScriptValue __mtd__(QScriptContext *ctx, QScriptEngine *eng) \
{ \ { \
DECLARE_SELF(Class, __mtd__); DECLARE_SELF(Class, __mtd__);
#define END_DECLARE_METHOD \ #define END_DECLARE_METHOD \
} }
#define DECLARE_GET_METHOD(Class, __get__) \ #define DECLARE_GET_METHOD(Class, __get__) \
BEGIN_DECLARE_METHOD(Class, __get__) { \ BEGIN_DECLARE_METHOD(Class, __get__) { \
return qScriptValueFromValue(eng, self->__get__()); \ return qScriptValueFromValue(eng, self->__get__()); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_SET_METHOD(Class, T, __set__) \ #define DECLARE_SET_METHOD(Class, T, __set__) \
BEGIN_DECLARE_METHOD(Class, __set__) { \ BEGIN_DECLARE_METHOD(Class, __set__) { \
self->__set__(qscriptvalue_cast<T>(ctx->argument(0))); \ self->__set__(qscriptvalue_cast<T>(ctx->argument(0))); \
return eng->undefinedValue(); \ return eng->undefinedValue(); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_GET_SET_METHODS(Class, T, __get__, __set__) \ #define DECLARE_GET_SET_METHODS(Class, T, __get__, __set__) \
DECLARE_GET_METHOD(Class, /*T,*/ __get__) \ DECLARE_GET_METHOD(Class, /*T,*/ __get__) \
DECLARE_SET_METHOD(Class, T, __set__) DECLARE_SET_METHOD(Class, T, __set__)
#define DECLARE_SIMPLE_GET_METHOD(Class, __get__) \ #define DECLARE_SIMPLE_GET_METHOD(Class, __get__) \
BEGIN_DECLARE_METHOD(Class, __get__) { \ BEGIN_DECLARE_METHOD(Class, __get__) { \
return QScriptValue(eng, self->__get__()); \ return QScriptValue(eng, self->__get__()); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_SIMPLE_SET_METHOD(Class, ToType, __set__) \ #define DECLARE_SIMPLE_SET_METHOD(Class, ToType, __set__) \
BEGIN_DECLARE_METHOD(Class, __set__) { \ BEGIN_DECLARE_METHOD(Class, __set__) { \
self->__set__(ctx->argument(0).ToType()); \ self->__set__(ctx->argument(0).ToType()); \
return eng->undefinedValue(); \ return eng->undefinedValue(); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_BOOLEAN_GET_METHOD(Class, __set__) \ #define DECLARE_BOOLEAN_GET_METHOD(Class, __set__) \
DECLARE_SIMPLE_GET_METHOD(Class, __set__) DECLARE_SIMPLE_GET_METHOD(Class, __set__)
@ -136,9 +130,9 @@ BEGIN_DECLARE_METHOD(Class, __set__) { \
DECLARE_SIMPLE_SET_METHOD(Class, toString, __set__) DECLARE_SIMPLE_SET_METHOD(Class, toString, __set__)
#define DECLARE_QOBJECT_GET_METHOD(Class, __get__) \ #define DECLARE_QOBJECT_GET_METHOD(Class, __get__) \
BEGIN_DECLARE_METHOD(Class, __get__) { \ BEGIN_DECLARE_METHOD(Class, __get__) { \
return eng->newQObject(self->__get__()); \ return eng->newQObject(self->__get__()); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_QOBJECT_SET_METHOD(Class, __set__) \ #define DECLARE_QOBJECT_SET_METHOD(Class, __set__) \
DECLARE_SIMPLE_SET_METHOD(Class, toQObject, __set__) DECLARE_SIMPLE_SET_METHOD(Class, toQObject, __set__)
@ -162,42 +156,40 @@ BEGIN_DECLARE_METHOD(Class, __get__) { \
DECLARE_QOBJECT_GET_METHOD(Class, __get__) \ DECLARE_QOBJECT_GET_METHOD(Class, __get__) \
DECLARE_QOBJECT_SET_METHOD(Class, __set__) DECLARE_QOBJECT_SET_METHOD(Class, __set__)
#define DECLARE_VOID_METHOD(Class, __fun__) \ #define DECLARE_VOID_METHOD(Class, __fun__) \
BEGIN_DECLARE_METHOD(Class, __fun__) { \ BEGIN_DECLARE_METHOD(Class, __fun__) { \
self->__fun__(); \ self->__fun__(); \
return eng->undefinedValue(); \ return eng->undefinedValue(); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_VOID_NUMBER_METHOD(Class, __fun__) \ #define DECLARE_VOID_NUMBER_METHOD(Class, __fun__) \
BEGIN_DECLARE_METHOD(Class, __fun__) { \ BEGIN_DECLARE_METHOD(Class, __fun__) { \
self->__fun__(ctx->argument(0).toNumber()); \ self->__fun__(ctx->argument(0).toNumber()); \
return eng->undefinedValue(); \ return eng->undefinedValue(); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_VOID_NUMBER_NUMBER_METHOD(Class, __fun__) \ #define DECLARE_VOID_NUMBER_NUMBER_METHOD(Class, __fun__) \
BEGIN_DECLARE_METHOD(Class, __fun__) { \ BEGIN_DECLARE_METHOD(Class, __fun__) { \
self->__fun__(ctx->argument(0).toNumber(), ctx->argument(1).toNumber()); \ self->__fun__(ctx->argument(0).toNumber(), ctx->argument(1).toNumber()); \
return eng->undefinedValue(); \ return eng->undefinedValue(); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_VOID_QUAD_NUMBER_METHOD(Class, __fun__) \ #define DECLARE_VOID_QUAD_NUMBER_METHOD(Class, __fun__) \
BEGIN_DECLARE_METHOD(Class, __fun__) { \ BEGIN_DECLARE_METHOD(Class, __fun__) { \
self->__fun__(ctx->argument(0).toNumber(), ctx->argument(1).toNumber(), ctx->argument(2).toNumber(), ctx->argument(3).toNumber()); \ self->__fun__(ctx->argument(0).toNumber(), ctx->argument(1).toNumber(), ctx->argument(2).toNumber(), ctx->argument(3).toNumber()); \
return eng->undefinedValue(); \ return eng->undefinedValue(); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_VOID_1ARG_METHOD(Class, ArgType, __fun__) \ #define DECLARE_VOID_1ARG_METHOD(Class, ArgType, __fun__) \
BEGIN_DECLARE_METHOD(Class, __fun__) { \ BEGIN_DECLARE_METHOD(Class, __fun__) { \
self->__fun__(qscriptvalue_cast<ArgType>(ctx->argument(0))); \ self->__fun__(qscriptvalue_cast<ArgType>(ctx->argument(0))); \
return eng->undefinedValue(); \ return eng->undefinedValue(); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_BOOLEAN_1ARG_METHOD(Class, ArgType, __fun__) \ #define DECLARE_BOOLEAN_1ARG_METHOD(Class, ArgType, __fun__) \
BEGIN_DECLARE_METHOD(Class, __fun__) { \ BEGIN_DECLARE_METHOD(Class, __fun__) { \
return QScriptValue(eng, self->__fun__(qscriptvalue_cast<ArgType>(ctx->argument(0)))); \ return QScriptValue(eng, self->__fun__(qscriptvalue_cast<ArgType>(ctx->argument(0)))); \
} END_DECLARE_METHOD } END_DECLARE_METHOD
#define DECLARE_POINTER_METATYPE(T) \ #define DECLARE_POINTER_METATYPE(T) \
Q_DECLARE_METATYPE(T*) \ Q_DECLARE_METATYPE(T*) \
@ -214,21 +206,22 @@ template <typename T>
class Pointer : public QSharedData class Pointer : public QSharedData
{ {
public: public:
typedef T* pointer_type; typedef T *pointer_type;
typedef QExplicitlySharedDataPointer<Pointer<T> > wrapped_pointer_type; typedef QExplicitlySharedDataPointer<Pointer<T> > wrapped_pointer_type;
~Pointer() ~Pointer()
{ {
if (!(m_flags & UserOwnership)) if (!(m_flags & UserOwnership)) {
delete m_value; delete m_value;
}
} }
operator T*() operator T *()
{ {
return m_value; return m_value;
} }
operator const T*() const operator const T *() const
{ {
return m_value; return m_value;
} }
@ -238,25 +231,26 @@ public:
return wrapped_pointer_type(new Pointer(value, flags)); return wrapped_pointer_type(new Pointer(value, flags));
} }
static QScriptValue toScriptValue(QScriptEngine *engine, T* const &source) static QScriptValue toScriptValue(QScriptEngine *engine, T *const &source)
{ {
if (!source) if (!source) {
return engine->nullValue(); return engine->nullValue();
}
return engine->newVariant(qVariantFromValue(source)); return engine->newVariant(qVariantFromValue(source));
} }
static void fromScriptValue(const QScriptValue &value, T* &target) static void fromScriptValue(const QScriptValue &value, T *&target)
{ {
if (value.isVariant()) { if (value.isVariant()) {
QVariant var = value.toVariant(); QVariant var = value.toVariant();
if (qVariantCanConvert<T*>(var)) { if (qVariantCanConvert<T *>(var)) {
target = qvariant_cast<T*>(var); target = qvariant_cast<T *>(var);
} else if (qVariantCanConvert<wrapped_pointer_type>(var)) { } else if (qVariantCanConvert<wrapped_pointer_type>(var)) {
target = qvariant_cast<wrapped_pointer_type>(var)->operator T*(); target = qvariant_cast<wrapped_pointer_type>(var)->operator T * ();
} else { } else {
// look in prototype chain // look in prototype chain
target = 0; target = 0;
int type = qMetaTypeId<T*>(); int type = qMetaTypeId<T *>();
int pointerType = qMetaTypeId<wrapped_pointer_type>(); int pointerType = qMetaTypeId<wrapped_pointer_type>();
QScriptValue proto = value.prototype(); QScriptValue proto = value.prototype();
while (proto.isObject() && proto.isVariant()) { while (proto.isObject() && proto.isVariant()) {
@ -264,10 +258,10 @@ public:
if ((type == protoType) || (pointerType == protoType)) { if ((type == protoType) || (pointerType == protoType)) {
QByteArray name = QMetaType::typeName(var.userType()); QByteArray name = QMetaType::typeName(var.userType());
if (name.startsWith("QScript::Pointer<")) { if (name.startsWith("QScript::Pointer<")) {
target = (*reinterpret_cast<wrapped_pointer_type*>(var.data()))->operator T*(); target = (*reinterpret_cast<wrapped_pointer_type *>(var.data()))->operator T * ();
break; break;
} else { } else {
target = static_cast<T*>(var.data()); target = static_cast<T *>(var.data());
break; break;
} }
} }
@ -276,28 +270,34 @@ public:
} }
} else if (value.isQObject()) { } else if (value.isQObject()) {
QObject *qobj = value.toQObject(); QObject *qobj = value.toQObject();
QByteArray typeName = QMetaType::typeName(qMetaTypeId<T*>()); QByteArray typeName = QMetaType::typeName(qMetaTypeId<T *>());
target = reinterpret_cast<T*>(qobj->qt_metacast(typeName.left(typeName.size()-1))); target = reinterpret_cast<T *>(qobj->qt_metacast(typeName.left(typeName.size() - 1)));
} else { } else {
target = 0; target = 0;
} }
} }
uint flags() const uint flags() const
{ return m_flags; } {
return m_flags;
}
void setFlags(uint flags) void setFlags(uint flags)
{ m_flags = flags; } {
m_flags = flags;
}
void unsetFlags(uint flags) void unsetFlags(uint flags)
{ m_flags &= ~flags; } {
m_flags &= ~flags;
}
protected: protected:
Pointer(T* value, uint flags) Pointer(T *value, uint flags)
: m_flags(flags), m_value(value) : m_flags(flags), m_value(value)
{} {}
private: private:
uint m_flags; uint m_flags;
T* m_value; T *m_value;
}; };
template <typename T> template <typename T>
@ -307,9 +307,9 @@ int registerPointerMetaType(
T * /* dummy */ = 0 T * /* dummy */ = 0
) )
{ {
QScriptValue (*mf)(QScriptEngine *, T* const &) = Pointer<T>::toScriptValue; QScriptValue(*mf)(QScriptEngine *, T * const &) = Pointer<T>::toScriptValue;
void (*df)(const QScriptValue &, T* &) = Pointer<T>::fromScriptValue; void (*df)(const QScriptValue &, T *&) = Pointer<T>::fromScriptValue;
const int id = qMetaTypeId<T*>(); const int id = qMetaTypeId<T *>();
qScriptRegisterMetaType_helper( qScriptRegisterMetaType_helper(
eng, id, reinterpret_cast<QScriptEngine::MarshalFunction>(mf), eng, id, reinterpret_cast<QScriptEngine::MarshalFunction>(mf),
reinterpret_cast<QScriptEngine::DemarshalFunction>(df), reinterpret_cast<QScriptEngine::DemarshalFunction>(df),
@ -323,8 +323,9 @@ inline void maybeReleaseOwnership(const QScriptValue &value)
if (value.isVariant()) { if (value.isVariant()) {
QVariant var = value.toVariant(); QVariant var = value.toVariant();
QByteArray name = QMetaType::typeName(var.userType()); QByteArray name = QMetaType::typeName(var.userType());
if (name.startsWith("QScript::Pointer<")) if (name.startsWith("QScript::Pointer<")) {
(*reinterpret_cast<Pointer<void*>::wrapped_pointer_type *>(var.data()))->setFlags(UserOwnership); (*reinterpret_cast<Pointer<void *>::wrapped_pointer_type *>(var.data()))->setFlags(UserOwnership);
}
} }
} }
@ -333,8 +334,9 @@ inline void maybeTakeOwnership(const QScriptValue &value)
if (value.isVariant()) { if (value.isVariant()) {
QVariant var = value.toVariant(); QVariant var = value.toVariant();
QByteArray name = QMetaType::typeName(var.userType()); QByteArray name = QMetaType::typeName(var.userType());
if (name.startsWith("QScript::Pointer<")) if (name.startsWith("QScript::Pointer<")) {
(*reinterpret_cast<Pointer<void*>::wrapped_pointer_type *>(var.data()))->unsetFlags(UserOwnership); (*reinterpret_cast<Pointer<void *>::wrapped_pointer_type *>(var.data()))->unsetFlags(UserOwnership);
}
} }
} }
@ -348,7 +350,8 @@ inline QScriptValue wrapPointer(QScriptEngine *eng, T *ptr, uint flags = 0)
#ifdef QGRAPHICSITEM_H #ifdef QGRAPHICSITEM_H
namespace QScript { namespace QScript
{
template <class T> template <class T>
inline QScriptValue wrapGVPointer(QScriptEngine *eng, T *item) inline QScriptValue wrapGVPointer(QScriptEngine *eng, T *item)

View File

@ -19,13 +19,12 @@
#include <QtCore/QRectF> #include <QtCore/QRectF>
#include "backportglobal.h" #include "backportglobal.h"
Q_DECLARE_METATYPE(QRectF*) Q_DECLARE_METATYPE(QRectF *)
Q_DECLARE_METATYPE(QRectF) Q_DECLARE_METATYPE(QRectF)
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
{ {
if (ctx->argumentCount() == 4) if (ctx->argumentCount() == 4) {
{
qreal x = ctx->argument(0).toNumber(); qreal x = ctx->argument(0).toNumber();
qreal y = ctx->argument(1).toNumber(); qreal y = ctx->argument(1).toNumber();
qreal width = ctx->argument(2).toNumber(); qreal width = ctx->argument(2).toNumber();
@ -158,7 +157,6 @@ static QScriptValue moveRight(QScriptContext *ctx, QScriptEngine *)
return QScriptValue(); return QScriptValue();
} }
static QScriptValue moveTo(QScriptContext *ctx, QScriptEngine *) static QScriptValue moveTo(QScriptContext *ctx, QScriptEngine *)
{ {
DECLARE_SELF(QRectF, moveTo); DECLARE_SELF(QRectF, moveTo);
@ -321,7 +319,7 @@ QScriptValue constructQRectFClass(QScriptEngine *eng)
proto.setProperty("y", eng->newFunction(y), getter | setter); proto.setProperty("y", eng->newFunction(y), getter | setter);
eng->setDefaultPrototype(qMetaTypeId<QRectF>(), proto); eng->setDefaultPrototype(qMetaTypeId<QRectF>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QRectF*>(), proto); eng->setDefaultPrototype(qMetaTypeId<QRectF *>(), proto);
return eng->newFunction(ctor, proto); return eng->newFunction(ctor, proto);
} }

View File

@ -134,7 +134,7 @@ QScriptValue ScriptEngine::loadTemplate(QScriptContext *context, QScriptEngine *
} }
const QString constraint = QString("[X-Plasma-Shell] == '%1' and [X-KDE-PluginInfo-Name] == '%2'") const QString constraint = QString("[X-Plasma-Shell] == '%1' and [X-KDE-PluginInfo-Name] == '%2'")
.arg(KGlobal::mainComponent().componentName(),layout); .arg(KGlobal::mainComponent().componentName(), layout);
KService::List offers = KServiceTypeTrader::self()->query("Plasma/LayoutTemplate", constraint); KService::List offers = KServiceTypeTrader::self()->query("Plasma/LayoutTemplate", constraint);
if (offers.isEmpty()) { if (offers.isEmpty()) {
@ -145,8 +145,8 @@ QScriptValue ScriptEngine::loadTemplate(QScriptContext *context, QScriptEngine *
Plasma::PackageStructure::Ptr structure(new LayoutTemplatePackageStructure); Plasma::PackageStructure::Ptr structure(new LayoutTemplatePackageStructure);
KPluginInfo info(offers.first()); KPluginInfo info(offers.first());
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
structure->defaultPackageRoot() + '/' + info.pluginName() + '/', structure->defaultPackageRoot() + '/' + info.pluginName() + '/',
QStandardPaths::LocateDirectory); QStandardPaths::LocateDirectory);
if (path.isEmpty()) { if (path.isEmpty()) {
// qDebug() << "script path is empty"; // qDebug() << "script path is empty";
return false; return false;
@ -189,11 +189,11 @@ void ScriptEngine::setupEngine()
v.setProperty("widgets", newFunction(ScriptEngine::widgets)); v.setProperty("widgets", newFunction(ScriptEngine::widgets));
v.setProperty("addWidget", newFunction(ScriptEngine::addWidget)); v.setProperty("addWidget", newFunction(ScriptEngine::addWidget));
v.setProperty("applicationVersion", KGlobal::mainComponent().aboutData()->version(), v.setProperty("applicationVersion", KGlobal::mainComponent().aboutData()->version(),
QScriptValue::PropertyGetter | QScriptValue::ReadOnly | QScriptValue::Undeletable); QScriptValue::PropertyGetter | QScriptValue::ReadOnly | QScriptValue::Undeletable);
v.setProperty("scriptingVersion", newVariant(PLASMA_KPART_SCRIPTING_VERSION), v.setProperty("scriptingVersion", newVariant(PLASMA_KPART_SCRIPTING_VERSION),
QScriptValue::PropertyGetter | QScriptValue::ReadOnly | QScriptValue::Undeletable); QScriptValue::PropertyGetter | QScriptValue::ReadOnly | QScriptValue::Undeletable);
v.setProperty("platformVersion", KDE::versionString(), v.setProperty("platformVersion", KDE::versionString(),
QScriptValue::PropertyGetter | QScriptValue::ReadOnly | QScriptValue::Undeletable); QScriptValue::PropertyGetter | QScriptValue::ReadOnly | QScriptValue::Undeletable);
setGlobalObject(v); setGlobalObject(v);
} }
@ -205,9 +205,9 @@ bool ScriptEngine::evaluateScript(const QString &script, const QString &path)
if (hasUncaughtException()) { if (hasUncaughtException()) {
//qDebug() << "catch the exception!"; //qDebug() << "catch the exception!";
QString error = QString("Error: %1 at line %2\n\nBacktrace:\n%3").arg( QString error = QString("Error: %1 at line %2\n\nBacktrace:\n%3").arg(
uncaughtException().toString(), uncaughtException().toString(),
QString::number(uncaughtExceptionLineNumber()), QString::number(uncaughtExceptionLineNumber()),
uncaughtExceptionBacktrace().join("\n ")); uncaughtExceptionBacktrace().join("\n "));
emit printError(error); emit printError(error);
return false; return false;
} }
@ -334,24 +334,24 @@ QScriptValue ScriptEngine::addWidget(QScriptContext *context, QScriptEngine *eng
if (v.isString()) { if (v.isString()) {
// FIXME: Using QMetaObject::invokeMethod until the newspaper's API is exported... Fuuuu // FIXME: Using QMetaObject::invokeMethod until the newspaper's API is exported... Fuuuu
// applet = env->m_containment->addApplet(v.toString(), row, column); // applet = env->m_containment->addApplet(v.toString(), row, column);
QMetaObject::invokeMethod(env->m_containment, "addApplet", QMetaObject::invokeMethod(env->m_containment, "addApplet",
Qt::DirectConnection, Qt::DirectConnection,
Q_RETURN_ARG(Plasma::Applet*, applet), Q_RETURN_ARG(Plasma::Applet *, applet),
Q_ARG(QString, v.toString()), Q_ARG(QString, v.toString()),
Q_ARG(int, row), Q_ARG(int, column)); Q_ARG(int, row), Q_ARG(int, column));
if (applet) { if (applet) {
ScriptEngine *env = ScriptEngine::envFor(engine); ScriptEngine *env = ScriptEngine::envFor(engine);
return env->wrap(applet); return env->wrap(applet);
} }
} else if (Widget *widget = qobject_cast<Widget*>(v.toQObject())) { } else if (Widget *widget = qobject_cast<Widget *>(v.toQObject())) {
applet = widget->applet(); applet = widget->applet();
// FIXME: Using QMetaObject::invokeMethod until the newspaper's API is exported... Fuuuu // FIXME: Using QMetaObject::invokeMethod until the newspaper's API is exported... Fuuuu
// env->m_containment->addApplet(applet, row, column); // env->m_containment->addApplet(applet, row, column);
QMetaObject::invokeMethod(env->m_containment, "addApplet", QMetaObject::invokeMethod(env->m_containment, "addApplet",
Qt::DirectConnection, Qt::DirectConnection,
Q_RETURN_ARG(Plasma::Applet*, applet), Q_RETURN_ARG(Plasma::Applet *, applet),
Q_ARG(QString, v.toString()), Q_ARG(QString, v.toString()),
Q_ARG(int, row), Q_ARG(int, column)); Q_ARG(int, row), Q_ARG(int, column));
return v; return v;
} }

View File

@ -25,9 +25,9 @@
namespace Plasma namespace Plasma
{ {
class Applet; class Applet;
class Containment; class Containment;
class Corona; class Corona;
} // namespace Plasma } // namespace Plasma
namespace PlasmaKPartScripting namespace PlasmaKPartScripting

View File

@ -26,7 +26,7 @@
namespace Plasma namespace Plasma
{ {
class Applet; class Applet;
} // namespace Plasma } // namespace Plasma
namespace PlasmaKPartScripting namespace PlasmaKPartScripting
@ -71,7 +71,7 @@ public:
QString type() const; QString type() const;
/** /**
FIXME: what should the index(es?) be given that we're in the newspaper containment FIXME: what should the index(es?) be given that we're in the newspaper containment
int index() const; int index() const;
void setIndex(int index); void setIndex(int index);
*/ */
@ -89,7 +89,7 @@ public Q_SLOTS:
private: private:
class Private; class Private;
Private * const d; Private *const d;
}; };
} }

View File

@ -56,7 +56,6 @@
#include "private/associatedapplicationmanager_p.h" #include "private/associatedapplicationmanager_p.h"
#include "private/containment_p.h" #include "private/containment_p.h"
namespace Plasma namespace Plasma
{ {
@ -168,12 +167,12 @@ void Applet::restore(KConfigGroup &group)
if (!shortcutText.isEmpty()) { if (!shortcutText.isEmpty()) {
setGlobalShortcut(QKeySequence(shortcutText)); setGlobalShortcut(QKeySequence(shortcutText));
/* /*
#ifndef NDEBUG #ifndef NDEBUG
// qDebug() << "got global shortcut for" << name() << "of" << QKeySequence(shortcutText); // qDebug() << "got global shortcut for" << name() << "of" << QKeySequence(shortcutText);
#endif #endif
#ifndef NDEBUG #ifndef NDEBUG
// qDebug() << "set to" << d->activationAction->objectName() // qDebug() << "set to" << d->activationAction->objectName()
#endif #endif
<< d->activationAction->globalShortcut().primary(); << d->activationAction->globalShortcut().primary();
*/ */
} }
@ -181,10 +180,10 @@ void Applet::restore(KConfigGroup &group)
// local shortcut, if any // local shortcut, if any
//TODO: implement; the shortcut will need to be registered with the containment //TODO: implement; the shortcut will need to be registered with the containment
/* /*
#include "accessmanager.h" #include "accessmanager.h"
#include "private/plasmoidservice_p.h" #include "private/plasmoidservice_p.h"
#include "authorizationmanager.h" #include "authorizationmanager.h"
#include "authorizationmanager.h" #include "authorizationmanager.h"
shortcutText = shortcutConfig.readEntryUntranslated("local", QString()); shortcutText = shortcutConfig.readEntryUntranslated("local", QString());
if (!shortcutText.isEmpty()) { if (!shortcutText.isEmpty()) {
//TODO: implement; the shortcut //TODO: implement; the shortcut
@ -268,7 +267,7 @@ bool Applet::destroyed() const
ConfigLoader *Applet::configScheme() const ConfigLoader *Applet::configScheme() const
{ {
if (!d->configLoader) { if (!d->configLoader) {
const QString xmlPath = d->package? d->package->filePath("mainconfigxml") : QString(); const QString xmlPath = d->package ? d->package->filePath("mainconfigxml") : QString();
KConfigGroup cfg = config(); KConfigGroup cfg = config();
if (xmlPath.isEmpty()) { if (xmlPath.isEmpty()) {
d->configLoader = new ConfigLoader(&cfg, 0); d->configLoader = new ConfigLoader(&cfg, 0);
@ -352,7 +351,7 @@ Types::Types::ImmutabilityType Applet::immutability() const
Types::ImmutabilityType upperImmutability = Types::Mutable; Types::ImmutabilityType upperImmutability = Types::Mutable;
if (isContainment()) { if (isContainment()) {
Corona *cor = static_cast<Containment*>(const_cast<Applet*>(this))->corona(); Corona *cor = static_cast<Containment *>(const_cast<Applet *>(this))->corona();
if (cor) { if (cor) {
upperImmutability = cor->immutability(); upperImmutability = cor->immutability();
} }
@ -506,7 +505,7 @@ void Applet::flushPendingConstraintsEvents()
} }
// now take care of constraints in special subclass: Contaiment // now take care of constraints in special subclass: Contaiment
Containment* containment = qobject_cast<Plasma::Containment*>(this); Containment *containment = qobject_cast<Plasma::Containment *>(this);
if (containment) { if (containment) {
containment->d->containmentConstraintsEvent(c); containment->d->containmentConstraintsEvent(c);
} }
@ -534,10 +533,10 @@ void Applet::flushPendingConstraintsEvents()
} }
} }
QList<QAction*> Applet::contextualActions() QList<QAction *> Applet::contextualActions()
{ {
//qDebug() << "empty context actions"; //qDebug() << "empty context actions";
return d->script ? d->script->contextualActions() : QList<QAction*>(); return d->script ? d->script->contextualActions() : QList<QAction *>();
} }
KActionCollection *Applet::actions() const KActionCollection *Applet::actions() const
@ -561,7 +560,7 @@ Types::FormFactor Applet::formFactor() const
Containment *Applet::containment() const Containment *Applet::containment() const
{ {
Containment *c = qobject_cast<Containment*>(const_cast<Applet*>(this)); Containment *c = qobject_cast<Containment *>(const_cast<Applet *>(this));
if (c && c->isContainment()) { if (c && c->isContainment()) {
return c; return c;
} else { } else {
@ -571,7 +570,7 @@ Containment *Applet::containment() const
QObject *parent = this->parent(); QObject *parent = this->parent();
while (parent) { while (parent) {
Containment *possibleC = qobject_cast<Containment*>(parent); Containment *possibleC = qobject_cast<Containment *>(parent);
if (possibleC && possibleC->isContainment()) { if (possibleC && possibleC->isContainment()) {
c = possibleC; c = possibleC;
@ -612,7 +611,6 @@ QKeySequence Applet::globalShortcut() const
} }
} }
return QKeySequence(); return QKeySequence();
} }
@ -731,7 +729,7 @@ void Applet::timerEvent(QTimerEvent *event)
// Don't flushPendingConstraints if we're just starting up // Don't flushPendingConstraints if we're just starting up
// flushPendingConstraints will be called by Corona // flushPendingConstraints will be called by Corona
if(!(d->pendingConstraints & Plasma::Types::StartupCompletedConstraint)) { if (!(d->pendingConstraints & Plasma::Types::StartupCompletedConstraint)) {
flushPendingConstraintsEvents(); flushPendingConstraintsEvents();
} }
} else if (d->modificationsTimer && event->timerId() == d->modificationsTimer->timerId()) { } else if (d->modificationsTimer && event->timerId() == d->modificationsTimer->timerId()) {
@ -753,7 +751,7 @@ bool Applet::isContainment() const
return true; return true;
} }
//normal "acting as a containment" condition //normal "acting as a containment" condition
return qobject_cast<const Containment*>(this) && qobject_cast<Corona *>(parent()); return qobject_cast<const Containment *>(this) && qobject_cast<Corona *>(parent());
} }
} // Plasma namespace } // Plasma namespace

File diff suppressed because it is too large Load Diff

View File

@ -155,7 +155,7 @@ QString ConfigLoaderHandler::defaultValue() const
} }
bool ConfigLoaderHandler::endElement(const QString &namespaceURI, bool ConfigLoaderHandler::endElement(const QString &namespaceURI,
const QString &localName, const QString &qName) const QString &localName, const QString &qName)
{ {
Q_UNUSED(namespaceURI) Q_UNUSED(namespaceURI)
Q_UNUSED(qName) Q_UNUSED(qName)
@ -247,7 +247,7 @@ void ConfigLoaderHandler::addItem()
item = m_config->addItemFont(m_name, *d->newFont(), QFont(m_default), m_key); item = m_config->addItemFont(m_name, *d->newFont(), QFont(m_default), m_key);
} else if (m_type == "int") { } else if (m_type == "int") {
KConfigSkeleton::ItemInt *intItem = m_config->addItemInt(m_name, *d->newInt(), KConfigSkeleton::ItemInt *intItem = m_config->addItemInt(m_name, *d->newInt(),
m_default.toInt(), m_key); m_default.toInt(), m_key);
if (m_haveMin) { if (m_haveMin) {
intItem->setMinValue(m_min); intItem->setMinValue(m_min);
@ -313,11 +313,11 @@ void ConfigLoaderHandler::addItem()
longlongItem->setMaxValue(m_max); longlongItem->setMaxValue(m_max);
} }
item = longlongItem; item = longlongItem;
/* No addItemPathList in KConfigSkeleton ? /* No addItemPathList in KConfigSkeleton ?
} else if (m_type == "PathList") { } else if (m_type == "PathList") {
//FIXME: the split() is naive and will break on lists with ,'s in them //FIXME: the split() is naive and will break on lists with ,'s in them
item = m_config->addItemPathList(m_name, *d->newStringList(), m_default.split(","), m_key); item = m_config->addItemPathList(m_name, *d->newStringList(), m_default.split(","), m_key);
*/ */
} else if (m_type == "point") { } else if (m_type == "point") {
QPoint defaultPoint; QPoint defaultPoint;
QStringList tmpList = m_default.split(','); QStringList tmpList = m_default.split(',');
@ -352,15 +352,15 @@ void ConfigLoaderHandler::addItem()
ulonglongItem->setMaxValue(m_max); ulonglongItem->setMaxValue(m_max);
} }
item = ulonglongItem; item = ulonglongItem;
/* No addItemUrlList in KConfigSkeleton ? /* No addItemUrlList in KConfigSkeleton ?
} else if (m_type == "urllist") { } else if (m_type == "urllist") {
//FIXME: the split() is naive and will break on lists with ,'s in them //FIXME: the split() is naive and will break on lists with ,'s in them
QStringList tmpList = m_default.split(","); QStringList tmpList = m_default.split(",");
QList<QUrl> defaultList; QList<QUrl> defaultList;
foreach (const QString& tmp, tmpList) { foreach (const QString& tmp, tmpList) {
defaultList.append(QUrl(tmp)); defaultList.append(QUrl(tmp));
} }
item = m_config->addItemUrlList(m_name, *d->newUrlList(), defaultList, m_key);*/ item = m_config->addItemUrlList(m_name, *d->newUrlList(), defaultList, m_key);*/
} }
if (item) { if (item) {
@ -456,7 +456,7 @@ bool ConfigLoader::usrWriteConfig()
{ {
if (d->saveDefaults) { if (d->saveDefaults) {
KConfigSkeletonItem::List itemList = items(); KConfigSkeletonItem::List itemList = items();
for(int i = 0; i < itemList.size(); i++) { for (int i = 0; i < itemList.size(); i++) {
KConfigGroup cg(config(), itemList.at(i)->group()); KConfigGroup cg(config(), itemList.at(i)->group());
cg.writeEntry(itemList.at(i)->key(), ""); cg.writeEntry(itemList.at(i)->key(), "");
} }

View File

@ -146,7 +146,7 @@ protected:
private: private:
friend class Service; friend class Service;
ConfigLoaderPrivate * const d; ConfigLoaderPrivate *const d;
}; };
} // Plasma namespace } // Plasma namespace

Some files were not shown because too many files have changed in this diff Show More