Skip to content
Snippets Groups Projects
Commit c74a9a40 authored by Federico Montesino Pouzols's avatar Federico Montesino Pouzols
Browse files

in AssocDialog table disable rows that are empty data, re #7133

parent 68aaa1ff
No related branches found
No related tags found
No related merge requests found
......@@ -57,11 +57,11 @@ AssociationsDialog::AssociationsDialog( Graph* g, Qt::WFlags fl )
QVBoxLayout *vl = new QVBoxLayout();
QHBoxLayout *hbox1 = new QHBoxLayout ();
hbox1->addWidget(new QLabel(tr( "Spreadsheet: " )));
hbox1->addWidget(new QLabel(tr( "Spreadsheet: " )));
tableCaptionLabel = new QLabel();
hbox1->addWidget(tableCaptionLabel);
vl->addLayout(hbox1);
hbox1->addWidget(tableCaptionLabel);
vl->addLayout(hbox1);
table = new QTableWidget(3, 5);
table->horizontalHeader()->setClickable( false );
......@@ -70,26 +70,26 @@ AssociationsDialog::AssociationsDialog( Graph* g, Qt::WFlags fl )
table->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
table->setMaximumHeight(8*table->rowHeight(0));
table->setHorizontalHeaderLabels(QStringList() << tr("Column") << tr("X") << tr("Y") << tr("xErr") << tr("yErr"));
vl->addWidget(table);
vl->addWidget(table);
connect(table, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(processStateChange(QTableWidgetItem*)));
associations = new QListWidget();
associations->setSelectionMode ( QListWidget::SingleSelection );
vl->addWidget(associations);
vl->addWidget(associations);
btnApply = new QPushButton(tr( "&Update curves" ));
btnOK = new QPushButton( tr( "&OK" ) );
btnOK = new QPushButton( tr( "&OK" ) );
btnOK->setDefault( true );
btnCancel = new QPushButton( tr( "&Cancel" ) );
btnCancel = new QPushButton( tr( "&Cancel" ) );
QHBoxLayout *hbox2 = new QHBoxLayout ();
QHBoxLayout *hbox2 = new QHBoxLayout ();
hbox2->addStretch();
hbox2->addWidget(btnApply);
hbox2->addWidget(btnOK);
hbox2->addWidget(btnCancel);
vl->addStretch();
vl->addLayout(hbox2);
hbox2->addWidget(btnApply);
hbox2->addWidget(btnOK);
hbox2->addWidget(btnCancel);
vl->addStretch();
vl->addLayout(hbox2);
setLayout(vl);
active_table = 0;
......@@ -213,35 +213,58 @@ Table * AssociationsDialog::findTable(int index)
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]);
cell->setBackground (QBrush(Qt::lightGray));
cell->setFlags (Qt::ItemIsEnabled);
table->setItem(i, 0, cell);
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++ )
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);
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();
updateColumnTypes();
}
void AssociationsDialog::updateColumnTypes()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment