Exemple #1
0
void QgsDualView::modifySort()
{
  if ( !mLayer )
    return;

  QgsAttributeTableConfig config = mConfig;

  QDialog orderByDlg;
  orderByDlg.setWindowTitle( tr( "Configure Attribute Table Sort Order" ) );
  QDialogButtonBox *dialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
  QGridLayout *layout = new QGridLayout();
  connect( dialogButtonBox, &QDialogButtonBox::accepted, &orderByDlg, &QDialog::accept );
  connect( dialogButtonBox, &QDialogButtonBox::rejected, &orderByDlg, &QDialog::reject );
  orderByDlg.setLayout( layout );

  QGroupBox *sortingGroupBox = new QGroupBox();
  sortingGroupBox->setTitle( tr( "Defined sort order in attribute table" ) );
  sortingGroupBox->setCheckable( true );
  sortingGroupBox->setChecked( !sortExpression().isEmpty() );
  layout->addWidget( sortingGroupBox );
  sortingGroupBox->setLayout( new QGridLayout() );

  QgsExpressionBuilderWidget *expressionBuilder = new QgsExpressionBuilderWidget();
  QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
  expressionBuilder->setExpressionContext( context );
  expressionBuilder->setLayer( mLayer );
  expressionBuilder->loadFieldNames();
  expressionBuilder->loadRecent( QStringLiteral( "generic" ) );
  expressionBuilder->setExpressionText( sortExpression().isEmpty() ? mLayer->displayExpression() : sortExpression() );

  sortingGroupBox->layout()->addWidget( expressionBuilder );

  QCheckBox *cbxSortAscending = new QCheckBox( tr( "Sort ascending" ) );
  cbxSortAscending->setChecked( config.sortOrder() == Qt::AscendingOrder );
  sortingGroupBox->layout()->addWidget( cbxSortAscending );

  layout->addWidget( dialogButtonBox );
  if ( orderByDlg.exec() )
  {
    Qt::SortOrder sortOrder = cbxSortAscending->isChecked() ? Qt::AscendingOrder : Qt::DescendingOrder;
    if ( sortingGroupBox->isChecked() )
    {
      setSortExpression( expressionBuilder->expressionText(), sortOrder );
      config.setSortExpression( expressionBuilder->expressionText() );
      config.setSortOrder( sortOrder );
    }
    else
    {
      setSortExpression( QString(), sortOrder );
      config.setSortExpression( QString() );
    }

    setAttributeTableConfig( config );
  }
}
Exemple #2
0
void PreferencesDialog::maintainServices() {

	QGroupBox *group = qobject_cast<QGroupBox *>(sender());

	if (group == nullptr) {
		switch (Settings::settings()->getDataService()) {
		case Settings::WeatherService::Undefined:
			m_ui->groupGoogle->setChecked(false);
			m_ui->groupWUnd->setChecked(false);
			m_ui->groupYahoo->setChecked(false);
			break;
		case Settings::WeatherService::GoogleSearch:
			m_ui->groupGoogle->setChecked(true);
			m_ui->groupWUnd->setChecked(false);
			m_ui->groupYahoo->setChecked(false);
			break;
		case Settings::WeatherService::WeatherUnderground:
			m_ui->groupGoogle->setChecked(false);
			m_ui->groupWUnd->setChecked(true);
			m_ui->groupYahoo->setChecked(false);
			break;
		case Settings::WeatherService::YahooWeather:
			m_ui->groupGoogle->setChecked(false);
			m_ui->groupWUnd->setChecked(false);
			m_ui->groupYahoo->setChecked(true);
			break;
		}
	}
	else if (group == m_ui->groupGoogle && group->isChecked()) {
		m_ui->groupWUnd->setChecked(false);
		m_ui->groupYahoo->setChecked(false);
	}
	else if (group == m_ui->groupWUnd && group->isChecked()) {
		m_ui->groupGoogle->setChecked(false);
		m_ui->groupYahoo->setChecked(false);
	}
	else if (group == m_ui->groupYahoo && group->isChecked()) {
		m_ui->groupGoogle->setChecked(false);
		m_ui->groupWUnd->setChecked(false);
	}

}
	QVariant ItemHandlerGroupbox::GetValue (QObject *object) const
	{
		QGroupBox *groupbox = qobject_cast<QGroupBox*> (object);
		if (!groupbox)
		{
			qWarning () << Q_FUNC_INFO
				<< "not a QGroupBox"
				<< object;
			return QVariant ();
		}
		return groupbox->isChecked ();
	}
