Example #1
0
void AssociationsDialog::updateTable(int index)
{
	Table *t = findTable(index);
	if (!t)
		return;

	if (active_table != t){
		active_table = t;
		tableCaptionLabel->setText(t->objectName());
		table->clearContents();
		table->setRowCount(t->numCols());

		QStringList colNames = t->colNames();
		for (int i=0; i<table->rowCount(); i++ ){
			QTableWidgetItem *cell = new QTableWidgetItem(colNames[i].replace(",", "."));
			cell->setBackground (QBrush(Qt::lightGray));
			cell->setFlags (Qt::ItemIsEnabled);
			table->setItem(i, 0, cell);
			}

		for (int j=1; j < table->columnCount(); j++){
			for (int i=0; i < table->rowCount(); i++ )
				{
				QTableWidgetItem *cell = new QTableWidgetItem();
				cell->setBackground (QBrush(Qt::lightGray));
				table->setItem(i, j, cell);

				QCheckBox* cb = new QCheckBox(table);
				cb->installEventFilter(this);
				table->setCellWidget(i, j, cb);
				}
			}
		}
	updateColumnTypes();
}
Example #2
0
void AssociationsDialog::updateTable(int index)
{
  Table *t = findTable(index);
  if (!t)
    return;

  if (active_table != t)
  {
    active_table = t;
    tableCaptionLabel->setText(t->objectName());
    table->clearContents();
    table->setRowCount(t->numCols());

    QStringList colNames = t->colNames();
    // this vector will tell which rows should be disabled (cause there's no data in them)
    std::vector<bool> disableRow;
    disableRow.resize(table->rowCount(), false);
    for (int i=0; i<table->rowCount(); i++ )
    {
      QTableWidgetItem *cell = new QTableWidgetItem(colNames[i]);
      cell->setBackground (QBrush(Qt::lightGray));
      cell->setFlags (Qt::ItemIsEnabled);
      table->setItem(i, 0, cell);

      // do we need to disable this row cause the corresponding curve it's empty?
      // (empty curves could cause crashes in many other places)
      bool allEmpty = true;
      // Note possible confusion, here 'table' is the table that you see in the AssociationsDialog,
      // whereas t is the underlying data table (spreadsheet).
      for (int dataRow = 0; dataRow < t->numRows() && allEmpty; dataRow++)
      {
        // use i (row in the associations table) as column index
        allEmpty = allEmpty & t->text(dataRow, i).isEmpty();
      }
      if (allEmpty)
        disableRow[i] = true;
    }

    for (int j=1; j < table->columnCount(); j++)
    {
      for (int i=0; i < table->rowCount(); i++ )
      {
          QTableWidgetItem *cell = new QTableWidgetItem();
          cell->setBackground(QBrush(Qt::lightGray));
          cell->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
          table->setItem(i, j, cell);

          // disable (but keep the checkbox, as set above)
          if (disableRow[i])
            cell->setFlags(Qt::NoItemFlags);
      }
    }
  }
  updateColumnTypes();
}