subform2bt.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Tomeu Borras Riera                              *
00003  *   tborras@conetxia.com                                                  *
00004  *   http://www.iglues.org -- BulmaFact Facturacion GPL                    *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  *   This program is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU General Public License for more details.                          *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this program; if not, write to the                         *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00020  ***************************************************************************/
00021 
00022 #include <QMessageBox>
00023 #include <QMenu>
00024 #include <QKeyEvent>
00025 #include <QEvent>
00026 #include <QComboBox>
00027 #include <QAbstractItemView>
00028 
00029 #include "subform2bt.h"
00030 #include "funcaux.h"
00031 #include "qtexteditdelegate.h"
00032 #include "plugins.h"
00033 
00034 
00036 
00039 SubForm2Bt::SubForm2Bt(QWidget *parent) : SubForm3(parent) {
00040     _depura("SubForm2Bt::SubForm2Bt", 0);
00041     setDelete(TRUE);
00042     m_delegate = new QSubForm2BtDelegate(this);
00043     mui_list->setItemDelegate(m_delegate);
00044     mdb_idcliente = "";
00045     _depura("END SubForm2Bt::SubForm2Bt", 0);
00046 }
00047 
00048 
00050 
00052 SubForm2Bt::~SubForm2Bt() {
00053     _depura("SubForm2Bt::~SubForm2Bt", 0);
00054     delete m_delegate;
00055     _depura("END SubForm2Bt::~SubForm2Bt", 0);
00056 }
00057 
00058 
00060 
00063 void SubForm2Bt::cargar(QString query) {
00064     _depura("SubForm2Bt::cargar", 0);
00065     SubForm3::cargar(query);
00066     _depura("END SubForm2Bt::cargar", 0);
00067 }
00068 
00069 
00071 
00076 void SubForm2Bt::on_mui_list_pressedAsterisk(int row, int col) {
00077     _depura("SubForm2Bt::pressedAsterisk", 0);
00078     _depura("END SubForm2Bt::pressedAsterisk", 0);
00079 }
00080 
00081 
00083 
00087 void SubForm2Bt::on_mui_list_pressedSlash(int row, int col) {
00088     _depura("SubForm2Bt::pressedSlash", 0);
00089     SDBCampo *camp = (SDBCampo *) item(row, col);
00090     QString text = editaTexto(camp->text());
00091     camp->set(text);
00092     _depura("END SubForm2Bt::pressedSlash", 0);
00093 }
00094 
00095 
00097 
00101 void SubForm2Bt::on_mui_list_pressedMinus(int row, int col) {
00102     _depura("SubForm2Bt::pressedMinus", 0);
00103     _depura("END SubForm2Bt::pressedMinus", 0);
00104 }
00105 
00106 
00108 
00113 void SubForm2Bt::on_mui_list_cellChanged(int row, int col) {
00114     _depura("SubForm2Bt::on_mui_list_cellChanged", 0, QString::number(row) + " " + QString::number(col));
00115     _depura("END SubForm2Bt::on_mui_list_editFinished", 0);
00116 }
00117 
00118 
00120 
00124 void SubForm2Bt::setIdCliente(QString id) {
00125     _depura("SubForm2Bt::setIdCliente", 0, id);
00126 
00128     if (mdb_idcliente  == "" ) {
00129     mdb_idcliente = id;
00130     return;
00131     } // end if
00132 
00134     if (mdb_idcliente == id) return;
00135 
00137     for (int i = 0; i < rowCount() - 1; i++) {
00138         SDBRecord *rec = lineaat(i);
00139         rec->setDBvalue("iva" + m_tablename, "0");
00140         rec->setDBvalue("reqeq" + m_tablename, "0");
00141     } // end for
00142 
00143     mdb_idcliente = id;
00144 
00146     if (id == "") {
00147         _depura("END SubForm2Bt::setIdCliente", 0, "idcliente invalido");
00148         return;
00149     } // end if
00150 
00151     cursor2 *curcliente = empresaBase()->cargacursor("SELECT recargoeqcliente, regimenfiscalcliente FROM cliente WHERE idcliente = " + mdb_idcliente);
00152 
00153     if (!curcliente->eof()) {
00155         for (int i = 0; i < rowCount() - 1; i++) {
00156             SDBRecord *rec = lineaat(i);
00157             cursor2 *cur = empresaBase()->cargacursor("SELECT * FROM articulo WHERE idarticulo = " + rec->DBvalue("idarticulo") );
00158             cursor2 *cur1 = empresaBase()->cargacursor("SELECT * FROM tasa_iva WHERE idtipo_iva = " + cur->valor("idtipo_iva") + " ORDER BY fechatasa_iva LIMIT 1");
00159             if (!cur->eof()) {
00160 
00161                 if (curcliente->valor("regimenfiscalcliente") == "Normal") {
00162                     rec->setDBvalue("iva" + m_tablename, cur1->valor("porcentasa_iva"));
00163                 } // end if
00164 
00165                 if (curcliente->valor("recargoeqcliente") == "t") {
00166                     rec->setDBvalue("reqeq" + m_tablename, cur1->valor("porcentretasa_iva"));
00167                 } // end if
00168 
00169             } // end if
00170             delete cur1;
00171             delete cur;
00172         } // end for
00173     } // end if
00174     delete curcliente;
00175     _depura("END SubForm2Bt::setIdCliente", 0);
00176 }
00177 
00178 
00180 
00184 void SubForm2Bt::setIdProveedor(QString id) {
00185     _depura("SubForm2Bt::setIdProveedor", 0, id);
00186 
00188     if (mdb_idproveedor  == "" ) {
00189         mdb_idproveedor = id;
00190         return;
00191     } // end if
00192 
00194     if (mdb_idproveedor == id) return;
00195 
00196     mdb_idproveedor = id;
00197 
00199     for (int i = 0; i < rowCount() - 1; i++) {
00200         SDBRecord *rec = lineaat(i);
00201         rec->setDBvalue("iva"+m_tablename, "0");
00202         rec->setDBvalue("reqeq"+m_tablename, "0");
00203     } // end for
00204 
00205     cursor2 *curproveedor = empresaBase()->cargacursor("SELECT recargoeqproveedor, regimenfiscalproveedor FROM proveedor WHERE idproveedor="+mdb_idproveedor);
00206     if (!curproveedor->eof()) {
00208         for (int i = 0; i < rowCount() - 1; i++) {
00209             SDBRecord *rec = lineaat(i);
00210             cursor2 *cur = empresaBase()->cargacursor("SELECT * FROM articulo WHERE idarticulo = " + rec->DBvalue("idarticulo") );
00211             cursor2 *cur1 = empresaBase()->cargacursor("SELECT * FROM tasa_iva WHERE idtipo_iva = " + cur->valor("idtipo_iva") + " ORDER BY fechatasa_iva LIMIT 1");
00212             if (!cur->eof() ) {
00213                 if (curproveedor->valor("regimenfiscalproveedor") == "Normal") {
00214                     rec->setDBvalue("iva"+m_tablename, cur1->valor("porcentasa_iva"));
00215                 } // end if
00216                 if (curproveedor->valor("recargoeqproveedor") == "t") {
00217                     rec->setDBvalue("reqeq"+m_tablename, cur1->valor("porcentretasa_iva"));
00218                 } // end if
00219 
00220             } // end if
00221             delete cur1;
00222             delete cur;
00223         } // end for
00224     } // end if
00225     delete curproveedor;
00226     _depura("END SubForm2Bt::setIdProveedor", 0);
00227 }
00228 
00229 
00231 
00234 void SubForm2Bt::setEmpresaBase(EmpresaBase *c) {
00235     _depura("SubForm2Bt::setcompany", 0);
00236     SubForm3::setEmpresaBase(c);
00237     m_delegate->setEmpresaBase(c);
00238     _depura("END SubForm2Bt::setcompany", 0);
00239 }
00240 
00241 
00243 
00246 int SubForm2Bt::cerrarEditor() {
00247     _depura("SubForm2Bt::cerrarEditor", 0);
00248     QWidget *editor = mui_list->QAbstractItemView::indexWidget(mui_list->currentIndex());
00249     m_delegate->cerrarEditor(editor);
00250     _depura("END SubForm2Bt::cerrarEditor", 0);
00251     return 0;
00252 }
00253 
00254 
00259 
00262 QSubForm2BtDelegate::QSubForm2BtDelegate(QObject *parent = 0) : QItemDelegate(parent), PEmpresaBase() {
00263     _depura("QSubForm2BtDelegate::QSubForm2BtDelegate", 0);
00264     m_subform = (SubForm2Bt *) parent;
00265     installEventFilter(this);
00266     _depura("END QSubForm2BtDelegate::QSubForm2BtDelegate", 0);
00267 }
00268 
00269 
00271 
00273 QSubForm2BtDelegate::~QSubForm2BtDelegate() {
00274     _depura("QSubForm2BtDelegate::~QSubForm2BtDelegate", 0);
00275     _depura("END QSubForm2BtDelegate::~QSubForm2BtDelegate", 0);
00276 }
00277 
00278 
00280 
00285 QWidget *QSubForm2BtDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
00286     _depura("QSubForm2BtDelegate::createEditor", 0);
00287     SHeader *linea;
00288     linea = m_subform->cabecera()->at(index.column());
00289     _depura("QSubForm2BtDelegate::createEditor", 0, "CurrentColumn: " + QString::number(index.column()));
00290     _depura("QSubForm2BtDelegate::createEditor", 0, "CurrentRow" + QString::number(index.row()));
00291 
00292     if (linea->nomcampo() == "desc" + m_subform->tableName()) {
00293         QTextEditDelegate *editor = new QTextEditDelegate(parent);
00294         editor->setObjectName("QTextEditDelegate");
00295         return editor;
00296 
00297     } else if (linea->nomcampo() == "cant" + m_subform->tableName()
00298                 || linea->nomcampo() == "pvp" + m_subform->tableName()
00299                 || linea->nomcampo() == "descuento" + m_subform->tableName()
00300                 || linea->nomcampo() == "iva" + m_subform->tableName()
00301                 || linea->nomcampo() == "reqeq" + m_subform->tableName()) {
00302 
00303         QDoubleSpinBox2 *editor = new QDoubleSpinBox2(parent);
00304         editor->setMinimum(-1000000);
00305         editor->setMaximum(1000000);
00306         return editor;
00307 
00308 /*
00309     } else if (linea->nomcampo() == "codigocompletoarticulo") {
00310         BusquedaArticuloDelegate *editor = new BusquedaArticuloDelegate(parent);
00311         editor->setEmpresaBase((Company *)m_subform->empresaBase());
00312         return editor;
00313     } else if (linea->nomcampo() == "desctipo_iva") {
00314         BusquedaTipoIVADelegate *editor = new BusquedaTipoIVADelegate(parent);
00315         editor->setEmpresaBase((Company *)m_subform->empresaBase());
00316         return editor;
00317     } else if (linea->nomcampo() == "nomtrabajador") {
00318         BusquedaTrabajadorDelegate *editor = new BusquedaTrabajadorDelegate(parent);
00319         editor->setEmpresaBase((Company *)m_subform->empresaBase());
00320         return editor;
00321     } else if (linea->nomcampo() == "nomalmacen") {
00322         BusquedaAlmacenDelegate *editor = new BusquedaAlmacenDelegate(parent);
00323         editor->setEmpresaBase((Company *)m_subform->empresaBase());
00324         return editor;
00325     } else  {
00326 //        QWidget *it = QItemDelegate::createEditor(parent, option, index);
00327 //        if (linea->tipo() == DBint) {
00329 //        } else {
00330 
00331 //        } // end if
00332 */
00333         return QItemDelegate::createEditor(parent, option, index);
00334     } // end if
00335     _depura("END QSubForm2BtDelegate::createEditor", 0);
00336 }
00337 
00338 
00340 
00346 void QSubForm2BtDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
00347     _depura("QSubForm2BtDelegate::setModelData", 0);
00348     _depura("QSubForm2BtDelegate::setModelData", 0, "CurrentColumn: " + QString::number(index.column()));
00349     _depura("QSubForm2BtDelegate::setModelData", 0, "CurrentRow: " + QString::number(index.row()));
00350 
00352     if (index.column() < 0 || index.row() < 0)
00353         return;
00354 
00355     SHeader *linea;
00356     linea = m_subform->cabecera()->at(index.column());
00357     if (linea->nomcampo() == "desc" + m_subform->tableName()) {
00358         QTextEditDelegate *textedit = qobject_cast<QTextEditDelegate *>(editor);
00359         model->setData(index, textedit->toPlainText());
00360         return;
00361 
00362     } else if (linea->nomcampo() == "cant" + m_subform->tableName()
00363                 || linea->nomcampo() == "pvp" + m_subform->tableName()
00364                 || linea->nomcampo() == "descuento" + m_subform->tableName()
00365                 || linea->nomcampo() == "reqeq" + m_subform->tableName()
00366                 || linea->nomcampo() == "iva" + m_subform->tableName()) {
00367 
00368         QDoubleSpinBox2 *spinBox = static_cast<QDoubleSpinBox2*>(editor);
00369         spinBox->interpretText();
00370         QString value = spinBox->text();
00371         model->setData(index, value);
00372 /*
00373     } else if (linea->nomcampo() == "codigocompletoarticulo") {
00374         BusquedaArticuloDelegate *comboBox = static_cast<BusquedaArticuloDelegate*>(editor);
00375         QString value = comboBox->currentText();
00376         value = value.left(value.indexOf(".-"));
00377         model->setData(index, value);
00378     } else if (linea->nomcampo() == "desctipo_iva") {
00379         BusquedaTipoIVADelegate *comboBox = static_cast<BusquedaTipoIVADelegate*>(editor);
00380         QString value = comboBox->currentText();
00381         model->setData(index, value);
00382     } else if (linea->nomcampo() == "nomtrabajador") {
00383         BusquedaTrabajadorDelegate *comboBox = static_cast<BusquedaTrabajadorDelegate*>(editor);
00384         QString value = comboBox->currentText();
00385         model->setData(index, value);
00386     } else if (linea->nomcampo() == "nomalmacen") {
00387         BusquedaAlmacenDelegate *comboBox = static_cast<BusquedaAlmacenDelegate*>(editor);
00388         QString value = comboBox->currentText();
00389         model->setData(index, value);
00390 */
00391     } else {
00392         QItemDelegate::setModelData(editor, model, index);
00393     } // end if
00394     _depura("END QSubForm2BtDelegate::setModelData", 0);
00395 }
00396 
00397 
00399 
00403 void QSubForm2BtDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const {
00404     _depura("QSubForm2BtDelegate::setEditorData", 0);
00405     _depura("QSubForm2BtDelegate::setEditorData", 0, "CurrentColumn: " + QString::number(index.column()));
00406     _depura("QSubForm2BtDelegate::setEditorData", 0, "CurrentRow: " + QString::number(index.row()));
00407     SHeader *linea;
00408     linea = m_subform->cabecera()->at(index.column());
00409     if (linea->nomcampo() == "desc" + m_subform->tableName()) {
00410         QString data = index.model()->data(index, Qt::DisplayRole).toString();
00411         QTextEditDelegate *textedit = qobject_cast<QTextEditDelegate*>(editor);
00412         textedit->setText(data);
00413 
00414     } else if (linea->nomcampo() == "cant" + m_subform->tableName()
00415                 || linea->nomcampo() == "pvp" + m_subform->tableName()
00416                 || linea->nomcampo() == "descuento" + m_subform->tableName()
00417                 || linea->nomcampo() == "reqeq" + m_subform->tableName()
00418                 || linea->nomcampo() == "iva" + m_subform->tableName()) {
00419 
00420         QString value = index.model()->data(index, Qt::DisplayRole).toString();
00421         QDoubleSpinBox2 *spinBox = static_cast<QDoubleSpinBox2*>(editor);
00422         spinBox->setValue(value.toDouble());
00423         spinBox->selectAll();
00424 
00425 /*
00426     } else if (linea->nomcampo() == "codigocompletoarticulo") {
00427         QString value = index.model()->data(index, Qt::DisplayRole).toString();
00428         BusquedaArticuloDelegate *comboBox = static_cast<BusquedaArticuloDelegate*>(editor);
00429         comboBox->addItem(value);
00430     } else if (linea->nomcampo() == "desctipo_iva") {
00431         QString value = index.model()->data(index, Qt::DisplayRole).toString();
00432         BusquedaTipoIVADelegate *comboBox = static_cast<BusquedaTipoIVADelegate*>(editor);
00433         comboBox->set(value);
00434     } else if (linea->nomcampo() == "nomtrabajador") {
00435         QString value = index.model()->data(index, Qt::DisplayRole).toString();
00436         BusquedaTrabajadorDelegate *comboBox = static_cast<BusquedaTrabajadorDelegate*>(editor);
00437         comboBox->set(value);
00438     } else if (linea->nomcampo() == "nomalmacen") {
00439         QString value = index.model()->data(index, Qt::DisplayRole).toString();
00440         BusquedaAlmacenDelegate *comboBox = static_cast<BusquedaAlmacenDelegate*>(editor);
00441         comboBox->set(value);
00442 */
00443     } else {
00444         QItemDelegate::setEditorData(editor, index);
00445     } // end if
00446     _depura("END QSubForm2BtDelegate::setEditorData", 0);
00447 }
00448 
00449 
00451 
00456 bool QSubForm2BtDelegate::eventFilter(QObject *obj, QEvent *event) {
00458     if (event->type() == QEvent::KeyPress) {
00459         _depura("QSubForm2BtDelegate::eventFilter", 0, obj->objectName() + " --> " + QString::number(event->type()));
00460         QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
00461         int key = keyEvent->key();
00462         _depura("QSubForm2BtDelegate::key = : ", 0, QString::number(key));
00463         Qt::KeyboardModifiers mod = keyEvent->modifiers();
00465         switch (key) {
00466         case Qt::Key_Return:
00467         case Qt::Key_Enter:
00468             if (obj->objectName() == "QTextEditDelegate") {
00469                 obj->event(event);
00470                 return TRUE;
00471             } // end if
00472         case Qt::Key_Tab:
00473             return TRUE;
00474         } // end switch
00475         return QItemDelegate::eventFilter(obj, event);
00476     } // end if
00477 
00478     if (event->type() == QEvent::KeyRelease) {
00479         _depura("QSubForm2BtDelegate::eventFilter", 0, obj->objectName() + " --> " + QString::number(event->type()));
00480         QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
00481         int key = keyEvent->key();
00482         _depura("QSubForm2BtDelegate::key = : ", 0, QString::number(key));
00483         Qt::KeyboardModifiers mod = keyEvent->modifiers();
00485         switch (key) {
00486         case Qt::Key_Return:
00487         case Qt::Key_Enter:
00488             if (obj->objectName() == "QTextEditDelegate") {
00489                 obj->event(event);
00490                 return TRUE;
00491             } // end if
00492         case Qt::Key_Tab:
00493             QApplication::sendEvent(m_subform->mui_list, event);
00494             return TRUE;
00495         } // end switch
00496         return QItemDelegate::eventFilter(obj, event);
00497     } // end if
00498 
00499     return QItemDelegate::eventFilter(obj, event);
00500 }
00501 
00502 
00504 
00508 int QSubForm2BtDelegate::cerrarEditor(QWidget *editor) {
00509     _depura("QSubForm2BtDelegate::cerrarEditor", 0);
00510     emit closeEditor(editor, QAbstractItemDelegate::NoHint);
00511     _depura("END QSubForm2BtDelegate::cerrarEditor", 0);
00512     return 0;
00513 }
00514 

Generated on Sat Dec 15 00:01:24 2007 for BulmaGes by  doxygen 1.5.1