Gnats 4697: TableSeriesSlot not setting column labels correctly. //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- (1) THIS WORKS, see updateAllBlockColNames() /* virtual */ void TableSlot::appendBlock (bool notify /*=true*/) { // Check if we're even supposed to expando this slot if (getBlockSize() == -1) return; // Check if the block size is at least equal to the number of // columns we currently have. if (getBlockSize() > numColumns()) return; for (int col = 0; col < getBlockSize(); col++) { appendColumn (false); // no notify copyColConfig (col, numColumns() - 1); // >>> } SlotStatusChangeData::incrementSerialNum(); if (notify) { // Only update all the column labels if this isn't a bulk operation updateAllBlockColNames(); SLOT_STATUS_CHANGED_CALLBACK (this, TABLESLOT_COLUMN_COUNT_CHANGED); } SLOT_STATUS_CHANGED_CALLBACK (this, TABLESLOT_SIZE_CHANGED); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- (2) THIS PROBABLY WORKS TOO, see updateAllBlockColNames() bool TableSlot::setBlockCount (int newCount, bool notify /*=true*/) { const int initCount (getNumBlocks()); const int blockSize (getBlockSize()); // Check if we're even supposed to expand this slot if (numColumns() < 1 || blockSize < 1) return true; int oldCount (initCount); // Append blocks as necessary // (could be rewritten to be slightly more efficient) while (newCount > oldCount) { appendBlock (false); // no notify oldCount++; } // Delete blocks as necessary while (newCount < oldCount) { removeLastBlock (false); // no notify oldCount--; } // Only update all the column labels if this isn't a bulk operation updateAllBlockColNames(); if (notify) { SlotStatusChangeData::incrementSerialNum(); SLOT_STATUS_CHANGED_CALLBACK (this, TABLESLOT_COLUMN_COUNT_CHANGED); } return false; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // virtual void TableSlot::resize (int nrows, int ncols, int changeEndRow /*=true*/) { if ( (nrows == _rowDimension) && (ncols == _colDimension) ) { syncColMapSize(); return; } int row, col; cwArray2 *newTable = new cwArray2 (nrows, ncols); if (_table) { if (changeEndRow) newTable->copy(_table, INVALIDVALUE, true); else newTable->copy(_table, INVALIDVALUE, false); delete _table; _table = NULL; } // Otherwise initialize the values else { for (row = 0; row < nrows; ++row) for (col = 0; col < ncols; ++col) (*newTable)(row, col) = INVALIDVALUE; } _table = newTable; // Only update row labels if the number of rows changed if (nrows != _rowDimension) { cwArray *newRowLabels = new cwArray (nrows); if (_rowLabels) { if (changeEndRow) newRowLabels->copy(_rowLabels, "", true); else newRowLabels->copy(_rowLabels, "", false); delete _rowLabels; } // Otherwise initialize the values else { for (row = 0; row < nrows; ++row) (*newRowLabels)[row] = RWCString(""); } _rowLabels = newRowLabels; } // Only update col labels, maxs, mins, scaled units, formats, and // precisions if the number of columns changed. if (ncols != _colDimension) { cwArray *newColumnLabels = new cwArray (ncols); if (_colLabels) { newColumnLabels->copy(_colLabels, ""); delete _colLabels; } // Otherwise initialize the values else { for (col = 0; col < ncols; ++col) (*newColumnLabels)[col] = RWCString(""); } _colLabels = newColumnLabels; cwArray *newMaximums = new cwArray (ncols); if (_maximums) { newMaximums->copy(_maximums, INVALIDVALUE); delete _maximums; } // Otherwise initialize the values else { for (col = 0; col < ncols; ++col) (*newMaximums)[col] = INVALIDVALUE; } _maximums = newMaximums; cwArray *newMinimums = new cwArray (ncols); if (_minimums) { newMinimums->copy(_minimums, INVALIDVALUE); delete _minimums; } // Otherwise initialize the values else { for (col = 0; col < ncols; ++col) (*newMinimums)[col] = INVALIDVALUE; } _minimums = newMinimums; ScaledUnitPtr scaledUnit = unitMgr->getScaledUnit(NOUNITS); if (_scaledUnits != NULL) { cwArray* newScaledUnits = new cwArray (ncols, NULL); newScaledUnits->copy(_scaledUnits, scaledUnit); delete _scaledUnits; _scaledUnits = newScaledUnits; } else { _scaledUnits = new cwArray (ncols, scaledUnit); } cwArray *newUsrFormat = new cwArray (ncols); if (_usrFormat) { newUsrFormat->copy(_usrFormat, defaultFormat); delete _usrFormat; } // Otherwise initialize the values else { for (col = 0; col < ncols; ++col) (*newUsrFormat)[col] = defaultFormat.data(); } _usrFormat = newUsrFormat; cwArray *newUsrPrecision = new cwArray (ncols); if (_usrPrecision) { // use the previous column precision if there is one, 2 otherwise int previousPrecision = 2; if (_colDimension > 0) previousPrecision = (* _usrPrecision)[_colDimension - 1]; newUsrPrecision->copy(_usrPrecision, previousPrecision); delete _usrPrecision; } // Otherwise initialize the values else { for (col = 0; col < ncols; ++col) (*newUsrPrecision)[col] = 2; } _usrPrecision = newUsrPrecision; } bool colCntChange (_colDimension != ncols); _rowDimension = nrows; _colDimension = ncols; syncColMapSize(); SlotStatusChangeData::incrementSerialNum(); if (colCntChange) { SLOT_STATUS_CHANGED_CALLBACK (this, TABLESLOT_COLUMN_COUNT_CHANGED); } SLOT_STATUS_CHANGED_CALLBACK (this, TABLESLOT_SIZE_CHANGED); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void TableSlot::updateAllBlockColNames () { static const char (*mname) ("TableSlot::updateAllBlockColNames"); if (numColumns() < 1 || getBlockSize() < 1) return; const SimObj* simObj = getSimObj(); bool autoColRelab = !simObj || simObj->autoColumnRelabelingSupported (this); if (!autoColRelab) { // std::cout << mname << " Disabled for: " << getCompleteName() // << std::endl; return; } // Get the old label for each column in the first // block, taking out any numeric digits. std::vector colNames; for (int col = 0; col < getBlockSize(); col++) { const RWCString oldColLabel (getColumnLabel(col)); if (!rwAssert (oldColLabel.length() < MAX_BUF)) return; //--------------------------------------------------->> char labelBuffer [MAX_BUF]; strcpy(labelBuffer, oldColLabel.data()); // std::cout << mname << " " << getCompleteName() // << " Old [" << col << "]: " // << oldColLabel << std::endl; // labelPtr Points to start of label, and charPtr backs up // from the end of the label, looking for digits char *charPtr = labelBuffer; int labelLength = strlen(labelBuffer); if (labelLength != 0) { // Now points to the end charPtr += labelLength - 1; // Take out digits, but don't back up too far while (isdigit(*charPtr)) { *charPtr = '\0'; if (charPtr == labelBuffer) break; else charPtr--; } } colNames.push_back(labelBuffer); } for (int colNum = 0; colNum < numColumns(); colNum++) { const RWCString baseColName = colNames[(colNum % getBlockSize())]; // Tack the block number onto the column name const int blockNum = (colNum / getBlockSize()); char colNumStr[MAX_BUF]; sprintf(colNumStr, "%d", blockNum+1); const RWCString newColLabel (baseColName + colNumStr); // std::cout << mname << " " << getCompleteName() // << " New [" << colNum << "]: " // << newColLabel << std::endl; setColumnLabel(colNum, newColLabel); } } ---