コード例 #1
0
void SQLToolWidget::fillResultsTable(ResultSet &res)
{
    try
    {
        int col=0, row=0, row_cnt=res.getTupleCount(), col_cnt=res.getColumnCount();
        QTableWidgetItem *item=nullptr;

        row_cnt_lbl->setText(QString::number(row_cnt));
        export_tb->setEnabled(row_cnt > 0);
        results_tbw->setRowCount(0);
        results_tbw->setColumnCount(col_cnt);

        //Configuring the grid columns with the names of retrived table columns
        for(col=0; col < col_cnt; col++)
            results_tbw->setHorizontalHeaderItem(col, new QTableWidgetItem(res.getColumnName(col)));

        if(res.accessTuple(ResultSet::FIRST_TUPLE))
        {
            results_tbw->setRowCount(row_cnt);

            do
            {
                //Fills the current row with the values of current tuple
                for(col=0; col < col_cnt; col++)
                {
                    item=new QTableWidgetItem;

                    if(res.isColumnBinaryFormat(col))
                        item->setText(trUtf8("[binary data]"));
                    else
                        item->setText(res.getColumnValue(col));

                    results_tbw->setItem(row, col, item);
                }

                //Configure the vertical header to show the current tuple id
                results_tbw->setVerticalHeaderItem(row, new QTableWidgetItem(QString::number(row + 1)));
                row++;
            }
            while(res.accessTuple(ResultSet::NEXT_TUPLE));
        }

        results_tbw->resizeColumnsToContents();
    }
    catch(Exception &e)
    {
        throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
    }
}
コード例 #2
0
void SQLExecutionWidget::fillResultsTable(Catalog &catalog, ResultSet &res, QTableWidget *results_tbw, bool store_data)
{
	if(!results_tbw)
		throw Exception(ERR_OPR_NOT_ALOC_OBJECT ,__PRETTY_FUNCTION__,__FILE__,__LINE__);

	try
	{
		int col=0, row=0, col_cnt=res.getColumnCount();
		QTableWidgetItem *item=nullptr;
		vector<unsigned> type_ids;
		vector<attribs_map> types;
		map<unsigned, QString> type_names;
		unsigned orig_filter=catalog.getFilter();

		results_tbw->setRowCount(0);
		results_tbw->setColumnCount(col_cnt);
		results_tbw->verticalHeader()->setVisible(true);
		results_tbw->blockSignals(true);

		//Configuring the grid columns with the names of retrived table columns
		for(col=0; col < col_cnt; col++)
		{
			type_ids.push_back(res.getColumnTypeId(col));
			results_tbw->setHorizontalHeaderItem(col, new QTableWidgetItem(res.getColumnName(col)));
		}

		//Retrieving the data type names for each column
		catalog.setFilter(Catalog::LIST_ALL_OBJS);
		std::unique(type_ids.begin(), type_ids.end());
    types=catalog.getObjectsAttributes(OBJ_TYPE, QString(), QString(), type_ids);

    for(auto &tp : types)
			type_names[tp[ParsersAttributes::OID].toUInt()]=tp[ParsersAttributes::NAME];

		catalog.setFilter(orig_filter);

		//Assinging the type names as tooltip on header items
		for(col=0; col < col_cnt; col++)
		{
			item=results_tbw->horizontalHeaderItem(col);
			item->setToolTip(type_names[res.getColumnTypeId(col)]);
			item->setData(Qt::UserRole, type_names[res.getColumnTypeId(col)]);
		}

		if(res.accessTuple(ResultSet::FIRST_TUPLE))
		{
			results_tbw->setRowCount(res.getTupleCount());

			do
			{
				//Fills the current row with the values of current tuple
				for(col=0; col < col_cnt; col++)
				{
					item=new QTableWidgetItem;

					if(res.isColumnBinaryFormat(col))
					{
						//Binary columns can't be edited by user
						item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
						item->setText(trUtf8("[binary data]"));
					}
					else
					{
						item->setText(res.getColumnValue(col));

						if(store_data)
							item->setData(Qt::UserRole, item->text());
					}

					results_tbw->setItem(row, col, item);
				}

				//Configure the vertical header to show the current tuple id
				results_tbw->setVerticalHeaderItem(row, new QTableWidgetItem(QString::number(row + 1)));
				row++;
			}
			while(res.accessTuple(ResultSet::NEXT_TUPLE));
		}

		results_tbw->blockSignals(false);
		results_tbw->resizeColumnsToContents();
		results_tbw->resizeRowsToContents();
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}