예제 #1
0
void HuggleQueue::ResortItem(QLayoutItem *item, int position)
{
    HUGGLE_PROFILER_INCRCALL(BOOST_CURRENT_FUNCTION);
    if (position < 0)
    {
        // we don't know the position so we need to calculate it
        position = 0;
        while (position < this->ui->itemList->count() - 1)
        {
            if (item == this->ui->itemList->itemAt(position))
            {
                break;
            }
            position++;
        }
        if (position == this->ui->itemList->count() - 1)
        {
            HUGGLE_DEBUG("Unable to sort the queue because item wasn't present", 1);
            return;
        }
    }

    // first we get the item
    HuggleQueueItemLabel *q1 = (HuggleQueueItemLabel*)item->widget();
    int Score = q1->Edit->Score;
    int x = 0;
    bool sorted = true;
    while (x < position)
    {
        // every item on left side has to be lower than this one
        // get the item by index and compare the size
        QLayoutItem *l2 = this->ui->itemList->itemAt(x);
        if (l2 != item)
        {
            HuggleQueueItemLabel *q2 = (HuggleQueueItemLabel*)l2->widget();
            if (q2->Edit->Score < Score)
            {
                sorted = false;
                break;
            }
        }
        x++;
    }
    while (x < this->ui->itemList->count() - 1)
    {
        // every item on right side has to be bigger than this one
        // get the item by index and compare the size
        QLayoutItem *l2 = this->ui->itemList->itemAt(x);
        if (l2 != item)
        {
            HuggleQueueItemLabel *q2 = (HuggleQueueItemLabel*)l2->widget();
            // we need to check here if we accidentaly didn't get some
            // element that actually isn't an item
            if (q2 != nullptr && q2->Edit->Score > Score)
            {
                sorted = false;
                break;
            }
        }
        x++;
    }
    if (!sorted)
    {
        // now we need to remove the item and place it again
        // because QT doesn't allow manual insertion of item for unknown reasons, we need to readd whole item
        WikiEdit *page = q1->Edit;
        page->RegisterConsumer("HuggleQueue::ResortItem");
        this->DeleteItem(q1);
        this->AddItem(page);
        page->UnregisterConsumer("HuggleQueue::ResortItem");
    }
}
void HistoryForm::Display(int row, QString html, bool turtlemode)
{
    if (row == this->SelectedRow)
    {
        // there is nothing to do because we want to display exactly that row which was already selected
        return;
    }
    if (this->query != nullptr || this->RetrievingEdit || this->ui->tableWidget->rowCount() == 0 || this->CurrentEdit == nullptr)
    {
        // we must not retrieve edit until previous operation did finish
        return;
    }

    this->PreviouslySelectedRow = this->SelectedRow;
    this->SelectedRow = row;
    this->RetrievingEdit = true;
    // check if we don't have this edit in a buffer
    int x = 0;
    int revid = this->ui->tableWidget->item(row, 4)->text().toInt();
    if (revid == 0)
    {
        this->RetrievingEdit = false;
        return;
    }
    WikiEdit::Lock_EditList->lock();
    while (x < WikiEdit::EditList.count())
    {
        WikiEdit *edit = WikiEdit::EditList.at(x);
        x++;
        if (edit->RevID == revid)
        {
            MainWindow::HuggleMain->ProcessEdit(edit, false, true);
            this->RetrievingEdit = false;
            WikiEdit::Lock_EditList->unlock();
            this->MakeSelectedRowBold();
            return;
        }
    }
    WikiEdit::Lock_EditList->unlock();
    // there is no such edit, let's get it
    WikiEdit *w = new WikiEdit();
    w->User = new WikiUser(this->ui->tableWidget->item(row, 1)->text());
    w->Page = new WikiPage(this->CurrentEdit->Page);
    w->RevID = revid;
    w->RegisterConsumer(HUGGLECONSUMER_HISTORYWIDGET);
    if (this->RetrievedEdit != nullptr)
    {
        this->RetrievedEdit->UnregisterConsumer(HUGGLECONSUMER_HISTORYWIDGET);
    }
    QueryPool::HugglePool->PostProcessEdit(w);
    if (this->t1 != nullptr)
    {
        delete this->t1;
    }
    this->RetrievedEdit = w;
    MainWindow::HuggleMain->LockPage();
    MainWindow::HuggleMain->Browser->RenderHtml(html);
    this->t1 = new QTimer();
    connect(this->t1, SIGNAL(timeout()), this, SLOT(onTick01()));
    if (!turtlemode)
    {
        this->t1->start(200);
        return;
    }
    this->t1->start(2000);
}