Exemplo n.º 1
0
void toResultLine::addMenues(QMenu *popup)
{
    if (sqlName().length())
    {
        popup->addSeparator();
        popup->addAction(tr("Edit SQL..."),
                         this,
                         SLOT(editSQL()));
    }
}
Exemplo n.º 2
0
void toResultItem::addItem(const QString &title, const QString &value)
{
    if (WidgetPos >= NumWidgets)
    {
        NumWidgets += ALLOC_SIZE;
        Widgets.resize(NumWidgets, 0);
    }
    QString t;
    if (title != "-")
        t = Utils::toTranslateMayby(sqlName(), title);
    QWidget *widget;
    if (!Widgets[WidgetPos])
    {
        widget = createTitle(this);
        Widgets[WidgetPos] = widget;
    }
    else
        widget = ((QLabel *)Widgets[WidgetPos]);

    setTitle(widget, t, value);
    if (ShowTitle)
        widget->show();
    else
        widget->hide();

    WidgetPos++;
    if (!Widgets[WidgetPos])
    {
        widget = createValue(this);
        Widgets[WidgetPos] = widget;
    }
    else
        widget = Widgets[WidgetPos];
    setValue(widget, title, value);

    widget->show();
    WidgetPos++;
}
Exemplo n.º 3
0
//-----------------------------------------------------------------------------
void Generator::loadProperties()
{
    setPropertiesLoaded(false);

    DatabasePtr db = getDatabase();
    MetadataLoader* loader = db->getMetadataLoader();
    MetadataLoaderTransaction tr(loader);

    // IMPORTANT: for all other loading where the name of the db object is
    // Set() into a parameter getName_() is used, but for dynamically
    // building the SQL statement getQuotedName() must be used!
    std::string sqlName(wx2std(getQuotedName(), db->getCharsetConverter()));
    // do not use cached statements, because this can not be reused
    IBPP::Statement st1 = loader->createStatement(
        "select gen_id(" + sqlName + ", 0) from rdb$database");
        
    st1->Execute();
    st1->Fetch();
    st1->Get(1, &valueM);

    setPropertiesLoaded(true);
    notifyObservers();
}
Exemplo n.º 4
0
void toResultLong::slotAddItem(void)
{
    if (!Utils::toCheckModal(this))
        return;

    try
    {
        while (Query->hasMore())
        {
            bool em = false; // should we emit signal about first row fetched?
            QString buffer;
            if (First)
            {
                QString tmp = sql().simplified().mid(0, 10).toLower();
                if (tmp.startsWith(QString::fromLatin1("update")) ||
                        tmp.startsWith(QString::fromLatin1("delete")) ||
                        tmp.startsWith(QString::fromLatin1("insert")))
                    buffer = tr("%1 rows processed").arg(Query->rowsProcessed());
                else if (tmp.startsWith(QString::fromLatin1("select")))
                    buffer = tr("Query executed");
                else
                    buffer = tr("Statement executed");
                em = true;
            }
            if (!HasHeaders)
            {
                Description = Query->describe();
                bool hidden = false;

                for (toQColumnDescriptionList::iterator i = Description.begin(); i != Description.end(); i++)
                {
                    QString name = (*i).Name;
                    if (ReadableColumns)
                        Utils::toReadableColumn(name);
                    if (name.length() > 0 && name[0].toLatin1() != ' ')
                    {
                        if (hidden)
                            throw tr("Can only hide last column in query");
                        if (name[0].toLatin1() == '-')
                        {
                            addColumn(Utils::toTranslateMayby(sqlName(), name.right(name.length() - 1)));
                            setColumnAlignment(columns() - 1, Qt::AlignRight);
                        }
                        else
                        {
                            addColumn(Utils::toTranslateMayby(sqlName(), name));
                            if ((*i).AlignRight)
                                setColumnAlignment(columns() - 1, Qt::AlignRight);
                        }
                    }
                    else
                        hidden = true;
                }
                HasHeaders = true;

                setResizeMode(toTreeWidget::AllColumns);

                if (sortColumn() < 0)
                {
                    if (NumberColumn)
                        setSorting(0);
                    else
                        setSorting(Description.size());
                }
            }

            if (Query->hasMore())
            {
                int disp = 0;
                unsigned int cols = Description.size();
                if (NumberColumn)
                {
                    disp = 1;
                }
                do
                {
                    toTreeWidgetItem *last = LastItem;
                    LastItem = createItem(LastItem, QString::null);
                    if (NumberColumn)
                        LastItem->setText(0, QString::number(RowNumber + 1));
                    else
                        LastItem->setText(cols, QString::number(RowNumber + 1));
                    toResultViewItem *ri = dynamic_cast<toResultViewItem *>(LastItem);
                    toResultViewCheck *ci = dynamic_cast<toResultViewCheck *>(LastItem);
                    for (unsigned int j = 0; (j < cols || j == 0) && !Query->eof(); j++)
                    {
                        if (ri)
                            ri->setText(j + disp, (QString)Query->readValue());
                        else if (ci)
                            ci->setText(j + disp, (QString)Query->readValue());
                        else
                            LastItem->setText(j + disp, (QString)Query->readValue());
                    }
                    if (Filter && !Filter->check(LastItem))
                    {
                        delete LastItem;
                        LastItem = last;
                    }
                    else
                        RowNumber++;
                }
                while (Query->hasMore() && (MaxNumber < 0 || MaxNumber > RowNumber));
            }
            if (em)
            {
                First = false;
                emit firstResult(sql(), toConnection::exception(buffer), false);
            }
            if (!(MaxNumber < 0 || MaxNumber > RowNumber))
                Query->stop();
        }
    }
    catch (const toConnection::exception &str)
    {
        if (First)
        {
            First = false;
            emit firstResult(sql(), str, true);
            //// if (Mode != toQuery::Long)
            Utils::toStatusMessage(str);
        }
        else
            Utils::toStatusMessage(str);
        cleanup();
    }
    catch (const QString &str)
    {
        if (First)
        {
            First = false;
            emit firstResult(sql(), str, true);
            //// if (Mode != toQuery::Long)
            Utils::toStatusMessage(str);
        }
        else
            Utils::toStatusMessage(str);
        cleanup();
    }
}
Exemplo n.º 5
0
void SearchDlg::searchClicked()
{
    if (searchInDirs || searchInFiles || searchInDescriptions)
    {
        QString searchCriteria = searchLineEdit->text();
        if (searchCriteria.isEmpty())
        {
            QMessageBox::critical(this, tr("Missing Criteria"), tr("Missing Search Criteria.\nPlease fill some pattern to search for. "));   
            return;
  
        }
        dm->settings->searchDirNames = searchInDirs;
        dm->settings->searchFileNames = searchInFiles;
        dm->settings->searchDescriptions = searchInDescriptions;
        dm->settings->searchCaseSensitive = caseSensitiveSearch;

        QString sqlC = "SELECT id, parent, itemType, name, size, dateTime, iconId, attributes, diskNo FROM Catalog_" + QString::number(catId) + " WHERE ";
        QString sqlF = "SELECT id, parent, itemType, name, size, dateTime, iconId, attributes, diskNo FROM Files_" + QString::number(catId) + " WHERE ";
        
        QString sqlName(NULL);
        QString sqlDesc(NULL);
        if (searchInDescriptions)
        {
         	sqlDesc = " (description LIKE '%" + searchCriteria + "%') ";   
        }
        
        if (searchInFiles)
        {
            sqlName = " (name LIKE '%" + searchCriteria + "%') ";
            if (searchInDescriptions)
                sqlName += "OR " + sqlDesc;
        }
        if (searchInDirs)
        {
            sqlName = " (name LIKE '%" + searchCriteria + "%') ";
            if (searchInDescriptions)
                sqlName += "OR " + sqlDesc;
            
        }
        /*
        if (searchInDirs && searchInFiles)
        {
            sqlName = " (name LIKE '%" + searchCriteria + "%') ";
            if (searchInDescriptions)
                sqlName += "OR " + sqlDesc;
        }else{
            if (searchInFiles)
            {
                sqlName = " (itemType = " + QString::number(FILE_ELEMENT) + ") AND ((name LIKE '%" + searchCriteria + "%') ";
                if (searchInDescriptions)
                {
                    sqlName += "OR " + sqlDesc;   
                }
                sqlName += ")";
            }
            if (searchInDirs)
            {
                sqlName = " (itemType = " + QString::number(FOLDER_ELEMENT) + ") AND ((name LIKE '%" + searchCriteria + "%') ";
                if (searchInDescriptions)
                {
                    sqlName += "OR " + sqlDesc;   
                }
                sqlName += ")";
            }
        }
        */
        if (searchInFiles || searchInDirs)
        {
        	sqlC += sqlName;
            sqlF += sqlName;
        }else{
         	sqlC += sqlDesc;
            sqlF += sqlDesc;   
        }
    
        QSqlQuery *q = new QSqlQuery(dm->db);
        if (!q)
            return;
        //printQS(sqlC);
        //printQS(sqlF);
    // Delete previous items
        QTreeWidgetItem *qtwi = 0;
        while (qtwi = resultsTreeWidget->takeTopLevelItem(0))
        {
            delete qtwi;   
        }
    // Run current search
        /*
        if (q->exec(sqlC))
        {
            fillRes(q);
/*            
            QDateTime dt;
            while (q->next())
            {
            
				qlonglong _size = 0;
				int diskNo = q->value(8).toInt();
				if (!diskNames.contains(diskNo))
					diskNames[diskNo] = getDiskName(diskNo);
                CatTreeItem *item = new CatTreeItem;
//            item->setText(0, q->value(1).toString());
                item->iconId = q->value(6).toInt();
                item->itemType = q->value(2).toInt();
                item->id = q->value(0).toInt();
                item->parentId = q->value(1).toInt();
                dt.setTime_t(q->value(5).toInt());
                vFileName data;
                if (item->itemType == FILE_ELEMENT)
                {
                    parseFileName(q->value(3).toString(), data);
                    item->setText(0, data.fileName);
                }else{
                    item->setText(0, q->value(3).toString());
                }
                if (data.hasExt)
                    item->setText(1, data.fileExt);
				_size = q->value(4).toLongLong();
				item->setText(2, diskNames[diskNo]);
				item->setText(3, QString::number(_size));
                item->setText(4, dt.date().toString(Qt::LocalDate));
                item->setText(5, dt.time().toString(Qt::LocalDate));
                item->setText(6, permsToQString(q->value(7).toInt()));
                QPixmap *pix = 0;
                if (item->iconId)
                {
                    pix = dm->im->getPixmap(1, item->iconId);
                    item->setIcon(0, QIcon(*pix));
                }else{
                    if (item->itemType == FOLDER_ELEMENT)
                        pix = dm->im->getDefaultPixmap(item->itemType, 0);
                    else
                        if (item->itemType == FILE_ELEMENT)
                            pix = dm->im->getPixmap(0, data.defIcon);
                    else
                        pix = dm->im->getDefaultPixmap(item->itemType, item->fullType);
            
                    item->setIcon(0, QIcon(*pix));
                }
                delete pix;
            
            
            
                resultsTreeWidget->addTopLevelItem(item);
            
            }
            
        }
        */
        if (searchInDirs)
        {
            if (q->exec(sqlC))
            {
                fillRes(q);
            }
        }
        if (searchInFiles)
        {
            if (q->exec(sqlF))
            {
                fillRes(q);
            }
        }
        delete q;
        //printQS("Search!");
        
    }else{
        QMessageBox::critical(this, tr("Missing Criteria"), tr("Missing Search Criteria.\nPlease check at least one in the search options. "));   
    }
    
}
toTreeWidgetItem *toListView::printPage(TOPrinter *printer, QPainter *painter, toTreeWidgetItem *top, int &column, int &level, int pageNo, bool paint)
{
    Q3PaintDeviceMetrics wmetr(this);
    Q3PaintDeviceMetrics metrics(printer);

    double wpscalex = (double(metrics.width()) * wmetr.widthMM() / metrics.widthMM() / wmetr.width());
    double wpscaley = (double(metrics.height()) * wmetr.heightMM() / metrics.heightMM() / wmetr.height());

    painter->save();
    QFont font = painter->font();
    font.setPointSizeFloat(font.pointSizeFloat() / std::max(wpscalex, wpscaley));
    painter->setFont(font);

    painter->scale(wpscalex, wpscaley);

    double mwidth = metrics.width() / wpscalex;
    double mheight = metrics.height() / wpscaley;
    double x = 0;
    if (paint)
    {
        QString numPage(tr("Page: %1").arg(pageNo));
        painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex),
                          header()->height(),
                          Qt::SingleLine | Qt::AlignRight | Qt::AlignVCenter,
                          numPage);
        painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex),
                          header()->height(),
                          Qt::SingleLine | Qt::AlignHCenter | Qt::AlignVCenter,
                          middleString());
        painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex),
                          header()->height(),
                          Qt::SingleLine | Qt::AlignLeft | Qt::AlignVCenter,
                          sqlName());
        painter->drawLine(0, header()->height() - 1, int(mwidth), header()->height() - 1);
    }
    font = toListView::font();
    font.setPointSizeFloat(font.pointSizeFloat() / std::max(wpscalex, wpscaley));
    painter->setFont(font);

    for (int i = column; i < columns(); i++)
    {
        double width = columnWidth(i);
        if (width + x >= mwidth)
        {
            if (i == column)
                width = mwidth - x - 1;
            else
                break;
        }
        if (paint)
            painter->drawText(int(x), 0, int(width),
                              header()->height(),
                              Qt::SingleLine | Qt::AlignLeft | Qt::AlignVCenter, header()->label(i));
        x += width;
    }
    if (paint)
        painter->translate(0, header()->height());

    double y = (header()->height() + 1) + header()->height();
    int curLevel = level;
    int tree = rootIsDecorated() ? treeStepSize() : 0;
    int newCol = -1;
    toTreeWidgetItem *item = top;
    while (item && (y < mheight || item == top))
    {
        if (column == 0)
            x = curLevel;
        else
            x = 0;
        painter->translate(x, 0);
        for (int i = column; i < columns(); i++)
        {
            double width = columnWidth(i);
            if (width + x >= mwidth)
            {
                if (i == column)
                    width = mwidth - x - 1;
                else
                {
                    newCol = i;
                    break;
                }
            }
            if (i == 0)
                width -= curLevel;
            if (paint)
            {
                item->setSelected(false);
                item->paintCell(painter, qApp->palette().active(), i, int(width), columnAlignment(i));
                painter->translate(width, 0);
            }
            x += width;
        }
        if (paint)
            painter->translate(-x, item->height());
        y += item->height();
        if (item->firstChild())
        {
            item = item->firstChild();
            curLevel += tree;
        }
        else if (item->nextSibling())
            item = item->nextSibling();
        else
        {
            do
            {
                item = item->parent();
                curLevel -= tree;
            }
            while (item && !item->nextSibling());
            if (item)
                item = item->nextSibling();
        }
    }
    if (paint)
        painter->drawLine(0, 0, int(mwidth), 0);
    painter->restore();
    if (newCol >= 0)
    {
        column = newCol;
        return top;
    }
    column = 0;
    level = curLevel;
    return item;
}