QVariant BluetoothDevicesModel::data(const QModelIndex &index, int role) const
{
	qDebug()<<"requested role: "<<roleNames()[role];

	if(!index.isValid() || index.row() < 0)
	{
		qDebug()<<"index is not valid: "<<index.row()<<","<<index.column();
		return QVariant(); ///this is retarded but it has to be done.
	}

	if(roleNames()[role] == "bluetoothDevice")
	{
		return QVariant::fromValue<QObject*>((QObject*)m_devices[index.row()]);
	}

	QString roleName = roleNames()[role];
	QMetaObject object = BluetoothDevice::staticMetaObject;

	for(int i=0; i<object.propertyCount(); i++)
	{
		if(object.property(i).name() == roleName)
		{

			return object.property(i).read(m_devices[index.row()]);
		}
	}
	return QVariant();
}
QVariantHash DefaultItemFilterProxyModel::get(int row) const
{
    QModelIndex idx = index(row, 0);
    QVariantHash hash;

    QHash<int, QByteArray>::const_iterator i;
    for (i = roleNames().constBegin(); i != roleNames().constEnd(); ++i) {
        hash[i.value()] = data(idx, i.key());
    }

    return hash;
}
Пример #3
0
bool CheckedListModel::allChecked()
{
    int roleIndex = roleNames().key("checked");

    if (roleNames().contains(roleIndex))
    {
        for (int row=0; row<m_list.size(); ++row)
        {
            if (!m_list.at(row)->data(roleIndex).toBool())
                return false;
        }
    }

    return true;
}
Пример #4
0
TechnologyModel::TechnologyModel(QAbstractListModel* parent)
  : QAbstractListModel(parent),
    m_manager(NULL),
    m_tech(NULL),
    m_scanning(false),
    m_changesInhibited(false),
    m_uneffectedChanges(false),
    m_scanResultsReady(false)
{
    m_manager = NetworkManagerFactory::createInstance();

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    setRoleNames(roleNames());
#endif
    connect(m_manager, SIGNAL(availabilityChanged(bool)),
            this, SLOT(managerAvailabilityChanged(bool)));

    connect(m_manager,
            SIGNAL(technologiesChanged()),
            this,
            SLOT(updateTechnologies()));

    connect(m_manager,
            SIGNAL(servicesChanged()),
            this,
            SLOT(updateServiceList()));
}
Пример #5
0
ReverseTranslationsModel::ReverseTranslationsModel(QObject *parent)
    : QAbstractListModel(parent)
{
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    setRoleNames(roleNames());
#endif
}
PlaylistModel::PlaylistModel(QObject* parent):
    QAbstractListModel(parent),
    d(new Private)
{
    KConfigGroup cfgGroup = KGlobal::config()->group("General");
    setRandom(cfgGroup.readEntry("randomplaylist",false));
    QString dirPath = KGlobal::dirs()->saveLocation("data") + KCmdLineArgs::appName();
    QDir().mkdir(dirPath);
    d->filePath = dirPath + "/playlist";

    if (QFile::exists(d->filePath)) {
        QFile file(d->filePath);
        if (file.open(QIODevice::ReadOnly)) {
            QTextStream in(&file);
            while (!in.atEnd()) {
                QString line = in.readLine();
                d->musicList.append(PlaylistItem::fromString(line));
            }
        }
        file.close();
    }
    d->currentIndex = -1;
    setRoleNames(MediaCenter::appendAdditionalMediaRoles(roleNames()));

    qsrand(QDateTime::currentMSecsSinceEpoch());
}
Пример #7
0
void SectionDataModel::setModel(QAbstractItemModel *model)
{
    if (model == m_model)
        return;

    if (m_model) {
        disconnect(m_model, SIGNAL(modelReset()), this, SLOT(buildSectionMap()));
        disconnect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(handleRowsInserted(QModelIndex,int,int)));
        disconnect(m_model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(handleRowsMoved(QModelIndex,int,int,QModelIndex,int)));
        disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(handleRowsRemoved(QModelIndex,int,int)));
        disconnect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(handleDataChanged(QModelIndex,QModelIndex)));
    }

    m_model = model;

    if (m_model) {
        connect(m_model, SIGNAL(modelReset()), SLOT(buildSectionMap()));
        connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(handleRowsInserted(QModelIndex,int,int)));
        connect(m_model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), SLOT(handleRowsMoved(QModelIndex,int,int,QModelIndex,int)));
        connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(handleRowsRemoved(QModelIndex,int,int)));
        connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(handleDataChanged(QModelIndex,QModelIndex)));

        setRoleNames(m_model->roleNames());
    } else {
        setRoleNames(QHash<int, QByteArray>());
    }

    if (!m_sectionKey.isEmpty()) {
        m_sectionRole = roleNames().key(m_sectionKey.toLatin1());
    }

    emit modelChanged();

    buildSectionMap();
}
Пример #8
0
ResultModel::ResultModel(QObject *parent)
    : QAbstractListModel(parent), m_historyIndex(-1)
{    
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    setRoleNames(roleNames());
#endif
}
Пример #9
0
PicasaModel::PicasaModel(QObject* parent, const QString& username, const QString& password): QAbstractListModel(parent)
{
    m_flag = false;
    m_expandable = false;
    setRoleNames(MediaCenter::appendAdditionalMediaRoles(roleNames()));
    getTokenAndQuery(username, password,"album");
}
Пример #10
0
UsersModel::UsersModel(QObject *parent) :
    QAbstractListModel(parent),
    d_ptr(new UsersModelPrivate(this))
{
    Q_D(UsersModel);

    // Extend roleNames (we want to keep the "display" role)
    QHash<int, QByteArray> roles = roleNames();
    roles[NameRole] = "name";
    roles[RealNameRole] = "realName";
    roles[LoggedInRole] = "loggedIn";
    roles[BackgroundRole] = "background";
    roles[BackgroundPathRole] = "backgroundPath";
    roles[SessionRole] = "session";
    roles[HasMessagesRole] = "hasMessages";
    roles[ImagePathRole] = "imagePath";
    setRoleNames(roles);

    // Now modify our mock user backgrounds
    QDir bgdir = QDir(QStringLiteral("/usr/share/demo-assets/shell/backgrounds/"));
    QStringList backgrounds = bgdir.entryList(QDir::Files | QDir::NoDotAndDotDot);

    for (int i = 0, j = 0; i < d->entries.size(); i++) {
        Entry &entry = d->entries[i];
        if (entry.background.isNull() && !backgrounds.isEmpty()) {
            entry.background = bgdir.filePath(backgrounds[j++]);
            if (j >= backgrounds.length()) {
                j = 0;
            }
        }
    }
}
Пример #11
0
DictionaryModel::DictionaryModel(QObject *parent) :
    QAbstractListModel(parent)
{
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    setRoleNames(roleNames());
#endif
}
Пример #12
0
CommandModel::CommandModel() :
    m_loading(false)
{
    QHash<int, QByteArray> names = roleNames();
    names.insert(Qt::UserRole, "trigger");
    setRoleNames(names);
}
Пример #13
0
QVariantMap FileModel::get(int idx) const {
    QVariantMap map;
    foreach(int k, roleNames().keys()) {
        map[roleNames().value(k)] = data(index(idx, 0), k);
    }
    return map;
}
Пример #14
0
bool SalesModel::setProperty(int rowIndex, const QString &property, const QVariant &value)
{

    QVariantMap rowValues = getProperty(rowIndex);
    const char * UPDATE_STAMENT="UPDATE items_sales set price = :price WHERE prov = :prov and ref = :ref "
            "and size = :size and color = :color and sales_date = :sales_date;";
    m_updateQuery.prepare(UPDATE_STAMENT);
    m_updateQuery.bindValue(":ref",rowValues["ref"]);
    m_updateQuery.bindValue(":size",rowValues["size"]);
    m_updateQuery.bindValue(":color",rowValues["color"]);
    m_updateQuery.bindValue(":prov",rowValues["prov"]);
    m_updateQuery.bindValue(":sales_date",rowValues["date"]);
    m_updateQuery.bindValue(":price", value);
    if(!m_updateQuery.exec()){
        qWarning()<<"could no update sales "<<m_updateQuery.lastQuery();
        return false;

    }
    qDebug()<<"price updated "<<value;
    QHash<int, QByteArray> roles = roleNames();
    QModelIndex ind = index(rowIndex,roles.key("price"));
    QSqlQuery q = query();
    q.exec();
    setQuery(q);

    emit dataChanged(ind,ind);
    return true;

}
Пример #15
0
TranslationServicesModel::TranslationServicesModel(const QStringList &strings, QObject *parent)
    : QStringListModel(strings, parent)
{
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    setRoleNames(roleNames());
#endif
}
Пример #16
0
QVariantMap GameLibraryModel::get(int inx)
{
    QVariantMap map;
    foreach (int i, roleNames().keys()) {
        map[roleNames().value(i)] = data(index(inx, 0), i);
    }
    return map;
}
CMLibraryModel::CMLibraryModel(QObject *parent)
    : QSqlQueryModel(parent)
{    
#if QT_VERSION < 0x050000
    setRoleNames(roleNames());
#endif
    refresh();
}
CategoriesModel::CategoriesModel(QObject* parent): QAbstractItemModel(parent)
{
    m_categories.append(Category("All Songs", "audio", Category::AllMusic));
    m_categories.append(Category("Artists", "user-identity", Category::Artists));
    m_categories.append(Category("Albums", "tools-media-optical-copy", Category::Albums));

    setRoleNames(MediaCenter::appendAdditionalMediaRoles(roleNames()));
}
Пример #19
0
Rules::Rules(QObject *parent):
    HueModel(parent),
    m_busy(false)
{
#if QT_VERSION < 0x050000
    setRoleNames(roleNames());
#endif
}
Пример #20
0
OcFeedsModelNew::OcFeedsModelNew(QObject *parent) :
    QAbstractListModel(parent)
{
    m_folderId = -999;

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    setRoleNames(roleNames());
#endif
}
Пример #21
0
Trainrestrictions::Trainrestrictions(QObject *parent)
    : QStringListModel(parent)
{
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    setRoleNames(roleNames());
#endif

    connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged()));
}
Пример #22
0
NotesModel::NotesModel(QObject *parent) :
    QAbstractListModel(parent), m_query(new QSqlQueryModel(this))
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("qmiss.db");
    Q_ASSERT(db.open());
    m_query->setQuery("SELECT id,title,description FROM Notes ORDER BY title;");
    qDebug() << roleNames();
}
Пример #23
0
RouteRequestModel::RouteRequestModel( QObject *parent ) :
    QAbstractListModel( parent ),
    m_request( 0 ),
    m_routing( 0 )
{
    QHash<int,QByteArray> roles = roleNames();
    roles[LongitudeRole] = "longitude";
    roles[LatitudeRole] = "latitude";
    setRoleNames( roles );
}
Пример #24
0
QHash<int, QByteArray> WGTransposeProxy::roleNames() const
{
	auto source = sourceModel();
	if (source == nullptr)
	{
		return QHash<int, QByteArray>();
	}

	return source->roleNames();
}
int SortFilterProxyModel::roleKey(const QByteArray &role) const
{
    QHash<int, QByteArray> roles = roleNames();
    QHashIterator<int, QByteArray> it(roles);
    while (it.hasNext()) {
        it.next();
        if (it.value() == role)
            return it.key();
    }
    return -1;
}
Пример #26
0
QVariantMap AbstractListModel::get(int row)
{
    auto roles = roleNames();
    QVariantMap map;
    auto index = createIndex(row, 0);
    for (auto it = roles.constBegin(); it != roles.constEnd(); it++) {
        auto value = data(index, it.key());
        map.insert(it.value(), value);
    }
    return map;
}
Пример #27
0
EventsModel::EventsModel(QObject* parent): QAbstractListModel(parent)
{
    setRoleNames(MediaCenter::appendAdditionalMediaRoles(roleNames()));

    auto configGroup = KGlobal::config()->group(CONFIG_GROUP);
    QByteArray data = configGroup.readEntry("events", QByteArray());
    QDataStream s(&data, QIODevice::ReadOnly);

    s >> m_events;
    m_eventNames = m_events.keys();
}
Пример #28
0
FlatFilesystemModel::FlatFilesystemModel(const QString& path, const QStringList& filters) : m_path(path)
{
    QHash<int, QByteArray> names = roleNames();
    names.insert(Qt::UserRole, "index");
    names.insert(Qt::UserRole+1, "filePathRole");
    names.insert(Qt::UserRole+2, "niceFileName");
    setRoleNames(names);

    QDir d(path);
    m_files = d.entryList(filters, QDir::Files|QDir::NoDotAndDotDot);
}
QVariantMap
UnitySortFilterProxyModelQML::get(int row)
{
    QVariantMap res;
    const QHash<int, QByteArray> roles = roleNames();
    auto it = roles.begin();
    for ( ; it != roles.end(); ++it) {
        res[*it] = data(row, it.key());
    }
    return res;
}
Пример #30
0
///Constructor
CredentialModel::CredentialModel(Account* acc) : QAbstractListModel(acc),
d_ptr(new CredentialModelPrivate())
{
   Q_ASSERT(acc);
   d_ptr->m_EditState = CredentialModel::EditState::LOADING;
   d_ptr->m_pAccount  = acc;
   d_ptr->q_ptr       = this;
   QHash<int, QByteArray> roles = roleNames();
   this << EditAction::RELOAD;
   d_ptr->m_EditState = CredentialModel::EditState::READY;
}