void DeviceWizardOptions::specBox() { QGroupBox *gbSpecs = new QGroupBox(); gbSpecs->setTitle("Specifications"); QGridLayout *layout = new QGridLayout(); gbSpecs->setLayout(layout); this->layout()->addWidget(gbSpecs); QLabel *channelLabel = new QLabel("Number of channels"); layout->addWidget(channelLabel, 0, 0); QSpinBox *channels = new QSpinBox(); channels->setMinimum(1); channels->setMaximum(2); channels->setValue(1); layout->addWidget(channels, 1, 0, 1, 3); QLabel *voltageLabel = new QLabel("Voltage Range"); layout->addWidget(voltageLabel, 2, 0, 1, 2); QLabel *accLabel = new QLabel("Read back Accuracy"); layout->addWidget(accLabel, 2, 2); QDoubleSpinBox *voltLow = new QDoubleSpinBox(); voltLow->setMinimum(-50); voltLow->setMaximum(100); voltLow->setDecimals(1); voltLow->setSingleStep(0.1); voltLow->setValue(0.0); voltLow->setSuffix("V"); layout->addWidget(voltLow, 3, 0); QDoubleSpinBox *voltHigh = new QDoubleSpinBox(); voltHigh->setMinimum(0); voltHigh->setMaximum(100); voltHigh->setDecimals(1); voltHigh->setSingleStep(0.1); voltHigh->setValue(31.0); voltHigh->setSuffix("V"); layout->addWidget(voltHigh, 3, 1); QComboBox *voltAccCombo = new QComboBox(); voltAccCombo->addItems({"1V", "100mV", "10mV", "1mV"}); voltAccCombo->setCurrentIndex(2); // 10mV default layout->addWidget(voltAccCombo, 3, 2); QLabel *currentLabel = new QLabel("Current Range"); layout->addWidget(currentLabel, 4, 0, 1, 2); QDoubleSpinBox *currentLow = new QDoubleSpinBox(); currentLow->setMinimum(0); currentLow->setMaximum(10); currentLow->setDecimals(1); currentLow->setSingleStep(0.1); currentLow->setValue(0.0); currentLow->setSuffix("A"); layout->addWidget(currentLow, 5, 0); QDoubleSpinBox *currentHigh = new QDoubleSpinBox(); currentHigh->setMinimum(0); currentHigh->setMaximum(10); currentHigh->setDecimals(1); currentHigh->setSingleStep(0.1); currentHigh->setValue(5.1); currentHigh->setSuffix("A"); layout->addWidget(currentHigh, 5, 1); QComboBox *currentAccCombo = new QComboBox(); currentAccCombo->addItems({"1A", "100mA", "10mA", "1mA"}); currentAccCombo->setCurrentIndex(3); // 1mA default layout->addWidget(currentAccCombo, 5, 2); registerField("channel", channels); registerField("voltLow", voltLow, "value", "valueChanged"); registerField("voltHigh", voltHigh, "value", "valueChanged"); registerField("voltAcc", voltAccCombo); registerField("currentLow", currentLow, "value", "valueChanged"); registerField("currentHigh", currentHigh, "value", "valueChanged"); registerField("currentAcc", currentAccCombo); }
void RGBMatrixEditor::displayProperties(RGBScript *script) { if (script == NULL) return; int gridRowIdx = 0; QList<RGBScriptProperty> properties = script->properties(); if (properties.count() > 0) m_propertiesGroup->show(); foreach(RGBScriptProperty prop, properties) { switch(prop.m_type) { case RGBScriptProperty::List: { QLabel *propLabel = new QLabel(prop.m_displayName); m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0); QComboBox *propCombo = new QComboBox(this); propCombo->addItems(prop.m_listValues); propCombo->setProperty("pName", prop.m_name); connect(propCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotPropertyComboChanged(QString))); m_propertiesLayout->addWidget(propCombo, gridRowIdx, 1); if (m_matrix != NULL) { QString pValue = m_matrix->property(prop.m_name); if (!pValue.isEmpty()) #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) propCombo->setCurrentText(pValue); #else propCombo->setCurrentIndex(propCombo->findText(pValue)); #endif else { pValue = script->property(prop.m_name); if (!pValue.isEmpty()) #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) propCombo->setCurrentText(pValue); #else propCombo->setCurrentIndex(propCombo->findText(pValue)); #endif } } gridRowIdx++; } break; case RGBScriptProperty::Range: { QLabel *propLabel = new QLabel(prop.m_displayName); m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0); QSpinBox *propSpin = new QSpinBox(this); propSpin->setRange(prop.m_rangeMinValue, prop.m_rangeMaxValue); propSpin->setProperty("pName", prop.m_name); connect(propSpin, SIGNAL(valueChanged(int)), this, SLOT(slotPropertySpinChanged(int))); m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1); if (m_matrix != NULL) { QString pValue = m_matrix->property(prop.m_name); if (!pValue.isEmpty()) propSpin->setValue(pValue.toInt()); else { pValue = script->property(prop.m_name); if (!pValue.isEmpty()) propSpin->setValue(pValue.toInt()); } } gridRowIdx++; } break; default: qWarning() << "Type" << prop.m_type << "not handled yet"; break; }
void DeviceWizardOptions::comBox() { QGroupBox *gbCom = new QGroupBox(); gbCom->setTitle("Communication"); gbCom->setLayout(new QVBoxLayout()); this->layout()->addWidget(gbCom); this->comPort = new QComboBox(); this->comPort->setToolTip( "Choose the port to which your device is connected"); gbCom->layout()->addWidget(this->comPort); QGridLayout *baudFlowDBits = new QGridLayout(); dynamic_cast<QVBoxLayout *>(gbCom->layout())->addLayout(baudFlowDBits); QLabel *baudLabel = new QLabel("Baud Rate"); QComboBox *baudBox = new QComboBox(); baudBox->addItems( {"1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200"}); baudBox->setCurrentText("9600"); baudFlowDBits->addWidget(baudLabel, 0, 0); baudFlowDBits->addWidget(baudBox, 1, 0); QLabel *flowctlLabel = new QLabel("Flow Control"); QComboBox *flowctlBox = new QComboBox(); flowctlBox->addItems( {"No flow control", "Hardware flow control", "Software flow control"}); flowctlBox->setCurrentIndex(0); baudFlowDBits->addWidget(flowctlLabel, 0, 1); baudFlowDBits->addWidget(flowctlBox, 1, 1); QLabel *dbitsLabel = new QLabel("Data Bits"); QComboBox *dbitsBox = new QComboBox(); dbitsBox->addItems({"5", "6", "7", "8"}); dbitsBox->setCurrentText("8"); baudFlowDBits->addWidget(dbitsLabel, 0, 2); baudFlowDBits->addWidget(dbitsBox, 1, 2); QLabel *parityLabel = new QLabel("Parity"); QComboBox *parityBox = new QComboBox(); parityBox->addItem("No Parity", 0); parityBox->addItem("Even Parity", 2); parityBox->addItem("Odd Parity", 3); parityBox->addItem("Space Parity", 4); parityBox->addItem("Mark Parity", 5); parityBox->setCurrentIndex(0); baudFlowDBits->addWidget(parityLabel, 2, 0); baudFlowDBits->addWidget(parityBox, 3, 0); QLabel *stopLabel = new QLabel("Stop Bits"); QComboBox *stopBox = new QComboBox(); stopBox->addItem("1", 1); stopBox->addItem("1.5", 3); stopBox->addItem("2", 2); stopBox->setCurrentIndex(0); baudFlowDBits->addWidget(stopLabel, 2, 1); baudFlowDBits->addWidget(stopBox, 3, 1); QLabel *pollingFreqLabel = new QLabel("Polling frequency"); QComboBox *pollFreqBox = new QComboBox(); pollFreqBox->setToolTip("Polling Frequency in Hertz"); pollFreqBox->addItem("10 Hz", 100); pollFreqBox->addItem("5 Hz", 200); pollFreqBox->addItem("2 Hz", 500); pollFreqBox->addItem("1 Hz", 1000); pollFreqBox->addItem("0.5 Hz", 2000); pollFreqBox->addItem("0.2 Hz", 5000); pollFreqBox->addItem("0.1 Hz", 10000); pollFreqBox->setCurrentIndex(1); baudFlowDBits->addWidget(pollingFreqLabel, 4, 0); baudFlowDBits->addWidget(pollFreqBox, 5, 0); QLabel *sportTimeoutLabel = new QLabel("Serial port timeout"); QSpinBox *sportTimeout = new QSpinBox(); sportTimeout->setMinimum(1); sportTimeout->setMaximum(10000); sportTimeout->setSuffix("ms"); sportTimeout->setValue(10); sportTimeout->setToolTip( "Time in Milliseconds the Serialport will wait \n" "for an answer from the device. Tuning this option \n" "might improve communication resulting in a higher \n" "polling frequency. If this value is to low you \n" "will encounter partial or complete data loss on \n" "the serial port connection."); baudFlowDBits->addWidget(sportTimeoutLabel, 4, 1); baudFlowDBits->addWidget(sportTimeout, 5, 1); // we need the comport string not index registerField("comPort", this->comPort, "currentText"); registerField("baudBox", baudBox, "currentText"); registerField("flowctlBox", flowctlBox); registerField("dbitsBox", dbitsBox, "currentText"); registerField("parityBox", parityBox, "currentData"); registerField("stopBox", stopBox, "currentData"); registerField("pollFreqBox", pollFreqBox, "currentData"); registerField("sportTimeout", sportTimeout); }
QWidget* QmitkPropertyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option , const QModelIndex &index) const { QVariant data = index.data(Qt::EditRole); QVariant displayData = index.data(Qt::DisplayRole); QString name = index.model()->data(index.model()->index(index.row(), index.column()-1)).value<QString>(); if(data.isValid()) { QWidget* editorWidget = NULL; if(data.type() == QVariant::Color) { QPushButton* colorBtn = new QPushButton(parent); QColor color = data.value<QColor>(); QColor result = QColorDialog::getColor(color); if(result.isValid()) { QPalette palette = colorBtn->palette(); palette.setColor(QPalette::Button, result); colorBtn->setPalette(palette); colorBtn->setStyleSheet(QString("background-color: %1;foreground-color: %1; border-style: none;").arg(result.name())); //colorBtn->setFlat(true); } // QColorDialog closed by 'Cancel' button, use the old property color else { QPalette palette = colorBtn->palette(); palette.setColor(QPalette::Button, color); colorBtn->setPalette(palette); colorBtn->setStyleSheet(QString("background-color: %1;foreground-color: %1; border-style: none;").arg(color.name())); } connect(colorBtn, SIGNAL(pressed()), this, SLOT(commitAndCloseEditor())); editorWidget = colorBtn; } /* else if(data.type() == QVariant::Bool) { QCheckBox *visibilityCheckBox = new QCheckBox(parent); connect(visibilityCheckBox, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return visibilityCheckBox; }*/ else if(data.type() == QVariant::Int) { QSpinBox* spinBox = new QSpinBox(parent); spinBox->setSingleStep(1); spinBox->setMinimum(std::numeric_limits<int>::min()); spinBox->setMaximum(std::numeric_limits<int>::max()); editorWidget = spinBox; } // see qt documentation. cast is correct, it would be obsolete if we // store doubles else if(static_cast<QMetaType::Type>(data.type()) == QMetaType::Float) { QDoubleSpinBox* spinBox = new QDoubleSpinBox(parent); spinBox->setDecimals(2); spinBox->setSingleStep(0.1); if(name == "opacity") { spinBox->setMinimum(0.0); spinBox->setMaximum(1.0); } else { spinBox->setMinimum(std::numeric_limits<float>::min()); spinBox->setMaximum(std::numeric_limits<float>::max()); } editorWidget = spinBox; } else if(data.type() == QVariant::StringList) { QStringList entries = data.value<QStringList>(); QComboBox* comboBox = new QComboBox(parent); comboBox->setEditable(false); comboBox->addItems(entries); editorWidget = comboBox; } else { editorWidget = QStyledItemDelegate::createEditor(parent, option, index); } if ( editorWidget ) { // install event filter editorWidget->installEventFilter( const_cast<QmitkPropertyDelegate*>(this) ); } return editorWidget; } else return new QLabel(displayData.toString(), parent); }
QWidget *GrainDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &index) const { QComboBox *combo; QDoubleSpinBox *spin; QString suffix; // can only edit name on blank row if (index.row() >= index.model()->rowCount()) return 0; // different kind of editor for each column switch (index.column()) { case GrainModel::NAME: combo = new QComboBox(parent); combo->setEditable(true); combo->addItem(QString()); combo->addItems(Data::instance()->grainsList()); combo->installEventFilter(const_cast<GrainDelegate*>(this)); return combo; case GrainModel::WEIGHT: spin = new QDoubleSpinBox(parent); spin->setDecimals(3); spin->setRange(0.00, 1000.00); spin->setSingleStep(0.25); spin->setAccelerated(true); suffix = " " + Data::instance()->defaultGrainUnit().symbol(); spin->setSuffix(suffix); spin->installEventFilter(const_cast<GrainDelegate*>(this)); return spin; case GrainModel::EXTRACT: spin = new QDoubleSpinBox(parent); spin->setDecimals(3); spin->setRange(1.000, 1.100); spin->setSingleStep(0.001); spin->setAccelerated(true); spin->installEventFilter(const_cast<GrainDelegate*>(this)); return spin; case GrainModel::COLOR: spin = new QDoubleSpinBox(parent); spin->setDecimals(1); spin->setRange(0.0, 500.0); spin->setSingleStep(1.0); spin->setSuffix(Resource::DEGREE); spin->setAccelerated(true); spin->installEventFilter(const_cast<GrainDelegate*>(this)); return spin; case GrainModel::TYPE: combo = new QComboBox(parent); combo->setEditable(false); combo->addItems(Grain::typeStringList()); combo->installEventFilter(const_cast<GrainDelegate*>(this)); return combo; case GrainModel::USE: combo = new QComboBox(parent); combo->setEditable(false); combo->addItems(Grain::useStringList()); combo->installEventFilter(const_cast<GrainDelegate*>(this)); return combo; default: return 0; } }
void ParameterTable::updateTable(const CReactionInterface & ri, const CModel & model) { //first get the units strings CFindDimensions units(ri.getFunction(), model.getQuantityUnitEnum() == CModel::dimensionlessQuantity, model.getVolumeUnitEnum() == CModel::dimensionlessVolume, model.getTimeUnitEnum() == CModel::dimensionlessTime, model.getAreaUnitEnum() == CModel::dimensionlessArea, model.getLengthUnitEnum() == CModel::dimensionlessLength ); units.setUseHeuristics(true); units.setMolecularitiesForMassAction(ri.getChemEqInterface().getMolecularity(CFunctionParameter::SUBSTRATE), ri.getChemEqInterface().getMolecularity(CFunctionParameter::PRODUCT)); units.findDimensions(ri.isMulticompartment()); size_t i, imax = ri.size(); size_t j, jmax; size_t rowCounter = 0; QStringList qsl; QColor subsColor(255, 210, 210); QColor prodColor(210, 255, 210); QColor modiColor(250, 250, 190); QColor paraColor(210, 210, 255); QColor volColor(210, 210, 255); QColor timeColor(210, 210, 210); CFunctionParameter::Role usage; QString qUsage; QColor color; const std::vector<std::string> * metabNames; mIndex2Line.resize(imax); mLine2Index.clear(); this->setRowCount(0); this->setRowCount((int)(imax * 2)); for (i = 0; i < imax; ++i) { rowCounter++; mIndex2Line[i] = rowCounter; // set the stuff that is different for the specific usages usage = ri.getUsage(i); qUsage = FROM_UTF8(CFunctionParameter::RoleNameDisplay[usage]); switch (usage) { case CFunctionParameter::SUBSTRATE: color = subsColor; break; case CFunctionParameter::PRODUCT: color = prodColor; break; case CFunctionParameter::MODIFIER: color = modiColor; break; case CFunctionParameter::PARAMETER: color = paraColor; break; case CFunctionParameter::VOLUME: color = volColor; break; case CFunctionParameter::TIME: color = timeColor; break; case CFunctionParameter::VARIABLE: color = QColor(255, 20, 20); break; default: qUsage = "unknown"; color = QColor(255, 20, 20); break; } // add first column QTableWidgetItem * pItem = new ColorTableItem(color, qUsage); if (usage == CFunctionParameter::SUBSTRATE) pItem->setIcon(CQIconResource::icon(CQIconResource::reactionSubstrate)); if (usage == CFunctionParameter::PRODUCT) pItem->setIcon(CQIconResource::icon(CQIconResource::reactionProduct)); if (usage == CFunctionParameter::MODIFIER) pItem->setIcon(CQIconResource::icon(CQIconResource::reactionModifier)); setItem((int) rowCounter, 0, pItem); // add second column pItem = new ColorTableItem(color, FROM_UTF8(ri.getParameterName(i))); if ((usage != CFunctionParameter::PARAMETER) && (usage != CFunctionParameter::VOLUME) && (usage != CFunctionParameter::TIME)) { if (ri.isLocked(i)) pItem->setIcon(CQIconResource::icon(CQIconResource::locked)); else pItem->setIcon(CQIconResource::icon(CQIconResource::unlocked)); } setItem((int) rowCounter, 1, pItem); // add third column pItem = new ColorTableItem(color, ""); if (usage == CFunctionParameter::PARAMETER) { pItem->setFlags(pItem->flags() | Qt::ItemIsUserCheckable); pItem->setCheckState(ri.isLocalValue(i) ? Qt::Unchecked : Qt::Checked); } setItem((int) rowCounter, 2, pItem); // add units column assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0]; assert(pDataModel != NULL); pItem = new ColorTableItem(color, FROM_UTF8(" " + units.getDimensions()[i].getDisplayString(pDataModel))); setItem((int) rowCounter, 4, pItem); // add a line for a metabolite Parameter if ((usage == CFunctionParameter::SUBSTRATE) || (usage == CFunctionParameter::PRODUCT) || (usage == CFunctionParameter::MODIFIER)) { // get the list of possible metabs (for the combo box) if (usage == CFunctionParameter::MODIFIER) //get all metabs; modifiers are never locked vectorOfStrings2QStringList(getListOfAllMetabNames(model, ri), qsl); else //only get the modifiers from the ChemEq { if (!ri.isLocked(i)) vectorOfStrings2QStringList(ri.getListOfMetabs(usage), qsl); } metabNames = &(ri.getMappings(i)); if (!ri.isVector(i)) { if (ri.isLocked(i)) { pItem = new ColorTableItem(color, FROM_UTF8((*metabNames)[0])); setItem((int) rowCounter, 3, pItem); } else { QComboBox * pComboBox = new QComboBox(); pComboBox->addItems(qsl); pComboBox->setBackgroundColor(color); pComboBox->setCurrentText(FROM_UTF8(unQuote((*metabNames)[0]))); setCellWidget((int) rowCounter, 3, pComboBox); } } else { if (ri.isLocked(i)) { pItem = new ColorTableItem(color, ""); setItem((int) rowCounter, 3, pItem); } else // this should not happen { QComboBox * pComboBox = new QComboBox(); pComboBox->addItems(qsl); pComboBox->setBackgroundColor(color); pComboBox->setCurrentText("add species"); setCellWidget((int) rowCounter, 3, pComboBox); } // add lines for vector parameters jmax = metabNames->size(); setRowCount(rowCount() + (int) jmax); for (j = 0; j < jmax; ++j) { ++rowCounter; pItem = new ColorTableItem(color, FROM_UTF8((*metabNames)[j])); setItem((int) rowCounter, 3, pItem); } } } // add a line for a kinetic parameter else if (usage == CFunctionParameter::PARAMETER) { if (ri.isLocalValue(i)) { pItem = new ColorTableItem(color, QString::number(ri.getLocalValue(i))); setItem((int) rowCounter, 3, pItem); } else //global parameter { QComboBox * pComboBox = new QComboBox(); pComboBox->addItems(getListOfAllGlobalParameterNames(model)); pComboBox->setBackgroundColor(color); pComboBox->setCurrentText(FROM_UTF8(ri.getMapping(i))); setCellWidget((int) rowCounter, 3, pComboBox); } } // add a line for a kinetic parameter else if (usage == CFunctionParameter::VOLUME) { QComboBox * pComboBox = new QComboBox(); pComboBox->addItems(getListOfAllCompartmentNames(model)); pComboBox->setBackgroundColor(color); pComboBox->setCurrentText(FROM_UTF8(ri.getMapping(i))); setCellWidget((int) rowCounter, 3, pComboBox); } // add a line for time else if (usage == CFunctionParameter::TIME) { pItem = new ColorTableItem(color, ""); setItem((int) rowCounter, 3, pItem); } // add a line for an unknown role else { pItem = new ColorTableItem(color, QString::number(ri.getLocalValue(i))); setItem((int) rowCounter, 3, pItem); } resizeRowToContents((int) rowCounter); //mLine2Index ++rowCounter; } this->resizeColumnsToContents(); }
void MotionTypeDelegate::setEditorData(QWidget *editor, const QModelIndex & index) const { QComboBox * comboBox = static_cast<QComboBox*>(editor); comboBox->addItems(AbstractMotion::typeList()); comboBox->setCurrentIndex(index.model()->data(index, Qt::EditRole).toInt()); }
QWidget* SceneTableUi::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { ObsAction* action = 0; if (ObsActions) { action = (*ObsActions)[index.row()+1]; } int delay = 0; QString currentSceneOrTransition; switch (index.column()) { case QTV_DELAY1: delay = action ? action->GetDelay1():0; break; case QTV_DELAY2: delay = action ? action->GetDelay2():0; break; case QTV_SCENE1: currentSceneOrTransition = action ? action->GetScene1Name():""; break; case QTV_SCENE2: currentSceneOrTransition = action ? action->GetScene2Name():""; break; case QTV_TRANSITION: currentSceneOrTransition = action ? action->GetTransitionName():""; break; } switch (index.column()) { case QTV_ACTION: { return new QLabel(action ? action->actionName:""); } break; case QTV_DELAY1: case QTV_DELAY2: { QSpinBox *editor = new QSpinBox(parent); editor->setFrame(false); editor->setValue(delay); editor->setMinimum(0); editor->setMaximum(100); return editor; } break; case QTV_SCENE1: case QTV_SCENE2: case QTV_TRANSITION: { QComboBox* comboBox = new QComboBox(parent); comboBox->addItems(index.column() == QTV_TRANSITION?Transitions:Scenes); int index = comboBox->findText(currentSceneOrTransition); if ( index != -1 ) { comboBox->setCurrentIndex(index); } return comboBox; } break; } }
//------------------------------------------------------------------------------ void Widget::initUi() { QVBoxLayout* pMainLyt = new QVBoxLayout(this); pMainLyt->setMargin(5); pMainLyt->setSpacing(5); QHBoxLayout* pServerInfo = new QHBoxLayout(this); { QComboBox* pServerAddress = new QComboBox(this); pServerAddress->addItems(getLocalIpAddresses()); mpPort = new QLineEdit("12345",this); mpProtocols = new QComboBox( this ); mpProtocols->insertItem( tpRaw, "raw" ); mpProtocols->insertItem( tpRealisim, "realisim" ); connect(mpProtocols, SIGNAL(activated(int)), this, SLOT(protocolChanged(int)) ); pServerInfo->addWidget(pServerAddress); pServerInfo->addWidget(mpPort); pServerInfo->addWidget(mpProtocols); } QHBoxLayout* pButtonsLyt = new QHBoxLayout(this); { mpStartServer = new QPushButton("Start",this); mpStopServer = new QPushButton("Stop",this); mpStopServer->setDisabled(true); pButtonsLyt->addStretch(1); pButtonsLyt->addWidget(mpStartServer); pButtonsLyt->addWidget(mpStopServer); connect(mpStartServer, SIGNAL(clicked()), this, SLOT(startServer())); connect(mpStopServer, SIGNAL(clicked()), this, SLOT(stopServer())); } QHBoxLayout* pLyt1 = new QHBoxLayout(); { QLabel* pConnectedPeers = new QLabel("Connected Peers:", this); mpNumberOfPeers = new QLabel( "0", this ); pLyt1->addWidget( pConnectedPeers ); pLyt1->addWidget( mpNumberOfPeers ); pLyt1->addStretch( 1 ); } mpConnectedPeers = new QTreeWidget(this); mpConnectedPeers->setColumnCount(4); QTreeWidgetItem* item = new QTreeWidgetItem(); item->setText(0, "Id"); item->setText(1, "Ip Address"); item->setText(2, "state"); item->setText(3, "transmission"); mpConnectedPeers->setHeaderItem(item); connect( mpConnectedPeers, SIGNAL( itemClicked ( QTreeWidgetItem*, int ) ), this, SLOT( peerItemClicked( QTreeWidgetItem*, int ) ) ); //---générale QLabel* pLog = new QLabel("Log:", this); mpLog = new QTextEdit(this); //---assemblage dans le layout pMainLyt->addLayout(pServerInfo); pMainLyt->addLayout(pButtonsLyt); pMainLyt->addLayout(pLyt1); pMainLyt->addWidget(mpConnectedPeers); pMainLyt->addWidget(pLog); pMainLyt->addWidget(mpLog); }
void AsciiOpenDlg::updateTable(const QString &separator) { tableWidget->setEnabled(false); extractSFNamesFrom1stLineCheckBox->setEnabled(false); m_headerLine.clear(); if (m_filename.isEmpty()) { tableWidget->clear(); return; } if (separator.length()<1) { asciiCodeLabel->setText("Enter a valid character!"); buttonBox->setEnabled(false); tableWidget->clear(); m_invalidColumns = true; return; } //we open the file in ASCII mode FILE* pFile = fopen(qPrintable(m_filename),"rt"); if (!pFile) { tableWidget->clear(); m_invalidColumns = true; return; } //buffer char line[MAX_ASCII_FILE_LINE_LENGTH]; //last read line //we skip first lines (if needed) unsigned i; for (i=0;i<m_skippedLines;++i) { if (fgets(line, MAX_ASCII_FILE_LINE_LENGTH, pFile)) { //we keep track of the first line if (i==0) m_headerLine = QString(line); } else { fclose(pFile); tableWidget->clear(); m_invalidColumns = true; return; } } //new separator m_separator = separator[0]; asciiCodeLabel->setText(QString("(ASCII code: %1)").arg(m_separator.unicode())); //if the old setup has less than 3 columns, we forget it if (m_columnsCount<3) { tableWidget->clear(); m_columnsCount=0; } tableWidget->setRowCount(DISPLAYED_LINES+1); //+1 for first line shifting unsigned lineCount = 0; //number of lines read unsigned totalChars = 0; //total read characters (for stats) unsigned columnsCount = 0; //max columns count per line std::vector<bool> valueIsNumber; //identifies columns with numbers only [mandatory] std::vector<bool> valueIsBelowOne; //identifies columns with values between -1 and 1 only std::vector<bool> valueIsInteger; //identifies columns with integer values only std::vector<bool> valueIsBelow255; //identifies columns with integer values between 0 and 255 only while ((lineCount<LINES_READ_FOR_STATS) && fgets(line, MAX_ASCII_FILE_LINE_LENGTH, pFile)) { //we convert char buffer to a QString object QString str(line); //we recognize "//" as comment if (line[0]!='/' || line[1]!='/') { QStringList parts = str.trimmed().split(m_separator,QString::SkipEmptyParts); unsigned partsCount = (unsigned)parts.size(); if (partsCount>MAX_COLUMNS) partsCount=MAX_COLUMNS; if (lineCount<DISPLAYED_LINES) { //do we need to add one or several new columns? if (partsCount>columnsCount) { //we also extend vectors for (i=columnsCount;i<partsCount;++i) { valueIsNumber.push_back(true); valueIsBelowOne.push_back(true); valueIsBelow255.push_back(true); valueIsInteger.push_back(true); } tableWidget->setColumnCount(partsCount); columnsCount=partsCount; } //we fill row with extracted parts for (i=0;i<partsCount;++i) { QTableWidgetItem *newItem = new QTableWidgetItem(parts[i]); //test values bool isANumber = false; double value = parts[i].toDouble(&isANumber); if (!isANumber) { valueIsNumber[i] = false; valueIsBelowOne[i] = false; valueIsInteger[i] = false; valueIsBelow255[i] = false; newItem->setBackground(QBrush(QColor(255,160,160))); } else { double intPart, fracPart; fracPart = modf(value,&intPart); valueIsBelowOne[i] = valueIsBelowOne[i] && (fabs(value)<=1.0); valueIsInteger[i] = valueIsInteger[i] && (fracPart == 0.0); valueIsBelow255[i] = valueIsBelow255[i] && (valueIsInteger[i] && (intPart >= 0.0 && value<=255.0)); } tableWidget->setItem(lineCount+1, i, newItem); //+1 for first line shifting } } totalChars += (str.size()+1); //+1 for return char at eol ++lineCount; } } fclose(pFile); pFile=0; if (lineCount==0 || columnsCount==0) { m_averageLineSize = -1.0; tableWidget->clear(); m_invalidColumns = true; return; } //average line size m_averageLineSize = double(totalChars)/double(lineCount); //we add a type selector for each column QStringList propsText; for (i=0; i<ASCII_OPEN_DLG_TYPES_NUMBER; i++) propsText << QString(ASCII_OPEN_DLG_TYPES_NAMES[i]); //remove unnecessary columns while (columnsCount<m_columnsCount) tableWidget->removeColumn(--m_columnsCount); for (i=lineCount+1;i<=DISPLAYED_LINES;++i) tableWidget->removeRow(i); int columnWidth = (tableWidget->width()*9) / (columnsCount*10); columnWidth = std::max(columnWidth,80); //Icons const QIcon xIcon(QString::fromUtf8(":/CC/Types/images/types/x_coordinate.png")); const QIcon yIcon(QString::fromUtf8(":/CC/Types/images/types/y_coordinate.png")); const QIcon zIcon(QString::fromUtf8(":/CC/Types/images/types/z_coordinate.png")); const QIcon NormIcon(QString::fromUtf8(":/CC/Types/images/types/normal.png")); const QIcon RGBIcon(QString::fromUtf8(":/CC/Types/images/types/rgb_color.png")); const QIcon GreyIcon(QString::fromUtf8(":/CC/Types/images/types/gray_color.png")); const QIcon ScalarIcon(QString::fromUtf8(":/CC/Types/images/types/scalar_field.png")); const QIcon PositiveScalarIcon(QString::fromUtf8(":/CC/Types/images/types/positive_scalar_field.png")); unsigned assignedXYZ = 0; unsigned assignedNorm = 0; unsigned assignedRGB = 0; for (i=0;i<columnsCount;i++) { QComboBox* columnHeader = static_cast<QComboBox*>(tableWidget->cellWidget(0,i)); QComboBox* _columnHeader = columnHeader; if (!columnHeader) { columnHeader = new QComboBox(); columnHeader->addItems(propsText); columnHeader->setMaxVisibleItems(ASCII_OPEN_DLG_TYPES_NUMBER); columnHeader->setCurrentIndex(0); columnHeader->setItemIcon(ASCII_OPEN_DLG_X,xIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_Y,yIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_Z,zIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_NX,NormIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_NY,NormIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_NZ,NormIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_R,RGBIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_G,RGBIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_B,RGBIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_Grey,GreyIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_Scalar,ScalarIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_Positive_Scalar,PositiveScalarIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_RGB32i,RGBIcon); columnHeader->setItemIcon(ASCII_OPEN_DLG_RGB32f,RGBIcon); connect(columnHeader, SIGNAL(currentIndexChanged(int)), this, SLOT(columnsTypeHasChanged(int))); } if (valueIsNumber[i]) { //first time? let's try to assign each column a type if ((m_invalidColumns || m_columnsCount==0) && columnsCount>1) { columnHeader->blockSignals(true); //by default, we assume that the first columns are always X,Y and Z if (assignedXYZ<3) { //in rare cases, the first column is an index if (assignedXYZ==0 && valueIsInteger[i] && (i+1<columnsCount) && !valueIsInteger[i+1]) { //we skip it } else { ++assignedXYZ; columnHeader->setCurrentIndex(assignedXYZ); } } else { //looks like RGB? if (valueIsBelow255[i] && assignedRGB<3 && (i+2-assignedRGB < columnsCount) && (assignedRGB > 0 || (valueIsBelow255[i+1] && valueIsBelow255[i+2]))) //make sure that next values are also ok! { columnHeader->setCurrentIndex(ASCII_OPEN_DLG_R+assignedRGB); ++assignedRGB; } else if (valueIsBelowOne[i] && assignedNorm<3 && (i+2-assignedNorm < columnsCount) && (assignedNorm > 0 || (valueIsBelowOne[i+1] && valueIsBelowOne[i+2]))) //make sure that next values are also ok! { columnHeader->setCurrentIndex(ASCII_OPEN_DLG_NX+assignedNorm); ++assignedNorm; } else { //maybe it's a scalar? columnHeader->setCurrentIndex(ASCII_OPEN_DLG_Scalar); } } columnHeader->blockSignals(false); } } if (!_columnHeader) tableWidget->setCellWidget(0,i,columnHeader); tableWidget->setColumnWidth(i,columnWidth); }