/**
 *
 * read/write saves the column width and order
 * set a default column width
 * if we have saved state, use it
 * otherwise if we have 'columns' set the sizes from that, provided there are as many entries as
 * there are columns
 *
 * The passed QSettings is cloned, so the calling routine can do what it wants
 *
 * @param settings a QSettings pointing at the correct group
 */
void ColumnarTableWidget::readConfiguration(QSettings & settings) {

  m_settings = new QSettings(settings.fileName(),settings.format());
  m_settings->setIniCodec(settings.iniCodec());
  m_settings->beginGroup(settings.group());
  if (m_defaultWidth == -1) {
    m_defaultWidth = 200;
  }
  m_defaultWidth = settings.value(m_defaultWidthKey,m_defaultWidth).toInt();
  this->horizontalHeader()->setDefaultSectionSize(m_defaultWidth);
  QByteArray b = settings.value(m_stateKey,QByteArray()).toByteArray();
  if (b.size() > 0) {
    this->horizontalHeader()->restoreState(b);
  }
  else {
    bool ok;
    int w;
    QList<int> sections;
    QStringList v = settings.value(m_columnWidthsKey).toStringList();
    for(int i=0;i < v.size();i++) {
      w = v[i].toInt(&ok);
      if (ok) {
        if (w == -1) {
          w = m_defaultWidth;
        }
        sections << w;
      }
    }
    if (sections.size() == m_columnHeadings.size()) {
      for(int i=0;i < sections.size();i++) {
        this->setColumnWidth(i,sections[i]);
      }
    }
  }
  if (m_markColumn != -1) {
    this->resizeColumnToContents(m_markColumn);
  }
}