示例#1
0
QWidget *DateDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
                           const QModelIndex &index) const
{
    Q_UNUSED(option);
    Q_UNUSED(index);
    QDateEdit * dateEdit = new QDateEdit(parent);
    dateEdit->setDisplayFormat("yyyy-MM-dd");
    return dateEdit;
}
QWidget* DateEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/) const{
    QDateEdit *date = new QDateEdit(parent);
    date->setCalendarPopup(true);
    date->setDisplayFormat("yyyy-MM-dd");
    date->setDate(QDate::currentDate());
    date->setMinimumDate(QDate(2014,3,1));
    date->setMaximumDate(QDate(2050,12,31));
    return date;
}
示例#3
0
void EventsWindow::createDateFilter(QBoxLayout *layout)
{
	m_dateLabel = new QLabel;
	m_dateLabel->setStyleSheet(QLatin1String("font-weight:bold;"));
	layout->addWidget(m_dateLabel);

    QDateEdit *dateEdit = new QDateEdit(QDate::currentDate());
    dateEdit->setCalendarPopup(true);
    dateEdit->setMaximumDate(QDate::currentDate());
    dateEdit->setDisplayFormat(QLatin1String("ddd, MMM dd, yyyy"));
    dateEdit->setTime(QTime(23, 59, 59, 999));
    dateEdit->setFixedWidth(m_sourcesView->width());
    layout->addWidget(dateEdit);

    setFilterDay(dateEdit->dateTime());

    connect(dateEdit, SIGNAL(dateTimeChanged(QDateTime)), this,
            SLOT(setFilterDay(QDateTime)));
}
// setup editor for edit of field!!
QWidget *RideDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if (index.column() == dateColumn) {

        // edit that date!
        QDateEdit *dateEdit = new QDateEdit(parent);
        dateEdit->setDisplayFormat("dd MMM yyyy");
        connect(dateEdit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseDateEditor()));
        return dateEdit;
    } else if (index.column() == dateColumn+1) {

        // edit that time
        QTimeEdit *timeEdit = new QTimeEdit(parent);
        timeEdit->setDisplayFormat("hh:mm:ss a");
        connect(timeEdit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseTimeEditor()));
        return timeEdit;
    } else {
        return QItemDelegate::createEditor(parent, option, index);
    }
}
	QWidget *BudgetEntityDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /*option*/, const QModelIndex & /*index*/) const {
		QLocale locale;
		QWidget *editor = new QWidget(parent);
		QHBoxLayout *lay = new QHBoxLayout;
		QDateEdit *dateEdit = new QDateEdit(QDate::currentDate());
		QPlainTextEdit *textEdit = new QPlainTextEdit("Textedig");
		QDoubleSpinBox *spinBox = new QDoubleSpinBox;
		
		dateEdit->setDisplayFormat("yyyy-MM-dd");
		dateEdit->setCalendarPopup(true);
		
		spinBox->setMaximum(1e+08);
		spinBox->setMinimum(-1e+07);
		spinBox->setPrefix(locale.currencySymbol(QLocale::CurrencySymbol));
		spinBox->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
		
		editor->setLayout(lay);
		lay->addWidget(dateEdit);
		lay->addWidget(textEdit);
		lay->addWidget(spinBox);
		
		return editor;
	}
