void Table::setSelection(int row, int column, bool suppressSignals) { QTableWidget *tablewidget = static_cast<QTableWidget*>(getQWidget()); bool oldSignalsState = tablewidget->blockSignals(suppressSignals); tablewidget->setCurrentCell(row, column); tablewidget->blockSignals(oldSignalsState); }
void Table::setColumnCount(int count, bool suppressSignals) { QTableWidget *tablewidget = static_cast<QTableWidget*>(getQWidget()); bool oldSignalsState = tablewidget->blockSignals(suppressSignals); tablewidget->setColumnCount(count); tablewidget->blockSignals(oldSignalsState); }
void Table::clear(bool suppressSignals) { QTableWidget *tablewidget = static_cast<QTableWidget*>(getQWidget()); bool oldSignalsState = tablewidget->blockSignals(suppressSignals); tablewidget->clear(); // or clearContents() ? tablewidget->blockSignals(oldSignalsState); }
void Table::setItem(int row, int column, std::string text, bool suppressSignals) { QTableWidget *tablewidget = static_cast<QTableWidget*>(getQWidget()); bool oldSignalsState = tablewidget->blockSignals(suppressSignals); QTableWidgetItem *item = tablewidget->item(row, column); if(!item) item = new QTableWidgetItem; item->setText(QString::fromStdString(text)); tablewidget->setItem(row, column, item); tablewidget->blockSignals(oldSignalsState); }
void Table::setItemImage(int row, int column, std::string data, int width, int height, bool suppressSignals) { QTableWidget *tablewidget = static_cast<QTableWidget*>(getQWidget()); bool oldSignalsState = tablewidget->blockSignals(suppressSignals); QTableWidgetItem *item = tablewidget->item(row, column); if(!item) item = new QTableWidgetItem; QImage::Format format = QImage::Format_RGB888; int bpp = 3; // bytes per pixel QImage image((unsigned char *)data.data(), width, height, bpp * width, format); item->setData(Qt::DecorationRole, QPixmap::fromImage(image.mirrored())); tablewidget->setItem(row, column, item); tablewidget->blockSignals(oldSignalsState); }
void ParameterWidget::applySaved(int pId, int filter_id) { QWidget *found = 0; QDate tempdate; XSqlQuery qry; QString query; QString filterValue; QDate today = QDate::currentDate(); int xid, init_filter_id; init_filter_id = filter_id; QMapIterator<int, QPair<QString, QVariant> > j(_filterValues); QPair<QString, ParameterWidgetTypes> tempPair; clearFilters(); if (!parent()) return; if (_filterList->id() == -1) { emit updated(); return; } if (filter_id == 0 && _filterList->id() != -1) filter_id = _filterList->id(_filterList->currentIndex()); QString classname(parent()->objectName()); if (classname.isEmpty()) classname = parent()->metaObject()->className(); query = " SELECT filter_value, " " CASE WHEN (filter_username IS NULL) THEN true " " ELSE false END AS shared " " FROM filter " " WHERE filter_id=:id "; qry.prepare(query); qry.bindValue(":id", filter_id ); qry.exec(); if (qry.first()) { filterValue = qry.value("filter_value").toString(); _shared = qry.value("shared").toBool(); } QStringList filterRows = filterValue.split("|"); QString tempFilter = QString(); int windowIdx = _filtersLayout->rowCount(); if (filterRows.size() == 1 && pId == 0 && filter_id != 0) { emit updated(); return; } for (int i = 0; i < filterRows.size(); ++i) { tempFilter = filterRows[i]; if ( !(tempFilter.isEmpty()) ) { //0 is filterType, 1 is filterValue, 2 is parameterwidgettype QStringList tempFilterList = tempFilter.split(":"); QString key = this->getParameterTypeKey(tempFilterList[0]); if (key.isEmpty()) { //parametertype is no longer found, prompt user to delete filter if (QMessageBox::question(this, tr("Invalid Filter Set"), tr("This filter set contains an obsolete filter and will be deleted. Do you want to do this?"), QMessageBox::No | QMessageBox::Default, QMessageBox::Yes) == QMessageBox::No) return; else { QString query = "delete from filter where filter_id=:filter_id"; XSqlQuery qry; qry.prepare(query); qry.bindValue(":filter_id", filter_id); qry.exec(); setSavedFilters(); return; } } else { this->addParam(); QLayoutItem *test = _filtersLayout->itemAtPosition(windowIdx, 0)->layout()->itemAt(0); XComboBox *mybox = (XComboBox*)test->widget(); int idx = mybox->findText(key); mybox->setCurrentIndex(idx); found = getFilterWidget(windowIdx); int widgetType = tempFilterList[2].toInt(); //grab pointer to newly created filter object switch (widgetType) { case Date: DLineEdit *dLineEdit; dLineEdit = qobject_cast<DLineEdit*>(found); if (dLineEdit != 0) dLineEdit->setDate(today.addDays(tempFilterList[1].toInt()), true); break; case User: UsernameCluster *usernameCluster; usernameCluster = qobject_cast<UsernameCluster*>(found); if (usernameCluster != 0) usernameCluster->setUsername(tempFilterList[1]); break; case Crmacct: CRMAcctCluster *crmacctCluster; crmacctCluster = qobject_cast<CRMAcctCluster*>(found); if (crmacctCluster != 0) crmacctCluster->setId(tempFilterList[1].toInt()); break; case Contact: ContactCluster *contactCluster; contactCluster = qobject_cast<ContactCluster*>(found); if (contactCluster != 0) contactCluster->setId(tempFilterList[1].toInt()); break; case XComBox: XComboBox *xBox; xBox = qobject_cast<XComboBox*>(found); if (xBox != 0) { //fix for setid not emitting id signal if id found for filter is first in list //set to any other valid id first to fix it xBox->setId(2); xid = tempFilterList[1].toInt(); xBox->setId(xid); } break; case Multiselect: { QTableWidget *tab; tab = qobject_cast<QTableWidget*>(found); if (tab != 0) { QStringList savedval = tempFilterList[1].split(","); bool oldblk = tab->blockSignals(true); /* the obvious, loop calling tab->selectRow(), gives one selected row, so try this to get multiple selections: make only the desired values selectable, select everything, and connect to a slot that can clean up after us. yuck. */ for (int j = 0; j < tab->rowCount(); j++) { if (! savedval.contains(tab->item(j, 0)->data(Qt::UserRole).toString())) tab->item(j, 0)->setFlags(tab->item(j, 0)->flags() & (~ Qt::ItemIsSelectable)); } QTableWidgetSelectionRange range(0, 0, tab->rowCount() - 1, tab->columnCount() - 1); tab->setRangeSelected(range, true); connect(tab, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(resetMultiselect(QTableWidgetItem*))); tab->blockSignals(oldblk); storeFilterValue(-1, tab); } } break; default: { QLineEdit *lineEdit; lineEdit = qobject_cast<QLineEdit*>(found); if (lineEdit != 0) { lineEdit->setText(tempFilterList[1]); storeFilterValue(-1, lineEdit); } } break; }//end of switch }//end of not empty key else windowIdx++; }//end of if tempfilter not empty
void StatsView::on_statsTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) { if (current == 0) return; std::string data = ""; if (current->childCount() == 0) { DataContainerTreeItem *treeData = (DataContainerTreeItem *)current; data = treeData->getData(); } QTreeWidget *statsTree = this->findChild<QTreeWidget *>("statsTree"); QLabel *modName = this->findChild<QLabel *>("modName"); QTableWidget *modTable = this->findChild<QTableWidget *>("modTable"); modTable->blockSignals(true); StatsContainer *itemStats = GenStatsReader::getContainer(allItemStats, data.c_str()); if (itemStats != 0) { modName->setText(itemStats->getArg(0).c_str()); std::map<std::string, std::string> baseData = itemStats->getBaseDataMap(); if (itemStats->getUsing() != 0) { std::map<std::string, std::string> parentData = itemStats->getUsing()->getBaseDataMap(); for (std::map<std::string, std::string>::iterator it = parentData.begin(); it != parentData.end(); ++it) { if (baseData.find(it->first) == baseData.end()) { baseData[it->first] = it->second; } } } for (int i=0; i<modTable->rowCount(); ++i) { for (int j=0; j<modTable->columnCount(); ++j) { delete modTable->item(i, j); } } modTable->setRowCount(0); int row = 0; if (itemStats->getContainerType() == "deltamod") { StatsContainer *boost = GenStatsReader::getContainer(allItemStats, itemStats->getBoostName()); if (boost != 0) { std::map<std::string, std::string> boostMap = boost->getBaseDataMap(); for (std::map<std::string, std::string>::iterator it = boostMap.begin(); it != boostMap.end(); ++it) { if (baseData.find(it->first) == baseData.end()) { baseData[it->first] = it->second; } } } for (int i=0; i<itemStats->getPrefixList().size(); ++i) { QTableWidgetItem *nameItem = new QTableWidgetItem(); nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable); nameItem->setText("Prefix"); QTableWidgetItem *valueItem = new QTableWidgetItem(); valueItem->setFlags(valueItem->flags() & ~Qt::ItemIsEditable); valueItem->setText(itemStats->getPrefixList()[i].c_str()); modTable->insertRow(row); modTable->setItem(row, 0, nameItem); modTable->setItem(row, 1, valueItem); ++row; } for (int i=0; i<itemStats->getSuffixList().size(); ++i) { QTableWidgetItem *nameItem = new QTableWidgetItem(); nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable); nameItem->setText("Suffix"); QTableWidgetItem *valueItem = new QTableWidgetItem(); valueItem->setFlags(valueItem->flags() & ~Qt::ItemIsEditable); valueItem->setText(itemStats->getSuffixList()[i].c_str()); modTable->insertRow(row); modTable->setItem(row, 0, nameItem); modTable->setItem(row, 1, valueItem); ++row; } } for (std::map<std::string, std::string>::iterator it = baseData.begin(); it != baseData.end(); ++it) { QTableWidgetItem *nameItem = new QTableWidgetItem(); nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable); nameItem->setText(it->first.c_str()); QTableWidgetItem *valueItem = new QTableWidgetItem(); valueItem->setFlags(valueItem->flags() & ~Qt::ItemIsEditable); valueItem->setText(it->second.c_str()); modTable->insertRow(row); modTable->setItem(row, 0, nameItem); modTable->setItem(row, 1, valueItem); ++row; } modTable->resizeRowsToContents(); modTable->resizeColumnsToContents(); } else if (current->childCount() == 0) { bool canEdit = true; if (current->text(0) == "Abilities") { canEdit = false; } QStringList headerList; headerList.push_back("Name"); if (canEdit) { headerList.push_back("Editable Value"); } else { headerList.push_back("Value"); } modTable->setHorizontalHeaderLabels(headerList); for (int i=0; i<modTable->rowCount(); ++i) { for (int j=0; j<modTable->columnCount(); ++j) { delete modTable->item(i, j); } } modTable->setRowCount(0); int row = 0; modTable->insertRow(row); QTableWidgetItem *nameItem = new QTableWidgetItem(); nameItem->setText(current->text(0)); nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable); modTable->setItem(row, 0, nameItem); QTableWidgetItem *valueItem = new QTableWidgetItem(); if (!canEdit) { valueItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable); } valueItem->setText(data.c_str()); modTable->setItem(row, 1, valueItem); modTable->resizeRowsToContents(); modTable->resizeColumnsToContents(); } modTable->blockSignals(false); }