///
/// \brief Form_PlatformConfiguration::traversalControl
/// \param q
/// save
///
void Form_PlatformConfiguration::traversalControl(const QObjectList& q)
{
    for(int i=0;i<q.length();i++)
    {

        if(!q.at(i)->children().empty())
        {
            traversalControl(q.at(i)->children());
        }

        QObject* o = q.at(i);
        if (o->inherits("QLineEdit"))
        {
            QLineEdit* b = qobject_cast<QLineEdit*>(o);
            QDomElement qe= doc_config.createElement(b->objectName());
            qe.setAttribute("Value",b->text());
            qe.setAttribute("Type","QLineEdit");
            doc_config.firstChildElement("root").appendChild(qe);
        }
        else if (o->inherits("QGroupBox"))
        {
            QGroupBox* b = qobject_cast<QGroupBox*>(o);
            QDomElement qe= doc_config.createElement(b->objectName());
            qe.setAttribute("Value",b->isChecked());
            qe.setAttribute("Type","QGroupBox");
            doc_config.firstChildElement("root").appendChild(qe);
        }
        else if (o->inherits("QTableWidget"))
        {
            QTableWidget * b = qobject_cast<QTableWidget*>(o);
            int col_rate = b->objectName() == "table_labels" ? 1:0;
            QDomElement qe= doc_config.createElement(b->objectName());
            qe.setAttribute("Value_R",b->rowCount());
            qe.setAttribute("Value_C",b->columnCount());
            qe.setAttribute("Type","QTableWidget");
            for(int i =0 ; i<b->rowCount() ;i++)
            {
                QDomElement item= doc_config.createElement("R"+QString::number(i));
                for(int j=0 ;j <b->columnCount()  - col_rate; j++)
                {
                    item.setAttribute("C"+QString::number(j), b->item(i,j)->text());
                }
                qe.appendChild(item);
            }
            doc_config.firstChildElement("root").appendChild(qe);
        }
    }

}
QVariant UIPropertyGetters::DefaultGetter(QWidget* editor, SettingsPropertyMapper::WidgetType editorType, SettingsPropertyMapper::PropertyType)
{
	switch (editorType)
	{
		case SettingsPropertyMapper::CHECKBOX:
		{
			QCheckBox* pCheckBox = qobject_cast<QCheckBox*>(editor);
			if (pCheckBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return QVariant();
			}
			return QVariant::fromValue(pCheckBox->isChecked());
		}
		case SettingsPropertyMapper::RADIOBUTTON:
		{
			QRadioButton* pRadioButton = qobject_cast<QRadioButton*>(editor);
			if (pRadioButton == NULL)
			{
				qCritical() << "Invalid editor given";
				return QVariant();
			}
			return QVariant::fromValue(pRadioButton->isChecked());
		}
		case SettingsPropertyMapper::CHECKABLE_GROUPBOX:
		{
			QGroupBox* pGroupBox = qobject_cast<QGroupBox*>(editor);
			if (pGroupBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return QVariant();
			}
			if (!pGroupBox->isCheckable())
			{
				qCritical() << "Given QGroupBox is not checkable";
			}
			return QVariant::fromValue(pGroupBox->isChecked());
		}
		case SettingsPropertyMapper::LINE_EDIT:
		{
			QLineEdit* pLineEdit = qobject_cast<QLineEdit*>(editor);
			if (pLineEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return QVariant();
			}
			return QVariant::fromValue(pLineEdit->text());
		}
		case SettingsPropertyMapper::TEXT_EDIT:
		{
			QTextEdit* pTextEdit = qobject_cast<QTextEdit*>(editor);
			if (pTextEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return QVariant();
			}
			return QVariant::fromValue(pTextEdit->toPlainText());
		}
		case SettingsPropertyMapper::COMBOBOX:
		{
			QComboBox* pComboBox = qobject_cast<QComboBox*>(editor);
			if (pComboBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return QVariant();
			}
			return QVariant::fromValue(pComboBox->currentIndex());
		}
		case SettingsPropertyMapper::SPINBOX:
		{
			QSpinBox* pSpinBox = qobject_cast<QSpinBox*>(editor);
			if (pSpinBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return QVariant();
			}
			return QVariant::fromValue(pSpinBox->value());
		}
		case SettingsPropertyMapper::DOUBLE_SPINBOX:
		{
			QDoubleSpinBox* pDoubleSpinBox = qobject_cast<QDoubleSpinBox*>(editor);
			if (pDoubleSpinBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return QVariant();
			}
			return QVariant::fromValue(pDoubleSpinBox->value());
		}
		case SettingsPropertyMapper::TIME_EDIT:
		{
			QTimeEdit* pTimeEdit = qobject_cast<QTimeEdit*>(editor);
			if (pTimeEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return QVariant();
			}
			return QVariant::fromValue(pTimeEdit->time());
		}
		case SettingsPropertyMapper::DATETIME_EDIT:
		{
			QDateTimeEdit* pDateTimeEdit = qobject_cast<QDateTimeEdit*>(editor);
			if (pDateTimeEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return QVariant();
			}
			return QVariant::fromValue(pDateTimeEdit->dateTime());
		}
		default:
		{
			return QVariant();
		}
	}
}
//Reading ad writing parameters from/to selected widget to/from parameters container
void SynchronizeInterfaceWindow(QWidget *window, cParameterContainer *par,
		enumReadWrite mode)
{
	WriteLog("cInterface::SynchronizeInterface: QLineEdit", 3);
	//----------- QLineEdit -------------------
	{
		QList<QLineEdit *> widgetListLineEdit = window->findChildren<QLineEdit *>();
		QList<QLineEdit *>::iterator it;

		for (it = widgetListLineEdit.begin(); it != widgetListLineEdit.end(); ++it)
		{
			//qDebug() << "QLineEdit:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl;

			QString name = (*it)->objectName();
			QString className = (*it)->metaObject()->className();
			if (name.length() > 1
					&& (className == QString("QLineEdit") || className == QString("MyLineEdit")))
			{
				QLineEdit *lineEdit = *it;
				// QString text = lineEdit->text();
				//qDebug() << name << " - text: " << text << endl;

				QString type, parameterName;
				GetNameAndType(name, &parameterName, &type);
				//qDebug() << name << " - type: " << type << endl;

				if (className == QString("MyLineEdit"))
				{
					MyLineEdit *mylineedit = (MyLineEdit*) *it;
					mylineedit->AssignParameterContainer(par);
					mylineedit->AssingParameterName(parameterName);
				}

				//----- get vectors ------------
				if (type == QString("vect3") || type == QString("logvect3"))
				{
					char lastChar = (parameterName.at(parameterName.length() - 1)).toLatin1();
					QString nameVect = parameterName.left(parameterName.length() - 2);

					if (mode == read)
					{
						double value = systemData.locale.toDouble(lineEdit->text());
						//qDebug() << nameVect << " - " << lastChar << " axis = " << value << endl;
						CVector3 vect = par->Get<CVector3>(nameVect);

						switch (lastChar)
						{
							case 'x':
								vect.x = value;
								break;

							case 'y':
								vect.y = value;
								break;

							case 'z':
								vect.z = value;
								break;

							default:
								qWarning() << "cInterface::SynchronizeInterfaceWindow(): edit field " << nameVect
										<< " has wrong axis name (is " << lastChar << ")" << endl;
								break;
						}
						par->Set(nameVect, vect);
					}
					else if (mode == write)
					{
						CVector3 vect = par->Get<CVector3>(nameVect);
						QString qtext;

						switch (lastChar)
						{
							case 'x':
								qtext = QString("%L1").arg(vect.x, 0, 'g', 16);
								break;

							case 'y':
								qtext = QString("%L1").arg(vect.y, 0, 'g', 16);
								break;

							case 'z':
								qtext = QString("%L1").arg(vect.z, 0, 'g', 16);
								break;

							default:
								qWarning() << "cInterface::SynchronizeInterfaceWindow(): edit field " << nameVect
										<< " has wrong axis name (is " << lastChar << ")" << endl;
								break;
						}
						lineEdit->setText(qtext);
						lineEdit->setCursorPosition(0);
					}
				}

				//----- get vectors 4D  ------------
				if (type == QString("vect4"))
				{
					char lastChar = (parameterName.at(parameterName.length() - 1)).toLatin1();
					QString nameVect = parameterName.left(parameterName.length() - 2);

					if (mode == read)
					{
						double value = systemData.locale.toDouble(lineEdit->text());
						//qDebug() << nameVect << " - " << lastChar << " axis = " << value << endl;
						CVector4 vect = par->Get<CVector4>(nameVect);

						switch (lastChar)
						{
							case 'x':
								vect.x = value;
								break;

							case 'y':
								vect.y = value;
								break;

							case 'z':
								vect.z = value;
								break;

							case 'w':
								vect.w = value;
								break;

							default:
								qWarning() << "cInterface::SynchronizeInterfaceWindow(): edit field " << nameVect
										<< " has wrong axis name (is " << lastChar << ")" << endl;
								break;
						}
						par->Set(nameVect, vect);
					}
					else if (mode == write)
					{
						CVector4 vect = par->Get<CVector4>(nameVect);
						QString qtext;

						switch (lastChar)
						{
							case 'x':
								qtext = QString("%L1").arg(vect.x, 0, 'g', 16);
								break;

							case 'y':
								qtext = QString("%L1").arg(vect.y, 0, 'g', 16);
								break;

							case 'z':
								qtext = QString("%L1").arg(vect.z, 0, 'g', 16);
								break;

							case 'w':
								qtext = QString("%L1").arg(vect.w, 0, 'g', 16);
								break;

							default:
								qWarning() << "cInterface::SynchronizeInterfaceWindow(): edit field " << nameVect
										<< " has wrong axis name (is " << lastChar << ")" << endl;
								break;
						}
						lineEdit->setText(qtext);
						lineEdit->setCursorPosition(0);
					}
				}

				//---------- get double scalars --------
				else if (type == QString("edit") || type == QString("logedit"))
				{
					if (mode == read)
					{
						double value = systemData.locale.toDouble(lineEdit->text());
						par->Set(parameterName, value);
					}
					else if (mode == write)
					{
						double value = par->Get<double>(parameterName);
						lineEdit->setText(QString("%L1").arg(value, 0, 'g', 16));
						lineEdit->setCursorPosition(0);
					}
				}

				//----------- get texts ------------
				else if (type == QString("text"))
				{
					if (mode == read)
					{
						QString value = lineEdit->text();
						par->Set(parameterName, value);
					}
					else if (mode == write)
					{
						QString value = par->Get<QString>(parameterName);
						lineEdit->setText(value);
					}
				}
			}
		} //end foreach
	}

	WriteLog("cInterface::SynchronizeInterface: QDoubleSpinBox", 3);
	//------------ Double spin-box --------------
	{
		QList<QDoubleSpinBox *> widgetListDoubleSpinBox = window->findChildren<QDoubleSpinBox*>();
		QList<QDoubleSpinBox *>::iterator it;
		for (it = widgetListDoubleSpinBox.begin(); it != widgetListDoubleSpinBox.end(); ++it)
		{
			QString name = (*it)->objectName();
			//qDebug() << "QDoubleSpinBox:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl;
			QString className = (*it)->metaObject()->className();
			if (name.length() > 1
					&& (className == QString("QDoubleSpinBox") || className == QString("MyDoubleSpinBox")))
			{
				QDoubleSpinBox *spinbox = *it;

				QString type, parameterName;
				GetNameAndType(name, &parameterName, &type);

				if (className == QString("MyDoubleSpinBox"))
				{
					MyDoubleSpinBox *mydoublespinbox = (MyDoubleSpinBox*) *it;
					mydoublespinbox->AssignParameterContainer(par);
					mydoublespinbox->AssingParameterName(parameterName);
				}

				if (type == QString("spinbox") || type == QString("spinboxd"))
				{
					if (mode == read)
					{
						double value = spinbox->value();
						par->Set(parameterName, value);
					}
					else if (mode == write)
					{
						double value = par->Get<double>(parameterName);
						spinbox->setValue(value);
					}
				}
				else if (type == QString("spinbox3") || type == QString("spinboxd3"))
				{
					char lastChar = (parameterName.at(parameterName.length() - 1)).toLatin1();
					QString nameVect = parameterName.left(parameterName.length() - 2);
					if (mode == read)
					{
						double value = spinbox->value();
						CVector3 vect = par->Get<CVector3>(nameVect);

						switch (lastChar)
						{
							case 'x':
								vect.x = value;
								break;

							case 'y':
								vect.y = value;
								break;

							case 'z':
								vect.z = value;
								break;

							default:
								qWarning() << "cInterface::SynchronizeInterfaceWindow(): " << type << " "
										<< nameVect << " has wrong axis name (is " << lastChar << ")" << endl;
								break;
						}
						par->Set(nameVect, vect);
					}
					else if (mode == write)
					{
						CVector3 vect = par->Get<CVector3>(nameVect);
						double value = 0;

						switch (lastChar)
						{
							case 'x':
								value = vect.x;
								break;

							case 'y':
								value = vect.y;
								break;

							case 'z':
								value = vect.z;
								break;

							default:
								qWarning() << "cInterface::SynchronizeInterfaceWindow(): " << type << " "
										<< nameVect << " has wrong axis name (is " << lastChar << ")" << endl;
								break;
						}
						spinbox->setValue(value);
					}
				}
				else if (type == QString("spinbox4") || type == QString("spinboxd4"))
				{
					char lastChar = (parameterName.at(parameterName.length() - 1)).toLatin1();
					QString nameVect = parameterName.left(parameterName.length() - 2);
					if (mode == read)
					{
						double value = spinbox->value();
						CVector4 vect = par->Get<CVector4>(nameVect);

						switch (lastChar)
						{
							case 'x':
								vect.x = value;
								break;

							case 'y':
								vect.y = value;
								break;

							case 'z':
								vect.z = value;
								break;

							case 'w':
								vect.w = value;
								break;

							default:
								qWarning() << "cInterface::SynchronizeInterfaceWindow(): " << type << " "
										<< nameVect << " has wrong axis name (is " << lastChar << ")" << endl;
								break;
						}
						par->Set(nameVect, vect);
					}
					else if (mode == write)
					{
						CVector4 vect = par->Get<CVector4>(nameVect);
						double value = 0;

						switch (lastChar)
						{
							case 'x':
								value = vect.x;
								break;

							case 'y':
								value = vect.y;
								break;

							case 'z':
								value = vect.z;
								break;

							case 'w':
								value = vect.w;
								break;

							default:
								qWarning() << "cInterface::SynchronizeInterfaceWindow(): " << type << " "
										<< nameVect << " has wrong axis name (is " << lastChar << ")" << endl;
								break;
						}
						spinbox->setValue(value);
					}
				}
			}
		}
	}

	WriteLog("cInterface::SynchronizeInterface: QSpinBox", 3);
	//------------ integer spin-box --------------
	{
		QList<QSpinBox *> widgetListDoubleSpinBox = window->findChildren<QSpinBox*>();
		QList<QSpinBox *>::iterator it;
		for (it = widgetListDoubleSpinBox.begin(); it != widgetListDoubleSpinBox.end(); ++it)
		{
			QString name = (*it)->objectName();
			//qDebug() << "QDoubleSpinBox:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl;
			QString className = (*it)->metaObject()->className();
			if (name.length() > 1
					&& (className == QString("QSpinBox") || className == QString("MySpinBox")))
			{
				QSpinBox *spinbox = *it;
				QString type, parameterName;
				GetNameAndType(name, &parameterName, &type);

				if (className == QString("MySpinBox"))
				{
					MySpinBox *myspinbox = (MySpinBox*) *it;
					myspinbox->AssignParameterContainer(par);
					myspinbox->AssingParameterName(parameterName);
				}

				if (type == QString("spinboxInt"))
				{
					if (mode == read)
					{
						int value = spinbox->value();
						par->Set(parameterName, value);
					}
					else if (mode == write)
					{
						int value = par->Get<int>(parameterName);
						spinbox->setValue(value);
					}
				}
			}
		}
	}

	WriteLog("cInterface::SynchronizeInterface: QCheckBox", 3);
	//checkboxes
	{
		QList<QCheckBox *> widgetListDoubleSpinBox = window->findChildren<QCheckBox*>();
		QList<QCheckBox *>::iterator it;
		for (it = widgetListDoubleSpinBox.begin(); it != widgetListDoubleSpinBox.end(); ++it)
		{
			QString name = (*it)->objectName();
			//qDebug() << "QCheckBox:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl;
			QString className = (*it)->metaObject()->className();
			if (name.length() > 1
					&& (className == QString("QCheckBox") || className == QString("MyCheckBox")))
			{
				QCheckBox *checkbox = *it;

				QString type, parameterName;
				GetNameAndType(name, &parameterName, &type);

				if (className == QString("MyCheckBox"))
				{
					MyCheckBox *mycheckbox = (MyCheckBox*) *it;
					mycheckbox->AssignParameterContainer(par);
					mycheckbox->AssingParameterName(parameterName);
				}

				if (type == QString("checkBox"))
				{
					if (mode == read)
					{
						bool value = checkbox->isChecked();
						par->Set(parameterName, value);
					}
					else if (mode == write)
					{
						bool value = par->Get<bool>(parameterName);
						checkbox->setChecked(value);
					}
				}
			}
		}
	}

	WriteLog("cInterface::SynchronizeInterface: QGroupBox", 3);
	//groupsBox with checkbox
	{
		QList<QGroupBox *> widgetListDoubleSpinBox = window->findChildren<QGroupBox*>();
		QList<QGroupBox *>::iterator it;
		for (it = widgetListDoubleSpinBox.begin(); it != widgetListDoubleSpinBox.end(); ++it)
		{
			QString name = (*it)->objectName();
			//qDebug() << "QGroupBox:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl;
			QString className = (*it)->metaObject()->className();
			if (name.length() > 1
					&& (className == QString("QGroupBox") || className == QString("MyGroupBox")))
			{
				QGroupBox *groupbox = *it;

				QString type, parameterName;
				GetNameAndType(name, &parameterName, &type);

				if (className == QString("MyGroupBox"))
				{
					MyGroupBox *mygroupbox = (MyGroupBox*) *it;
					mygroupbox->AssignParameterContainer(par);
					mygroupbox->AssingParameterName(parameterName);
				}

				if (type == QString("groupCheck"))
				{
					if (mode == read)
					{
						bool value = groupbox->isChecked();
						par->Set(parameterName, value);
					}
					else if (mode == write)
					{
						bool value = par->Get<bool>(parameterName);
						groupbox->setChecked(value);
					}
				}
			}
		}
	}

	WriteLog("cInterface::SynchronizeInterface: FileSelectWidget", 3);
	//---------- file select widgets -----------
	{
		QList<FileSelectWidget *> widgetListPushButton = window->findChildren<FileSelectWidget*>();
		QList<FileSelectWidget *>::iterator it;
		for (it = widgetListPushButton.begin(); it != widgetListPushButton.end(); ++it)
		{
			QString name = (*it)->objectName();
			// QString className = (*it)->metaObject()->className();
			if (name.length() > 1 && (*it)->metaObject()->className() == QString("FileSelectWidget"))
			{
				QString type, parameterName;
				GetNameAndType(name, &parameterName, &type);

				FileSelectWidget *fileSelectWidget = *it;
				fileSelectWidget->AssignParameterContainer(par);
				fileSelectWidget->AssingParameterName(parameterName);

				if (mode == read)
				{
					par->Set(parameterName, fileSelectWidget->GetPath());
				}
				else if (mode == write)
				{
					fileSelectWidget->SetPath(par->Get<QString>(parameterName));
				}
			}
		}
	}

	WriteLog("cInterface::SynchronizeInterface: MyColorButton", 3);
	//---------- color buttons -----------
	{
		QList<MyColorButton *> widgetListPushButton = window->findChildren<MyColorButton*>();
		QList<MyColorButton *>::iterator it;
		for (it = widgetListPushButton.begin(); it != widgetListPushButton.end(); ++it)
		{
			QString name = (*it)->objectName();
			// QString className = (*it)->metaObject()->className();
			if (name.length() > 1 && (*it)->metaObject()->className() == QString("MyColorButton"))
			{
				QString type, parameterName;
				GetNameAndType(name, &parameterName, &type);

				MyColorButton *colorButton = *it;
				colorButton->AssignParameterContainer(par);
				colorButton->AssingParameterName(parameterName);

				if (mode == read)
				{
					par->Set(parameterName, colorButton->GetColor());
				}
				else if (mode == write)
				{
					colorButton->setText("");
					colorButton->SetColor(par->Get<sRGB>(parameterName));
				}
			}
		}
	}

	WriteLog("cInterface::SynchronizeInterface: ColorPaletteWidget", 3);
	//---------- colorpalette -----------
	{
		QList<ColorPaletteWidget *> widgetListColorPalette =
				window->findChildren<ColorPaletteWidget*>();
		QList<ColorPaletteWidget *>::iterator it;
		for (it = widgetListColorPalette.begin(); it != widgetListColorPalette.end(); ++it)
		{
			QString name = (*it)->objectName();
			//qDebug() << "ColorPalette:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl;
			if (name.length() > 1 && (*it)->metaObject()->className() == QString("ColorPaletteWidget"))
			{
				ColorPaletteWidget *colorPaletteWidget = *it;

				QString type, parameterName;
				GetNameAndType(name, &parameterName, &type);

				colorPaletteWidget->AssignParameterContainer(par);
				colorPaletteWidget->AssingParameterName(parameterName);

				if (type == QString("colorpalette"))
				{
					if (mode == read)
					{
						cColorPalette palette = colorPaletteWidget->GetPalette();
						par->Set(parameterName, palette);
					}
					else if (mode == write)
					{
						cColorPalette palette = par->Get<cColorPalette>(parameterName);
						colorPaletteWidget->SetPalette(palette);
					}
				}
			}
		}
	}

	WriteLog("cInterface::SynchronizeInterface: QComboBox", 3);
	//combo boxes
	{
		QList<QComboBox *> widgetListPushButton = window->findChildren<QComboBox*>();
		QList<QComboBox *>::iterator it;
		for (it = widgetListPushButton.begin(); it != widgetListPushButton.end(); ++it)
		{
			QString name = (*it)->objectName();
			//qDebug() << "QComboBox:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl;
			if (name.length() > 1 && (*it)->metaObject()->className() == QString("QComboBox"))
			{
				QComboBox *comboBox = *it;

				QString type, parameterName;
				GetNameAndType(name, &parameterName, &type);

				if (type == QString("comboBox"))
				{
					if (mode == read)
					{
						int selection = comboBox->currentIndex();
						if (parameterName.left(7) == QString("formula"))
						{
							selection = fractalList[comboBox->itemData(selection).toInt()].internalID;
						}
						par->Set(parameterName, selection);
					}
					else if (mode == write)
					{
						int selection = par->Get<int>(parameterName);
						if (parameterName.left(7) == QString("formula"))
						{
							for (int i = 0; i < fractalList.size(); i++)
							{
								if (fractalList[i].internalID == selection)
								{
									selection = comboBox->findData(i);
									break;
								}
							}
						}
						comboBox->setCurrentIndex(selection);
					}
				}
			}
		}
	}

	WriteLog("cInterface::SynchronizeInterface: cMaterialSelector", 3);
	//---------- material selector -----------
	{
		QList<cMaterialSelector *> widgetListMaterialSelector =
				window->findChildren<cMaterialSelector*>();
		QList<cMaterialSelector *>::iterator it;
		for (it = widgetListMaterialSelector.begin(); it != widgetListMaterialSelector.end(); ++it)
		{
			QString name = (*it)->objectName();
			// QString className = (*it)->metaObject()->className();
			if (name.length() > 1 && (*it)->metaObject()->className() == QString("cMaterialSelector"))
			{
				QString type, parameterName;
				GetNameAndType(name, &parameterName, &type);

				cMaterialSelector *materialSelector = *it;
				materialSelector->AssignParameterContainer(par);
				materialSelector->AssingParameterName(parameterName);

				if (type == QString("materialselector"))
				{
					if (mode == read)
					{
						par->Set(parameterName, materialSelector->GetMaterialIndex());
					}
					else if (mode == write)
					{
						materialSelector->SetMaterialIndex(par->Get<int>(parameterName));
					}
				}
			}
		}
	}
	WriteLog("cInterface::SynchronizeInterface: Done", 3);
}
bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value )
{
    if ( !widget )
        return false;

    const QgsField &theField = vl->pendingFields()[idx];
    QgsVectorLayer::EditType editType = vl->editType( idx );
    bool modified = false;
    QString text;

    QSettings settings;
    QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();

    QLineEdit *le = qobject_cast<QLineEdit *>( widget );
    if ( le )
    {
        text = le->text();
        modified = le->isModified();
        if ( text == nullValue )
        {
            text = QString::null;
        }
    }

    QTextEdit *te = qobject_cast<QTextEdit *>( widget );
    if ( te )
    {
        text = te->toHtml();
        modified = te->document()->isModified();
        if ( text == nullValue )
        {
            text = QString::null;
        }
    }

    QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( widget );
    if ( pte )
    {
        text = pte->toPlainText();
        modified = pte->document()->isModified();
        if ( text == nullValue )
        {
            text = QString::null;
        }
    }

    QComboBox *cb = qobject_cast<QComboBox *>( widget );
    if ( cb )
    {
        if ( editType == QgsVectorLayer::UniqueValues ||
                editType == QgsVectorLayer::ValueMap ||
                editType == QgsVectorLayer::Classification ||
                editType == QgsVectorLayer::ValueRelation )
        {
            text = cb->itemData( cb->currentIndex() ).toString();
            if ( text == nullValue )
            {
                text = QString::null;
            }
        }
        else
        {
            text = cb->currentText();
        }
        modified = true;
    }

    QListWidget *lw = qobject_cast<QListWidget *>( widget );
    if ( lw )
    {
        if ( editType == QgsVectorLayer::ValueRelation )
        {
            text = '{';
            for ( int i = 0, n = 0; i < lw->count(); i++ )
            {
                if ( lw->item( i )->checkState() == Qt::Checked )
                {
                    if ( n > 0 )
                    {
                        text.append( ',' );
                    }
                    text.append( lw->item( i )->data( Qt::UserRole ).toString() );
                    n++;
                }
            }
            text.append( '}' );
        }
        else
        {
            text = QString::null;
        }
        modified = true;
    }

    QSpinBox *sb = qobject_cast<QSpinBox *>( widget );
    if ( sb )
    {
        text = QString::number( sb->value() );
    }

    QAbstractSlider *slider = qobject_cast<QAbstractSlider *>( widget );
    if ( slider )
    {
        text = QString::number( slider->value() );
    }

    QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>( widget );
    if ( dsb )
    {
        text = QString::number( dsb->value() );
    }

    QCheckBox *ckb = qobject_cast<QCheckBox *>( widget );
    if ( ckb )
    {
        QPair<QString, QString> states = vl->checkedState( idx );
        text = ckb->isChecked() ? states.first : states.second;
    }

    QGroupBox *gb = qobject_cast<QGroupBox *>( widget );
    if ( gb )
    {
        QPair<QString, QString> states = vl->checkedState( idx );
        text = gb->isChecked() ? states.first : states.second;
    }

    QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( widget );
    if ( cw )
    {
        text = cw->selectedDate().toString( Qt::ISODate );
    }

    le = widget->findChild<QLineEdit *>();
    // QCalendarWidget and QGroupBox have an internal QLineEdit which returns the year
    // part of the date so we need to skip this if we have a QCalendarWidget
    if ( !cw && !gb && le )
    {
        text = le->text();
    }

    switch ( theField.type() )
    {
    case QVariant::Int:
    {
        bool ok;
        int myIntValue = text.toInt( &ok );
        if ( ok && !text.isEmpty() )
        {
            value = QVariant( myIntValue );
            modified = true;
        }
        else if ( modified )
        {
            value = QVariant();
        }
    }
    break;
    case QVariant::LongLong:
    {
        bool ok;
        qlonglong myLongValue = text.toLong( &ok );
        if ( ok && !text.isEmpty() )
        {
            value = QVariant( myLongValue );
            modified = true;
        }
        else if ( modified )
        {
            value = QVariant();
        }
    }
    case QVariant::Double:
    {
        bool ok;
        double myDblValue = text.toDouble( &ok );
        if ( ok && !text.isEmpty() )
        {
            value = QVariant( myDblValue );
            modified = true;
        }
        else if ( modified )
        {
            value = QVariant();
        }
    }
    break;
    case QVariant::Date:
    {
        QDate myDateValue = QDate::fromString( text, Qt::ISODate );
        if ( myDateValue.isValid() && !text.isEmpty() )
        {
            value = myDateValue;
            modified = true;
        }
        else if ( modified )
        {
            value = QVariant();
        }
    }
    break;
    default: //string
        modified = true;
        value = QVariant( text );
        break;
    }

    return modified;
}
Exemple #8
0
void MesytecMadc32UI::uiInput(QString _name)
{
    if(applyingSettings == true) return;

    QGroupBox* gb = findChild<QGroupBox*>(_name);
    if(gb != 0)
    {
        if(_name.startsWith("enable_channel")) {
            QRegExp reg("[0-9]{1,2}");
            reg.indexIn(_name);
            int ch = reg.cap().toInt();
            if(gb->isChecked()) module->conf_.enable_channel[ch] = true;
            else module->conf_.enable_channel[ch] = false;
            printf("Changed enable_channel %d\n",ch); fflush(stdout);
        }
    }

    QCheckBox* cb = findChild<QCheckBox*>(_name);
    if(cb != 0)
    {
        if(_name == "enable_multi_event_send_different_eob_marker") {
            module->conf_.enable_multi_event_send_different_eob_marker = cb->isChecked();
        }
        if(_name == "enable_multi_event_compare_with_max_transfer_data") {
            module->conf_.enable_multi_event_compare_with_max_transfer_data = cb->isChecked();
        }
        if(_name == "enable_adc_override") {
            module->conf_.enable_adc_override = cb->isChecked();
        }
        if(_name == "enable_switch_off_sliding_scale") {
            module->conf_.enable_switch_off_sliding_scale = cb->isChecked();
        }
        if(_name == "enable_skip_out_of_range") {
            module->conf_.enable_skip_out_of_range = cb->isChecked();
        }
        if(_name == "enable_ignore_thresholds") {
            module->conf_.enable_ignore_thresholds = cb->isChecked();
        }
        if(_name == "enable_termination_input_gate0") {
            module->conf_.enable_termination_input_gate0 = cb->isChecked();
        }
        if(_name == "enable_termination_input_fast_clear") {
            module->conf_.enable_termination_input_fast_clear = cb->isChecked();
        }
        if(_name == "enable_external_time_stamp_reset") {
            module->conf_.enable_external_time_stamp_reset = cb->isChecked();
        }
        //QMessageBox::information(this,"uiInput","You changed the checkbox "+_name);
    }

    QComboBox* cbb = findChild<QComboBox*>(_name);
    if(cbb != 0)
    {
        if(_name == "addr_source") {
            module->conf_.addr_source = static_cast<MesytecMadc32ModuleConfig::AddressSource>(cbb->currentIndex());
        }
        if(_name == "multi_event_mode") {
            module->conf_.multi_event_mode = static_cast<MesytecMadc32ModuleConfig::MultiEventMode>(cbb->currentIndex());
        }
        if(_name == "data_length_format") {
            module->conf_.data_length_format = static_cast<MesytecMadc32ModuleConfig::DataLengthFormat>(cbb->currentIndex());
        }
        if(_name == "vme_mode") {
            module->conf_.vme_mode = static_cast<MesytecMadc32ModuleConfig::VmeMode>(cbb->currentIndex());
            std::cout << "Changed vme_mode to" << module->conf_.vme_mode << std::endl;
        }
        if(_name == "time_stamp_source") {
            module->conf_.time_stamp_source = static_cast<MesytecMadc32ModuleConfig::TimeStampSource>(cbb->currentIndex());
        }
        if(_name == "adc_resolution") {
            module->conf_.adc_resolution = static_cast<MesytecMadc32ModuleConfig::AdcResolution>(cbb->currentIndex());
        }
        if(_name == "output_format") {
            module->conf_.output_format = static_cast<MesytecMadc32ModuleConfig::OutputFormat>(cbb->currentIndex());
        }
        if(_name == "gate_generator_mode") {
            module->conf_.gate_generator_mode = static_cast<MesytecMadc32ModuleConfig::GateGeneratorMode>(cbb->currentIndex());
        }
        if(_name == "ecl_gate1_mode") {
            module->conf_.ecl_gate1_mode =
                    static_cast<MesytecMadc32ModuleConfig::EclGate1Mode>(cbb->currentIndex());
        }
        if(_name == "ecl_fclear_mode") {
            module->conf_.ecl_fclear_mode =
                    static_cast<MesytecMadc32ModuleConfig::EclFClearMode>(cbb->currentIndex());
        }
        if(_name == "ecl_busy_mode") {
            module->conf_.ecl_busy_mode =
                    static_cast<MesytecMadc32ModuleConfig::EclBusyMode>(cbb->currentIndex());
        }
        if(_name == "nim_gate1_mode") {
            module->conf_.nim_gate1_mode =
                    static_cast<MesytecMadc32ModuleConfig::NimGate1Mode>(cbb->currentIndex());
        }
        if(_name == "nim_fclear_mode") {
            module->conf_.nim_fclear_mode =
                    static_cast<MesytecMadc32ModuleConfig::NimFClearMode>(cbb->currentIndex());
        }
        if(_name == "nim_busy_mode") {
            module->conf_.nim_busy_mode =
                    static_cast<MesytecMadc32ModuleConfig::NimBusyMode>(cbb->currentIndex());
            if(module->conf_.nim_busy_mode == MesytecMadc32ModuleConfig::nbRes5)
                module->conf_.nim_busy_mode = MesytecMadc32ModuleConfig::nbBufOverThr;
        }
        if(_name == "input_range") {
            switch(cbb->currentIndex()) {
            case 0:
                module->conf_.input_range = MesytecMadc32ModuleConfig::ir4V;
                break;
            case 1:
                module->conf_.input_range = MesytecMadc32ModuleConfig::ir8V;
                break;
            case 2:
            default:
                module->conf_.input_range = MesytecMadc32ModuleConfig::ir10V;
                break;
            }
        }
        if(_name == "marking_type") {
            switch(cbb->currentIndex()) {
            case 0:
                module->conf_.marking_type = MesytecMadc32ModuleConfig::mtEventCounter;
                break;
            case 1:
                module->conf_.marking_type = MesytecMadc32ModuleConfig::mtTimestamp;
                break;
            case 2:
                module->conf_.marking_type = MesytecMadc32ModuleConfig::mtExtendedTs;
                break;
            default:
                module->conf_.marking_type = MesytecMadc32ModuleConfig::mtEventCounter;
                break;
            }
        }
        if(_name == "bank_operation") {
            switch(cbb->currentIndex()) {
            case 0:
                module->conf_.bank_operation = MesytecMadc32ModuleConfig::boConnected;
                break;
            case 1:
                module->conf_.bank_operation = MesytecMadc32ModuleConfig::boIndependent;
                break;
            case 2:
                module->conf_.bank_operation = MesytecMadc32ModuleConfig::boToggle;
                break;
            default:
                module->conf_.bank_operation = MesytecMadc32ModuleConfig::boConnected;
                break;
            }
        }
        if(_name == "test_pulser_mode") {
            switch(cbb->currentIndex()) {
            case 0:
                module->conf_.test_pulser_mode = MesytecMadc32ModuleConfig::tpOff;
                break;
            case 1:
                module->conf_.test_pulser_mode = MesytecMadc32ModuleConfig::tpAmp0;
                break;
            case 2:
                module->conf_.test_pulser_mode = MesytecMadc32ModuleConfig::tpAmpLow;
                break;
            case 3:
                module->conf_.test_pulser_mode = MesytecMadc32ModuleConfig::tpAmpHigh;
                break;
            case 4:
                module->conf_.test_pulser_mode = MesytecMadc32ModuleConfig::tpToggle;
                break;
            default:
                module->conf_.test_pulser_mode = MesytecMadc32ModuleConfig::tpOff;
                break;
            }
        }
        //QMessageBox::information(this,"uiInput","You changed the combobox "+_name);
    }
    QSpinBox* sb = findChild<QSpinBox*>(_name);
    if(sb != 0)
    {
        if(_name == "irq_level") module->conf_.irq_level = sb->value();
        if(_name == "irq_vector"){
            module->conf_.irq_vector = sb->value();
        }
        if(_name == "irq_threshold"){
            module->conf_.irq_threshold = sb->value();
        }
        if(_name == "base_addr_register"){
            module->conf_.base_addr_register = sb->value();
        }
        if(_name == "time_stamp_divisor"){
            module->conf_.time_stamp_divisor = sb->value();
        }
        if(_name == "max_transfer_data"){
            module->conf_.max_transfer_data= sb->value();
        }
        if(_name == "rc_module_id_read"){
            module->conf_.rc_module_id_read = sb->value();
        }
        if(_name == "rc_module_id_write"){
            module->conf_.rc_module_id_write = sb->value();
        }
        if(_name.startsWith("hold_delay_")) {
            int ch = _name.right(1).toInt();
            module->conf_.hold_delay[ch] = sb->value();
        }
        if(_name.startsWith("hold_width_")) {
            int ch = _name.right(1).toInt();
            module->conf_.hold_width[ch] = sb->value();
        }
        if(_name.startsWith("thresholds")) {
            QRegExp reg("[0-9]{1,2}");
            reg.indexIn(_name);
            int ch = reg.cap().toInt();
            module->conf_.thresholds[ch] = sb->value();
        }

    }
    QRadioButton* rb = findChild<QRadioButton*>(_name);
    if(rb != 0)
    {
        if(_name == "mcst_cblt_none" && rb->isChecked()) {
            module->conf_.cblt_mcst_ctrl = 0;
            module->conf_.mcst_cblt_none = true;
        }
        if(_name == "enable_cblt_mode" && rb->isChecked()) {
            module->conf_.cblt_mcst_ctrl |=
                    (1 << MADC32V2_OFF_CBLT_MCST_CTRL_ENABLE_CBLT);
            module->conf_.enable_cblt_mode = true;
        }
        if(_name == "enable_mcst_mode" && rb->isChecked()) {
            module->conf_.cblt_mcst_ctrl |=
                    (1 << MADC32V2_OFF_CBLT_MCST_CTRL_ENABLE_MCST);
            module->conf_.enable_mcst_mode = true;
        }
        if(_name == "enable_cblt_first" && rb->isChecked()) {
            module->conf_.cblt_mcst_ctrl |=
                    (1 << MADC32V2_OFF_CBLT_MCST_CTRL_ENABLE_FIRST_MODULE);
            module->conf_.enable_cblt_first = true;
        }
        if(_name == "enable_cblt_last" && rb->isChecked()) {
            module->conf_.cblt_mcst_ctrl |=
                    (1 << MADC32V2_OFF_CBLT_MCST_CTRL_ENABLE_LAST_MODULE);
            module->conf_.enable_cblt_last = true;
        }
        if(_name == "enable_cblt_middle" && rb->isChecked()) {
            module->conf_.cblt_mcst_ctrl &=
                    ~((1 << MADC32V2_OFF_CBLT_MCST_CTRL_ENABLE_FIRST_MODULE)
                      |(1 << MADC32V2_OFF_CBLT_MCST_CTRL_ENABLE_LAST_MODULE));
            module->conf_.enable_cblt_middle = true;
        }
    }
    QPushButton* pb = findChild<QPushButton*>(_name);
    if(pb != 0)
    {
        if(_name == "trigger_button") clicked_start_button();
        if(_name == "stop_button") clicked_start_button();
        if(_name == "stop_button") clicked_stop_button();
        if(_name == "reset_button") clicked_reset_button();
        if(_name == "fifo_reset_button") clicked_fifo_reset_button();
        if(_name == "readout_reset_button") clicked_readout_reset_button();
        if(_name == "configure_button") clicked_configure_button();
        if(_name == "counter_update_button") clicked_counter_update_button();
        if(_name == "singleshot_button") clicked_singleshot_button();
        if(_name == "update_firmware_button") clicked_update_firmware_button();
    }

}