void QuickEdit::PrefixDelegateSetup() { GenericDelegate* delegate = new GenericDelegate(ui->tvEditor, false); delegate->widgetCreator = [&](QWidget * parent) { QStringList list; list << " " << "const " << "volatile "; QCompleter *completer = new QCompleter(list, parent); completer->setCaseSensitivity(Qt::CaseSensitive); QComboBox* box = new QComboBox(parent); QStringListModel* model = new QStringListModel; model->setStringList(list); box->setModel(model); box->setEditable(true); box->setCompleter(completer); return box; }; delegate->dataAccessor = [](QWidget * editor, const QModelIndex & index) { QString value = index.model()->data(index, Qt::EditRole).toString(); QComboBox *box = static_cast<QComboBox*>(editor); box->setCurrentText(value); }; delegate->dataSetter = [](QWidget * editor,QAbstractItemModel* model, const QModelIndex &index) { QComboBox * box = static_cast<QComboBox*>(editor); QString value = box->currentText(); model->setData(index, value, Qt::EditRole); }; ui->tvEditor->setItemDelegateForColumn(columns.indexOf("prefix"), delegate); }
void QuickEdit::TypeDelegateSetup() { GenericDelegate* delegate = new GenericDelegate(ui->tvEditor, false); delegate->widgetCreator = [](QWidget* parent) { BrowserNodeList result; QStringList classes; BrowserClass::instances(result); result.full_names(classes); QStringList basics = GenerationSettings::basic_types(); classes+=basics; QCompleter* completer = new QCompleter(classes, parent); completer->setCaseSensitivity(Qt::CaseSensitive); QComboBox* box = new QComboBox(parent); QStringListModel* model = new QStringListModel; model->setStringList(classes); box->setModel(model); box->setEditable(true); box->setCompleter(completer); return box; }; delegate->dataAccessor = [](QWidget* editor, const QModelIndex& index) { QString value = index.model()->data(index, Qt::EditRole).toString(); QComboBox* box = static_cast<QComboBox*>(editor); box->setCurrentText(value); }; delegate->dataSetter = [](QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) { QComboBox* box = static_cast<QComboBox*>(editor); QString value = box->currentText(); model->setData(index, value, Qt::EditRole); }; ui->tvEditor->setItemDelegateForColumn(columns.indexOf("type"), delegate); }
void FinanceMgr::createToolbar() { QToolBar* toolBar = addToolBar(QString::fromLocal8Bit("系统工具")); QAction* calcAction = new QAction(QIcon(tr(":/Icon/Resources/calculator.png")), QString::fromLocal8Bit("计算器"), this); toolBar->addAction(calcAction); connect(calcAction, SIGNAL(triggered()), this, SLOT(openCalc())); ui.toolBar->addWidget(new QLabel(QString::fromLocal8Bit("年月: "), this)); QComboBox* yearMonth = new QComboBox(this); QStringList dateList; // find the most faraway month from the budget table Database_Result& dr = DatabaseHandler::instance()->getHandler()->from(BudgetTableName)->limit("1")->orderBy("budget_month ASC")->get(); int currentYear = QDate::currentDate().year(); QString strCurrentYear = QString("%1").arg(currentYear); int currentMonth = QDate::currentDate().month(); QString strCurrentMonth = QString("%1").arg(currentMonth); QString strYM = QString("%1%2").arg(strCurrentYear, strCurrentMonth); QDate databaseDate = QDate::currentDate(); if (dr.count() > 0) { Array record = *dr.resultArray().begin(); databaseDate = QDate::fromString(record[budgetMonthColumnName].c_str(), Qt::ISODate); } // create the year month list from the database time to current time bool loop = true; int year, month; year = databaseDate.year(); month = databaseDate.month(); do { QString strYear = QString("%1").arg(year); QString strMonth = QString("%1").arg(month); QString strYear2Month = QString("%1%2").arg(strYear, strMonth); dateList << strYear2Month; month++; if (month > 12) { month = 1; year++; } // add more than 2 month to the list int monthCount1 = year * 12 + month; int monthCount2 = QDate::currentDate().year() * 12 + QDate::currentDate().month(); if ((monthCount2 + 2) < monthCount1) { loop = false; } } while (loop); yearMonth->addItems(dateList); yearMonth->setEditable(true); QCompleter* ymCompleter = new QCompleter(dateList, this); yearMonth->setCompleter(ymCompleter); yearMonth->setEditText(strYM); ui.toolBar->addWidget(yearMonth); connect(yearMonth, SIGNAL(editTextChanged(const QString&)), this, SLOT(handleMonthChanged(const QString&))); }