bool CLineEdit::setEditMode(bool p) { if (p == _editMode) return p; if (!_canEdit) return false; _editMode=p; _modeAct->setChecked(p); if (_x_metrics) { if (_editMode) _menuLabel->setPixmap(QPixmap(":/widgets/images/edit.png")); else _menuLabel->setPixmap(QPixmap(":/widgets/images/magnifier.png")); if (!_x_metrics->boolean("DisableAutoComplete") && _editMode) disconnect(this, SIGNAL(textEdited(QString)), this, SLOT(sHandleCompleter())); else if (!_x_metrics->boolean("DisableAutoComplete")) connect(this, SIGNAL(textEdited(QString)), this, SLOT(sHandleCompleter())); } setDisabled(_editMode && _x_metrics->value("CRMAccountNumberGeneration") == "A"); if (!_editMode) selectAll(); emit editable(p); return p; }
void ContactCluster::populate() { if (id() == -1) { _phone->clear(); _phone2->clear(); _fax->clear(); _email->clear(); _webaddr->clear(); _addr->clear(); setName(0, ""); setName(1, ""); setName(2, ""); setName(3, ""); setName(4, ""); _crmAcctId = -1; } else { if (_number->completer()) disconnect(_number, SIGNAL(textChanged(QString)), _number, SLOT(sHandleCompleter())); XSqlQuery dataQ; dataQ.prepare("SELECT cntct_honorific, cntct_first_name, " " cntct_middle, cntct_last_name, cntct_suffix, " " cntct_phone, cntct_phone2, " " cntct_fax, cntct_email, cntct_webaddr, " " formatAddr(cntct_addr_id) AS address, " " cntct_crmacct_id " "FROM cntct " "WHERE (cntct_id=:id);"); dataQ.bindValue(":id", id()); dataQ.exec(); if (dataQ.first()) { setName(0, dataQ.value("cntct_honorific").toString()); setName(1, dataQ.value("cntct_first_name").toString()); setName(2, dataQ.value("cntct_middle").toString()); setName(3, dataQ.value("cntct_last_name").toString()); setName(4, dataQ.value("cntct_suffix").toString()); _phone->setText(dataQ.value("cntct_phone").toString()); _phone2->setText(dataQ.value("cntct_phone2").toString()); _fax->setText(dataQ.value("cntct_fax").toString()); _email->setText(dataQ.value("cntct_email").toString()); _webaddr->setText(dataQ.value("cntct_webaddr").toString()); _email->setURL("mailto:" + dataQ.value("cntct_email").toString()); QUrl url(dataQ.value("cntct_webaddr").toString()); if(url.scheme().isEmpty()) url.setScheme("http"); _webaddr->setURL(url.toString()); _addr->setText(dataQ.value("address").toString()); _crmAcctId=-1; } if (_number->completer()) connect(_number, SIGNAL(textChanged(QString)), _number, SLOT(sHandleCompleter())); } }
void ItemLineEdit::silentSetId(const int pId) { XSqlQuery item; bool found = FALSE; _parsed = TRUE; if (_useValidationQuery) { item.prepare(_validationSql); item.bindValue(":item_id", pId); item.exec(); if (item.first()) found = TRUE; } else if (_useQuery) { item.prepare(_sql); item.exec(); found = (item.findFirst("item_id", pId) != -1); } else if (pId != -1) { QString pre( "SELECT DISTINCT item_number, item_descrip1, item_descrip2," " uom_name, item_type, item_config, item_upccode"); QStringList clauses; clauses = _extraClauses; clauses << "(item_id=:item_id)"; item.prepare(buildItemLineEditQuery(pre, clauses, QString::null, _type)); item.bindValue(":item_id", pId); item.exec(); found = item.first(); } if (found) { if (completer()) { disconnect(this, SIGNAL(textChanged(QString)), this, SLOT(sHandleCompleter())); static_cast<QSqlQueryModel* >(completer()->model())->setQuery(QSqlQuery()); } _itemNumber = item.value("item_number").toString(); _uom = item.value("uom_name").toString(); _itemType = item.value("item_type").toString(); _configured = item.value("item_config").toBool(); _upc = item.value("item_upccode").toString(); _id = pId; _valid = TRUE; setText(item.value("item_number").toString()); emit aliasChanged(""); emit typeChanged(_itemType); emit descrip1Changed(item.value("item_descrip1").toString()); emit descrip2Changed(item.value("item_descrip2").toString()); emit uomChanged(item.value("uom_name").toString()); emit configured(item.value("item_config").toBool()); emit upcChanged(item.value("item_upccode").toString()); emit valid(TRUE); if (completer()) connect(this, SIGNAL(textChanged(QString)), this, SLOT(sHandleCompleter())); } else { _itemNumber = ""; _uom = ""; _itemType = ""; _id = -1; _upc = ""; _valid = FALSE; setText(""); emit aliasChanged(""); emit typeChanged(""); emit descrip1Changed(""); emit descrip2Changed(""); emit uomChanged(""); emit configured(FALSE); emit upcChanged(""); emit valid(FALSE); } }
VirtualClusterLineEdit::VirtualClusterLineEdit(QWidget* pParent, const char* pTabName, const char* pIdColumn, const char* pNumberColumn, const char* pNameColumn, const char* pDescripColumn, const char* pExtra, const char* pName, const char* pActiveColumn) : XLineEdit(pParent, pName) { if (DEBUG) qDebug("VirtualClusterLineEdit(%p, %s, %s, %s, %s, %s, %s, %s, %s)", pParent ? pParent : 0, pTabName ? pTabName : "", pIdColumn ? pIdColumn : "", pNumberColumn ? pNumberColumn : "", pNameColumn ? pNameColumn : "", pDescripColumn ? pDescripColumn : "", pExtra ? pExtra : "", pName ? pName : "", pActiveColumn ? pActiveColumn : ""); setObjectName(pName ? pName : "VirtualClusterLineEdit"); _valid = false; _parsed = true; _strict = true; _completer = 0; _showInactive = false; _completerId = 0; setTableAndColumnNames(pTabName, pIdColumn, pNumberColumn, pNameColumn, pDescripColumn, pActiveColumn); if (pExtra && QString(pExtra).trimmed().length()) _extraClause = pExtra; setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); clear(); _titleSingular = tr("Object"); _titlePlural = tr("Objects"); // Completer set up if (_x_metrics) { if (!_x_metrics->boolean("DisableAutoComplete")) { QSqlQueryModel* hints = new QSqlQueryModel(this); _completer = new QCompleter(hints,this); _completer->setWidget(this); QTreeView* view = new QTreeView(this); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setHeaderHidden(true); view->setRootIsDecorated(false); _completer->setPopup(view); _completer->setCaseSensitivity(Qt::CaseInsensitive); _completer->setCompletionColumn(1); _completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel); connect(this, SIGNAL(textEdited(QString)), this, SLOT(sHandleCompleter())); connect(_completer, SIGNAL(highlighted(QString)), this, SLOT(setText(QString))); connect(_completer, SIGNAL(highlighted(const QModelIndex &)), this, SLOT(completerHighlighted(const QModelIndex &))); } }
VirtualClusterLineEdit::VirtualClusterLineEdit(QWidget* pParent, const char* pTabName, const char* pIdColumn, const char* pNumberColumn, const char* pNameColumn, const char* pDescripColumn, const char* pExtra, const char* pName, const char* pActiveColumn) : XLineEdit(pParent, pName) { if (DEBUG) qDebug("VirtualClusterLineEdit(%p, %s, %s, %s, %s, %s, %s, %s, %s)", pParent ? pParent : 0, pTabName ? pTabName : "", pIdColumn ? pIdColumn : "", pNumberColumn ? pNumberColumn : "", pNameColumn ? pNameColumn : "", pDescripColumn ? pDescripColumn : "", pExtra ? pExtra : "", pName ? pName : "", pActiveColumn ? pActiveColumn : ""); setObjectName(pName ? pName : "VirtualClusterLineEdit"); _valid = false; _parsed = true; _strict = true; _completer = 0; _showInactive = false; setTableAndColumnNames(pTabName, pIdColumn, pNumberColumn, pNameColumn, pDescripColumn, pActiveColumn); if (pExtra && QString(pExtra).trimmed().length()) _extraClause = pExtra; setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); clear(); _titleSingular = tr("Object"); _titlePlural = tr("Objects"); // Completer set up if (_x_metrics) { if (!_x_metrics->boolean("DisableAutoComplete")) { QSqlQueryModel* hints = new QSqlQueryModel(this); _completer = new QCompleter(hints,this); _completer->setWidget(this); QTreeView* view = new QTreeView(this); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setHeaderHidden(true); view->setRootIsDecorated(false); _completer->setPopup(view); _completer->setCaseSensitivity(Qt::CaseInsensitive); _completer->setCompletionColumn(1); _completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel); connect(this, SIGNAL(textEdited(QString)), this, SLOT(sHandleCompleter())); connect(_completer, SIGNAL(highlighted(QString)), this, SLOT(setText(QString))); } } // Set up actions connect(_listAct, SIGNAL(triggered()), this, SLOT(sList())); connect(_searchAct, SIGNAL(triggered()), this, SLOT(sSearch())); _infoAct = new QAction(tr("Info..."), this); _infoAct->setShortcut(QKeySequence(tr("Ctrl+Shift+I"))); _infoAct->setShortcutContext(Qt::WidgetWithChildrenShortcut); _infoAct->setToolTip(tr("View record information")); _infoAct->setEnabled(false); connect(_infoAct, SIGNAL(triggered()), this, SLOT(sInfo())); addAction(_infoAct); _openAct = new QAction(tr("Open..."), this); _openAct->setShortcut(QKeySequence(tr("Ctrl+Shift+O"))); _openAct->setShortcutContext(Qt::WidgetWithChildrenShortcut); _openAct->setToolTip(tr("Open record detail")); _openAct->setEnabled(false); connect(_openAct, SIGNAL(triggered()), this, SLOT(sOpen())); addAction(_openAct); _newAct = new QAction(tr("New..."), this); _newAct->setShortcut(QKeySequence(tr("Ctrl+Shift+N"))); _newAct->setShortcutContext(Qt::WidgetWithChildrenShortcut); _newAct->setToolTip(tr("Create new record")); _newAct->setEnabled(false); connect(_newAct, SIGNAL(triggered()), this, SLOT(sNew())); addAction(_newAct); connect(this, SIGNAL(valid(bool)), _infoAct, SLOT(setEnabled(bool))); _menuLabel = new QLabel(this); // Menu set up _menu = 0; _menuLabel->setPixmap(QPixmap(":/widgets/images/magnifier.png")); _menuLabel->installEventFilter(this); int height = minimumSizeHint().height(); QString sheet = QLatin1String("QLineEdit{ padding-right: "); sheet += QString::number(_menuLabel->pixmap()->width() + 6); sheet += QLatin1String(";}"); setStyleSheet(sheet); // Little hack. Somehow style sheet makes widget short. Put back height. setMinimumHeight(height); // Set default menu with standard actions QMenu* menu = new QMenu; menu->addAction(_listAct); menu->addAction(_searchAct); menu->addSeparator(); menu->addAction(_infoAct); setMenu(menu); connect(this, SIGNAL(valid(bool)), this, SLOT(sUpdateMenu())); connect(menu, SIGNAL(aboutToShow()), this, SLOT(sUpdateMenu())); }