Esempio n. 1
0
bool ThemeManager::selectItem(const QString& id, bool is_default)
{
	QListWidget* view = m_themes;
	QListWidget* other_view = m_default_themes;
	if (is_default) {
		std::swap(view, other_view);
	}
	QAbstractItemModel* model = view->model();
	QModelIndexList items = model->match(model->index(0, 0, QModelIndex()),
			Qt::UserRole, id, 1, Qt::MatchFixedString | Qt::MatchCaseSensitive);
	if (!items.isEmpty()) {
		view->setCurrentRow(items.first().row());
		other_view->setCurrentIndex(other_view->rootIndex());
		m_tabs->setCurrentIndex(!is_default);
		return true;
	} else {
		return false;
	}
}
Esempio n. 2
0
/*!
    Return a new modelType.
 */
QAbstractItemModel *ModelsToTest::createModel(const QString &modelType)
{
    if (modelType == "QStringListModelEmpty")
        return new QStringListModel();

    if (modelType == "QStringListModel") {
        QStringListModel *model = new QStringListModel();
        populateTestArea(model);
        return model;
    }

    if (modelType == "QStandardItemModelEmpty") {
        return new QStandardItemModel();
    }

    if (modelType == "QStandardItemModel") {
        QStandardItemModel *model = new QStandardItemModel();
        populateTestArea(model);
        return model;
    }

    if (modelType == "QSortFilterProxyModelEmpty") {
        QSortFilterProxyModel *model = new QSortFilterProxyModel;
        QStandardItemModel *standardItemModel = new QStandardItemModel;
        model->setSourceModel(standardItemModel);
        return model;
    }

    if (modelType == "QSortFilterProxyModelRegExp") {
        QSortFilterProxyModel *model = new QSortFilterProxyModel;
        QStandardItemModel *standardItemModel = new QStandardItemModel;
        model->setSourceModel(standardItemModel);
        populateTestArea(model);
        model->setFilterRegExp(QRegExp("(^$|0.*)"));
        return model;
    }

    if (modelType == "QSortFilterProxyModel") {
        QSortFilterProxyModel *model = new QSortFilterProxyModel;
        QStandardItemModel *standardItemModel = new QStandardItemModel;
        model->setSourceModel(standardItemModel);
        populateTestArea(model);
        return model;
    }

    if (modelType == "QDirModel") {
        QDirModel *model = new QDirModel();
        model->setReadOnly(false);
        return model;
    }

    if (modelType == "QSqlQueryModel") {
        QSqlQueryModel *model = new QSqlQueryModel();
        populateTestArea(model);
        return model;
    }

    if (modelType == "QSqlQueryModelEmpty") {
        QSqlQueryModel *model = new QSqlQueryModel();
        return model;
    }

    if (modelType == "QSqlTableModel") {
        QSqlTableModel *model = new QSqlTableModel();
        populateTestArea(model);
        return model;
    }

    if (modelType == "QListModelEmpty")
        return (new QListWidget)->model();

    if (modelType == "QListModel") {
        QListWidget *widget = new QListWidget;
        populateTestArea(widget->model());
        return widget->model();
    }

    if (modelType == "QTableModelEmpty")
        return (new QTableWidget)->model();

    if (modelType == "QTableModel") {
        QTableWidget *widget = new QTableWidget;
        populateTestArea(widget->model());
        return widget->model();
    }

    if (modelType == "QTreeModelEmpty") {
        QTreeWidget *widget = new QTreeWidget;
        return widget->model();
    }

    if (modelType == "QTreeModel") {
        QTreeWidget *widget = new QTreeWidget;
        populateTestArea(widget->model());
        return widget->model();
    }

    return 0;
}