Example #1
0
Settings::Settings(const QSettings &settingsSource)
  : m_Settings(settingsSource.fileName(), settingsSource.format())
{
  if (s_Instance != nullptr) {
    throw std::runtime_error("second instance of \"Settings\" created");
  } else {
    s_Instance = this;
  }
}
/**
 *
 * 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);
  }
}
Example #3
0
bool ContextPrivate::loadSettings( QSettings &pSettings, bool pPartial )
{
	QSettings		CFG( pSettings.fileName(), pSettings.format() );

	QList<QSharedPointer<fugio::NodeInterface>>		NodeLst;

	QMap<QUuid,QUuid>		NodeMap;
	QMap<QUuid,QUuid>		PinsMap;

	pSettings.beginGroup( "nodes" );

	for( const QString &K : pSettings.childKeys() )
	{
		QString			NodeName     = K;
		const QUuid		NodeOrigUuid = fugio::utils::string2uuid( K );
		const QUuid		NodeUuid     = ( findNode( NodeOrigUuid ).isNull() ? NodeOrigUuid : QUuid::createUuid() );
		const QUuid		ControlUuid  = fugio::utils::string2uuid( pSettings.value( K ).toString() );
		QVariantHash	NodeData;

		if( CFG.childGroups().contains( K ) )
		{
			CFG.beginGroup( K );

			NodeName = CFG.value( "name", NodeName ).toString();

			if( CFG.childGroups().contains( "settings" ) )
			{
				QStringList		VarBse;

				CFG.beginGroup( "settings" );

				loadNodeSettings( CFG, NodeData, VarBse );

				CFG.endGroup();
			}

			CFG.endGroup();
		}

		QSharedPointer<fugio::NodeInterface>	N = createNode( NodeName, NodeUuid, ControlUuid, NodeData );

		if( !N )
		{
			qWarning() << "Can't create node" << NodeName;

			continue;
		}

		NodeLst << N;

		NodeMap.insert( NodeUuid, NodeOrigUuid );
	}

	pSettings.endGroup();

	//-------------------------------------------------------------------------

	for( QSharedPointer<fugio::NodeInterface> N : NodeLst )
	{
		const QUuid		NodeUuid = N->uuid();
		const QUuid		OrigUuid = NodeMap.value( N->uuid() );

		// do this before we registerNode() to give everyone a chance to record the relabel
		// and look up data

		if( NodeUuid != OrigUuid )
		{
			emit qobject()->nodeRelabled( OrigUuid, NodeUuid );
		}

		registerNode( N );

		pSettings.beginGroup( fugio::utils::uuid2string( OrigUuid ) );

		N->loadSettings( pSettings, PinsMap, pPartial );

		pSettings.endGroup();
	}

	//-------------------------------------------------------------------------

//	CFG.beginGroup( "connections" );

//	foreach( const QString &NodeDst, CFG.childGroups() )
//	{
//		CF2.beginGroup( NodeDst );

//		foreach( const QString &PinDst, CFG.childKeys() )
//		{
//			QStringList		 SrcList = CFG.value( PinDst ).toString().split( '\\' );

//			if( SrcList.size() != 2 )
//			{
//				continue;
//			}

//			mConnectionMap.insert( ConnectionPair( SrcList.at( 0 ), SrcList.at( 1 ) ), ConnectionPair( NodeDst, PinDst ) );
//		}

//		CFG.endGroup();
//	}

//	CFG.endGroup();

	//-------------------------------------------------------------------------

	pSettings.beginGroup( "connections" );

	for( const QString &G : pSettings.childKeys() )
	{
		QUuid		SrcId = PinsMap.value( fugio::utils::string2uuid( G ) );

		PinHash::iterator		SrcIt = mPinHash.find( SrcId );

		if( SrcIt == mPinHash.end() )
		{
			qWarning() << "SRC PIN NOT FOUND" << SrcId;

			continue;
		}

		QSharedPointer<fugio::PinInterface>	SrcP = SrcIt.value();

		if( SrcP == 0 )
		{
			continue;
		}

		QUuid		DstId = PinsMap.value( fugio::utils::string2uuid( pSettings.value( G ).toString() ) );

		PinHash::iterator		DstIt = mPinHash.find( DstId );

		if( DstIt == mPinHash.end() )
		{
			qWarning() << "DST PIN NOT FOUND" << DstId;

			continue;
		}

		QSharedPointer<fugio::PinInterface>	DstP = DstIt.value();

		if( DstP == 0 )
		{
			continue;
		}

		connectPins( SrcP->globalId(), DstP->globalId() );
	}

	pSettings.endGroup();

	return( true );
}