Пример #1
0
void QCompletionEngine::filter(const QStringList& parts)
{
    const QAbstractItemModel *model = c->proxy->sourceModel();
    curParts = parts;
    if (curParts.isEmpty())
        curParts.append(QString());

    curRow = -1;
    curParent = QModelIndex();
    curMatch = QMatchData();
    historyMatch = filterHistory();

    if (!model)
        return;

    QModelIndex parent;
    for (int i = 0; i < curParts.count() - 1; i++) {
        QString part = curParts[i];
        int emi = filter(part, parent, -1).exactMatchIndex;
        if (emi == -1)
            return;
        parent = model->index(emi, c->column, parent);
    }

    // Note that we set the curParent to a valid parent, even if we have no matches
    // When filtering is disabled, we show all the items under this parent
    curParent = parent;
    if (curParts.last().isEmpty())
        curMatch = QMatchData(QIndexMapper(0, model->rowCount(curParent) - 1), -1, false);
    else
        curMatch = filter(curParts.last(), curParent, 1); // build at least one
    curRow = curMatch.isValid() ? 0 : -1;
}
Пример #2
0
void HistoryContentsWidget::addEntry(const HistoryEntry &entry)
{
	if (entry.identifier < 0)
	{
		return;
	}

	QStandardItem *groupItem = NULL;

	for (int i = 0; i < m_model->rowCount(); ++i)
	{
		groupItem = m_model->item(i, 0);

		if (groupItem && (entry.time.date() >= groupItem->data(Qt::UserRole).toDate() || !groupItem->data(Qt::UserRole).toDate().isValid()))
		{
			break;
		}

		groupItem = NULL;
	}

	if (!groupItem)
	{
		return;
	}

	QList<QStandardItem*> entryItems;
	entryItems.append(new QStandardItem((entry.icon.isNull() ? Utils::getIcon(QLatin1String("text-html")) : entry.icon), entry.url.toString().replace(QLatin1String("%23"), QString(QLatin1Char('#')))));
	entryItems.append(new QStandardItem(entry.title.isEmpty() ? tr("(Untitled)") : entry.title));
	entryItems.append(new QStandardItem(entry.time.toString()));
	entryItems[0]->setData(entry.identifier, Qt::UserRole);

	groupItem->appendRow(entryItems);

	m_ui->historyView->setRowHidden(groupItem->row(), groupItem->index().parent(), false);

	if (sender())
	{
		groupItem->sortChildren(2, Qt::DescendingOrder);
	}

	if (!m_ui->filterLineEdit->text().isEmpty())
	{
		filterHistory(m_ui->filterLineEdit->text());
	}
}
Пример #3
0
HistoryContentsWidget::HistoryContentsWidget(Window *window) : ContentsWidget(window),
	m_model(new QStandardItemModel(this)),
	m_isLoading(true),
	m_ui(new Ui::HistoryContentsWidget)
{
	m_ui->setupUi(this);

	QStringList groups;
	groups << tr("Today") << tr("Yesterday") << tr("Earlier This Week") << tr("Previous Week") << tr("Earlier This Month") << tr("Earlier This Year") << tr("Older");

	for (int i = 0; i < groups.count(); ++i)
	{
		m_model->appendRow(new QStandardItem(Utils::getIcon(QLatin1String("inode-directory")), groups.at(i)));
	}

	QStringList labels;
	labels << tr("Address") << tr("Title") << tr("Date");

	m_model->setHorizontalHeaderLabels(labels);
	m_model->setSortRole(Qt::DisplayRole);

	m_ui->historyView->setModel(m_model);
	m_ui->historyView->setItemDelegate(new ItemDelegate(this));
	m_ui->historyView->header()->setTextElideMode(Qt::ElideRight);
	m_ui->historyView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
	m_ui->historyView->expand(m_model->index(0, 0));

	QTimer::singleShot(100, this, SLOT(populateEntries()));

	connect(HistoryManager::getInstance(), SIGNAL(cleared()), this, SLOT(populateEntries()));
	connect(HistoryManager::getInstance(), SIGNAL(entryAdded(qint64)), this, SLOT(addEntry(qint64)));
	connect(HistoryManager::getInstance(), SIGNAL(entryUpdated(qint64)), this, SLOT(updateEntry(qint64)));
	connect(HistoryManager::getInstance(), SIGNAL(entryRemoved(qint64)), this, SLOT(removeEntry(qint64)));
	connect(HistoryManager::getInstance(), SIGNAL(dayChanged()), this, SLOT(populateEntries()));
	connect(m_ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterHistory(QString)));
	connect(m_ui->historyView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openEntry(QModelIndex)));
	connect(m_ui->historyView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
}
Пример #4
0
void HistoryContentsWidget::updateEntry(qint64 entry)
{
	QStandardItem *entryItem = findEntry(entry);

	if (!entryItem)
	{
		addEntry(entry);

		return;
	}

	HistoryEntry historyEntry = HistoryManager::getEntry(entry);

	entryItem->setIcon(historyEntry.icon.isNull() ? Utils::getIcon(QLatin1String("text-html")) : historyEntry.icon);
	entryItem->setText(historyEntry.url.toString());
	entryItem->parent()->child(entryItem->row(), 1)->setText(historyEntry.title.isEmpty() ? tr("(Untitled)") : historyEntry.title);
	entryItem->parent()->child(entryItem->row(), 2)->setText(historyEntry.time.toString());

	if (!m_ui->filterLineEdit->text().isEmpty())
	{
		filterHistory(m_ui->filterLineEdit->text());
	}
}