Exemple #1
0
void FindObjectWidget::reload(WidgetForControl* apControlFind)
{
    if (dynamic_cast<ApartmentWidget*>(apControlFind)
            || dynamic_cast<RentWidget*>(apControlFind)
            || dynamic_cast<HomeWidget*>(apControlFind))
    {
        TableModel* vpModel = dynamic_cast<TableModel*>(ui->mpView->model());
        if (vpModel)
        {
            ui->mpView->setModel(0);
            vpModel->load();
            ui->mpView->setModel(vpModel);

        }
        delete apControlFind;
        return;
    }
    FindApartment* vpFindApartment = dynamic_cast<FindApartment*>(apControlFind);
    FindRent * vpFindRent = dynamic_cast<FindRent*>(apControlFind);
    FindHome * vpFindHome = dynamic_cast<FindHome*>(apControlFind);
    TableModel* vpModel = 0;
    if (ui->mpView->model())
    {
        delete ui->mpView->model();
    }
    if (vpFindApartment)
    {
        vpModel = new TableModelApartment();
        if (!vpFindApartment->sql().isEmpty())
        {
            if (vpFindApartment->sql() != " ")
            ((TableModelApartment*)vpModel)->addFilter(vpFindApartment->sql());
        }
        else
        {
            return;
        }
    }
    if (vpFindRent)
    {
        vpModel = new TableModelRent();
        if (!vpFindRent->sql().isEmpty())
        {
            if (vpFindRent->sql() != " ")
            ((TableModelRent*)vpModel)->addFilter(vpFindRent->sql());
        }
        else
        {
            return;
        }
    }
    if (vpFindHome)
    {
        vpModel = new TableModelHome();
        if (!vpFindHome->sql().isEmpty())
        {
            if (vpFindHome->sql() != " ")
            ((TableModelHome*)vpModel)->addFilter(vpFindHome->sql());
        }
        else
        {
            return;
        }
    }
    vpModel->setActive(true);
    vpModel->setArchive(false);
    vpModel->setAside(false);
    vpModel->load();
    ui->mpView->setModel(vpModel);
    if (!ui->mpView->isVisible())
    {
        ui->mpView->setVisible(true);
        if (ui->verticalSpacer)
        {
            ui->verticalLayout->removeItem(ui->verticalSpacer);
            delete ui->verticalSpacer;
            ui->verticalSpacer = 0;
        }
    }
    ui->mpView->reset();
    ui->mpView->resizeRowsToContents();
    ui->mpView->resizeColumnsToContents();
    delete apControlFind;
}