示例#6
0
QWidget *DateTimeDelegate::createEditor(QWidget *parent,
                                       const QStyleOptionViewItem &/* option */,
                                       const QModelIndex &index) const
{
    // TODO: use the ModernDateEditor editor
    if (m_IsDateOnly) {
        QDateEdit *editor = new QDateEdit(parent);
        editor->setMinimumDate(m_MinDate);
        editor->setMaximumDate(m_MaxDate);
        editor->setCalendarPopup(true);
        editor->setDisplayFormat(tkTr(Trans::Constants::DATEFORMAT_FOR_EDITOR));
        editor->setDate(index.data(Qt::EditRole).toDate());
        return editor;
    } else {
        QDateTimeEdit *editor = new QDateTimeEdit(parent);
        editor->setMinimumDateTime(QDateTime(m_MinDate, m_MinTime));
        editor->setMaximumDateTime(QDateTime(m_MaxDate, m_MaxTime));
        editor->setDisplayFormat(tkTr(Trans::Constants::DATETIMEFORMAT_FOR_EDITOR));
        editor->setDateTime(index.data().toDateTime());
        return editor;
    }
    return 0;
}
示例#7
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QWidget *UKvyt_Delegate::createEditor(QWidget *parent,
        const QStyleOptionViewItem &option,
        const QModelIndex &index) const
{
	QSpinBox *spinbox;
    if (index.column() == durationColumn_2) {
        QDoubleSpinBox *double_spinbox = new QDoubleSpinBox(parent);
        double_spinbox->setMaximum ( 999999999 );
		double_spinbox->setMinimum ( -999999999 );
        connect(double_spinbox, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return double_spinbox;
    } 
	else if ((index.column() == durationColumn_3) || (index.column() == durationColumn_4)){
        QDateEdit * dateEdit = new QDateEdit(parent);
		QDate date;
		date.setYMD( 2100, 12, 30 );
        dateEdit->setMaximumDate( date );
		date.setYMD( 2004, 1, 1 );
		dateEdit->setMinimumDate( date );
		dateEdit->setDisplayFormat( "d.MM.yyyy" );
        connect(dateEdit, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return dateEdit;
	}
	else if ((index.column() == durationColumn_5) || (index.column() == durationColumn_1)){
        spinbox = new QSpinBox(parent);
        spinbox->setMaximum ( 999999 );
		spinbox->setMinimum ( 1 );
        connect(spinbox, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return spinbox;
	}
	else{
        return QSqlRelationalDelegate::createEditor(parent, option, index);
    }
}
void ExprParamElement::setRangedSearch(bool ranged)
{    
    
    if (inRangedConfig == ranged) return; // nothing to do here
    inRangedConfig = ranged;
    QHBoxLayout* hbox = (dynamic_cast<QHBoxLayout*>(internalframe->layout()));

    // add additional or remove extra input fields depending on whether
    // ranged search or not
    if (inRangedConfig)
    {
        QLabel * toLbl = new QLabel(tr("to"));
        toLbl->setMinimumSize(10, FIELDS_MIN_HEIGHT);
        toLbl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

        if (searchType ==  DateSearch) {
           internalframe->setMinimumSize(250,26);            
            QDateEdit * dateEdit = new QDateEdit(QDate::currentDate(), internalframe);
            dateEdit->setMinimumSize(DATE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
            dateEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
            dateEdit->setObjectName("param2");
            dateEdit->setDisplayFormat(tr("dd.MM.yyyy"));
            dateEdit->setMinimumDate(QDate(1970, 1, 1));
            dateEdit->setMaximumDate(QDate(2099, 12,31));
            
            hbox->addSpacing(9);
            hbox->addWidget(toLbl, Qt::AlignLeft);
            hbox->addSpacing(9);
            hbox->addWidget(dateEdit, Qt::AlignLeft);
            hbox->addStretch();
        } else if (searchType == SizeSearch) {
            internalframe->setMinimumSize(340,26);
            QLineEdit * lineEdit = new QLineEdit(internalframe);
            lineEdit->setMinimumSize(SIZE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
            lineEdit->setMaximumSize(SIZE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
            lineEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
            lineEdit->setObjectName("param2");
            lineEdit->setValidator(numValidator);
            
            QComboBox * cb = new QComboBox(internalframe);
            cb->setObjectName("unitsCb2");
            cb-> addItem(tr("KB"), QVariant(1024));
            cb->addItem(tr("MB"), QVariant(1048576));
            cb->addItem(tr("GB"), QVariant(1073741824));
            
            hbox->addSpacing(9);
            hbox->addWidget(toLbl, Qt::AlignLeft);
            hbox->addSpacing(9);
            hbox->addWidget(lineEdit, Qt::AlignLeft);
            hbox->addSpacing(9);
            hbox->addWidget(cb);
            hbox->addStretch();
        } 
//         else if (searchType == PopSearch)
//         {
//             elem->layout()->addWidget(new QLabel(tr("to")), Qt::AlignCenter);
//             QLineEdit * lineEdit = new QLineEdit(elem);
//             lineEdit->setObjectName("param2");
//             lineEdit->setValidator(numValidator);
//             elem->layout()->addWidget(slineEdit);
//         }
        hbox->invalidate();
        internalframe->adjustSize();
        internalframe->show();
        this->adjustSize();
    } else {
        adjustForSearchType(searchType);
    }
}
void ExprParamElement::adjustForSearchType(ExprSearchType type)
{    
    // record which search type is active
    searchType = type;
    QRegExp regExp("0|[1-9][0-9]*");
    numValidator = new QRegExpValidator(regExp, this);
    QRegExp hexRegExp("[A-Fa-f0-9]*");
    hexValidator = new QRegExpValidator(hexRegExp, this);
    
    // remove all elements
    QList<QWidget*> children = qFindChildren<QWidget*>(internalframe);
    QWidget* child;
    QLayout * lay_out = internalframe->layout();
     while (!children.isEmpty())
    {
        child = children.takeLast();
        child->hide();
        lay_out->removeWidget(child);
        delete child;
    }
    delete lay_out;

    QHBoxLayout* hbox = createLayout();
    internalframe->setLayout(hbox);
    internalframe->setMinimumSize(320,26);

    if (isStringSearchExpression())
    {
        // set up for default of a simple input field
        QLineEdit* lineEdit = new QLineEdit(internalframe);
        lineEdit->setMinimumSize(STR_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
        lineEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
        lineEdit->setObjectName("param1");
        hbox->addWidget(lineEdit);
        hbox->addSpacing(9);
        QCheckBox* icCb = new QCheckBox(tr("ignore case"), internalframe);
        icCb->setObjectName("ignoreCaseCB");
	icCb->setCheckState(Qt::Checked);
	// hex search specifics: hidden case sensitivity and hex validator
	if (searchType == HashSearch) {
		icCb->hide();
		lineEdit->setValidator(hexValidator);        
	}
	hbox->addWidget(icCb);
        hbox->addStretch();
	
    } else if (searchType == DateSearch) 
    {
        QDateEdit * dateEdit = new QDateEdit(QDate::currentDate(), internalframe);
        dateEdit->setMinimumSize(DATE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
        dateEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        dateEdit->setDisplayFormat(tr("dd.MM.yyyy"));
        dateEdit->setObjectName("param1");
        dateEdit->setMinimumDate(QDate(1970, 1, 1));
        dateEdit->setMaximumDate(QDate(2099, 12,31));
        hbox->addWidget(dateEdit, Qt::AlignLeft);
        hbox->addStretch();
    } else if (searchType == SizeSearch) 
    {
        QLineEdit * lineEdit = new QLineEdit(internalframe);
        lineEdit->setMinimumSize(SIZE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
        lineEdit->setMaximumSize(SIZE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
        lineEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        lineEdit->setObjectName("param1");
        lineEdit->setValidator(numValidator);
        hbox->addWidget(lineEdit, Qt::AlignLeft);

        QComboBox * cb = new QComboBox(internalframe);
        cb->setObjectName("unitsCb1");
        cb-> addItem(tr("KB"), QVariant(1024));
        cb->addItem(tr("MB"), QVariant(1048576));
        cb->addItem(tr("GB"), QVariant(1073741824));
        hbox->addSpacing(9);
        internalframe->layout()->addWidget(cb);
        hbox->addStretch();
    } 

    /* POP Search not implemented
    else if (searchType == PopSearch)
    {
        QLineEdit * lineEdit = new QLineEdit(elem);
        lineEdit->setObjectName("param1");
        lineEdit->setValidator(numValidator);
        elem->layout()->addWidget(lineEdit);
    }*/
    hbox->invalidate();
    internalframe->adjustSize();
    internalframe->show();
    this->adjustSize();
}
示例#10
0
// Предоставление редактора
QWidget*  ComboBoxFileldDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option,
												 const QModelIndex & index ) const
{
	if (index.column()>2){

		// QMessageBox::critical(0,"",index.model()->data(index.sibling(index.row(),0)).toString());
		QString pole = index.model()->data(index.sibling(index.row(),0)).toString();
		int j;
		for(int i=0;i<fieldName.count();i++){
				QString s = model->headerData( fieldName.at(i) , Qt::Horizontal).toString();
				s.replace("\n"," ");
				if (s==pole){
					j=fieldName.at(i);
					break;
				}
		}

		//QMessageBox::critical(0,"",QString("%1").arg(j));
		QSqlRelation rel =  model->relation(j);
		if (rel.indexColumn()!=QString("")){
			//QMessageBox::critical(0,"",rel.indexColumn()+" "+rel.displayColumn()+" "+rel.tableName());
			QComboBox * pRes = new QComboBox(parent);
			QSqlTableModel* relModel = new QSqlTableModel;

			relModel->setTable(rel.tableName());
			relModel->select();

			pRes->setModel(relModel);
			pRes->setModelColumn(relModel->fieldIndex(rel.displayColumn()));

			return pRes;

		}

		if (model->data(model->index(0,j), Qt::EditRole).type() == QVariant::Date){
			QDateEdit* pRes = new  QDateEdit(parent);
			pRes->setCalendarPopup(true);
			pRes->setDisplayFormat("dd.MM.yyyy");
			return pRes;
		}

		if (model->data(model->index(0,j), Qt::EditRole).type() == QVariant::Bool){
			QComboBox * pRes = new QComboBox(parent);

			pRes->addItem(tr("Нет"));
			pRes->addItem(tr("Да"));
			return pRes;
		}


		return QItemDelegate::createEditor(parent,option,index);
	}

	QComboBox * pRes = new QComboBox(parent);

	switch (index.column()) {
		case 0: {

			QStringList field;
			for(int i=0;i<fieldName.count();i++){
				QString s = model->headerData( fieldName.at(i) , Qt::Horizontal).toString();
				s.replace("\n"," ");
				field<<s;
			}
			pRes->addItems(field);
			break;
		}
		case 1: {
			pRes->addItem(tr(" "));
			pRes->addItem(tr("не"));
			break;
		}
		case 2: {
			pRes->addItem(tr("равно"));
			pRes->addItem(tr("похоже на"));
			pRes->addItem(tr("больше"));
			pRes->addItem(tr("меньше"));
			break;
		}

	}

	// это строка нужна для того чтобы по enter и esc завершалось редактирование итд
	pRes->installEventFilter(const_cast<ComboBoxFileldDelegate*>(this));

	return pRes;

};
示例#11
0
// Предоставление редактора
QWidget*  ComboBoxMailDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option,
        const QModelIndex& index) const
{

    if (index.column() == 1) {

        // QMessageBox::critical(0,"",index.model()->data(index.sibling(index.row(),0)).toString());
        QString pole = index.model()->data(index.sibling(index.row(), 0)).toString();
        int j;
        for (int i = 0; i < fieldName.count(); i++) {
            QString s = model->headerData(fieldName.at(i) , Qt::Horizontal).toString();
            s.replace("\n", " ");

            if (s == pole) {
                j = fieldName.at(i);
                break;
            }
        }

        //QMessageBox::critical(0,"",QString("%1").arg(j));
        QSqlRelation rel =  model->relation(j);
        if (rel.indexColumn() != QString("")) {
            //QMessageBox::critical(0,"",rel.indexColumn()+" "+rel.displayColumn()+" "+rel.tableName());
            QComboBox* pRes = new QComboBox(parent);
            QSqlTableModel* relModel = new QSqlTableModel;
            relModel->setTable(rel.tableName());

            /* Удаление выбранных значений в кому */
            if (pole == tr("Кому")) {
                QString relFilter = QString("user_id != '00000000-0000-0000-0000-000000000000'");
                for (int i = 0; i < index.model()->rowCount(); i++) {

                    QString pole = index.model()->data(index.sibling(i, 0)).toString();

                    if (pole == tr("Кому") && index.row() != i) {
                        QString val = index.model()->data(index.sibling(i, 1)).toString();
                        if ( val != QString(""))
                            relFilter = QString("%1 and not user_id = '%2'").arg(relFilter).arg(val);
                    }
                    //QMessageBox::critical(0,"",index.model()->data(index.sibling(i,1)).toString());
                }
                //QMessageBox::critical(0,"","-"+relFilter+"-");
                relModel->setFilter(relFilter);
            }

            relModel->select();

            pRes->setModel(relModel);
            pRes->setModelColumn(relModel->fieldIndex(rel.displayColumn()));

            return pRes;

        }

        if (model->data(model->index(0, j)).type() == QVariant::Date) {
            QDateEdit* pRes = new  QDateEdit(parent);
            pRes->setCalendarPopup(true);
            pRes->setDisplayFormat("dd.MM.yyyy");
            return pRes;
        }

        if (model->data(model->index(0, j)).type() == QVariant::Bool) {
            QComboBox* pRes = new QComboBox(parent);

            pRes->addItem(tr("Нет"));
            pRes->addItem(tr("Да"));
            return pRes;
        }


        return QItemDelegate::createEditor(parent, option, index);
    }

    if (index.column() == 0) {
        QComboBox* pRes = new QComboBox(parent);

        bool typeflag       = true;
        bool priorflag      = true;
        bool recipientflag  = true;
        bool beginflag  = true;
        bool endflag  = true;

        for (int i = 0; i < index.model()->rowCount(); i++) {

            QString pole = index.model()->data(index.sibling(i, 0)).toString();

            if (pole == tr("Тип") && index.row() != i)
                typeflag = false;
            if (pole == tr("Приоритет") && index.row() != i)
                priorflag = false;
            if (pole == tr("Начало") && index.row() != i)
                beginflag = false;
            if (pole == tr("Конец") && index.row() != i)
                endflag = false;
        }

        //if (recipientflag)
        pRes->addItem(tr("Кому"));

        if (typeflag)
            pRes->addItem(tr("Тип"));
        if (priorflag)
            pRes->addItem(tr("Приоритет"));
        if (beginflag)
            pRes->addItem(tr("Начало"));
        if (endflag)
            pRes->addItem(tr("Конец"));

        //pRes->addItem(tr("Копия"));

        // это строка нужна для того чтобы по enter и esc завершалось редактирование итд
        pRes->installEventFilter(const_cast<ComboBoxMailDelegate*>(this));

        return pRes;
    }


    return QItemDelegate::createEditor(parent, option, index);

};