inline void reset( const char* const* _items, int _itemLen, char _sep, const char* _states, int _defaultState ) { /// save previous selection state std::string states; if ( _states ) { states = std::string( _states ); } /// clear clear(); /// reset if ( widget_ && _items && _itemLen > 0 ) { widget_->setSuspendUpdate( true ); widget_->itemIndices().reserve( _itemLen ); int stateLen( static_cast< int >( states.size() ) ); QTreeWidgetItem* parent = NULL; std::string fullPath; for ( int idx( 0 ); idx < _itemLen; ++idx ) { parent = NULL; fullPath.clear(); /// this variable denotes the item state, also considers the /// parent nodes bool itemState( true ); QStringList tokens; if ( _sep != '\0' ) { tokens = QStringList( QString::fromStdString( _items[ idx ] ).split( _sep, QString::SkipEmptyParts) ); } else { tokens = QStringList( QString::fromStdString( _items[ idx ] ) ); } for ( int tokenIdx( 0 ); tokenIdx < tokens.size(); ++tokenIdx ) { QString itemStr( tokens.at( tokenIdx ) ); if ( !parent ) { parent = createWidgetItem( widget_, widget_, itemStr, fullPath, stateLen, states, _defaultState ); } else { parent = createWidgetItem( parent, parent->child( 0 ), itemStr, fullPath, stateLen, states, _defaultState ); } if ( parent && itemState && ! parent->checkState( 0 ) ) { itemState = false; } fullPath = fullPath + "/" + itemStr.toStdString(); } widget_->itemIndices().append( QPair< QString, QTreeWidgetItem* >( fullPath.c_str(), parent ) ); itemStatesStr_.push_back( itemState ? '1' : '0' ); } widget_->expandAll(); widget_->setSuspendUpdate( false ); } }
void QtDataXfer::variableUpdated(const unsigned int index, const std::string& name, const std::string& description, const std::string& value, const bool modifiable) { // Don't pass itemChanged signals generated from the following code. passChangeSignals = false; // Grow the table this this index if past the last row. if (index >= static_cast<unsigned int>(table->rowCount())) { table->setRowCount(index + 1); } // Name table->setItem(index, 0, createWidgetItem(name, false)); // Mutable (checkbox) // So this is irritating. There's no good way to have an enabled, non-user-editable, // centered checkbox in a table item. So we create our own layout. QWidget *pWidget = new QWidget(); QCheckBox *pCheckBox = new QCheckBox(); QHBoxLayout *pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(pCheckBox); pLayout->setAlignment(Qt::AlignCenter); pLayout->setContentsMargins(0, 0, 0, 0); pWidget->setLayout(pLayout); pCheckBox->setChecked(modifiable); pCheckBox->setEnabled(false); table->setCellWidget(index, 1, pWidget); // Value table->setItem(index, 2, createWidgetItem(value, modifiable)); // Description table->setItem(index, 3, createWidgetItem(description, false)); passChangeSignals = true; }