00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 }
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 }
00142
00143 mdb_idcliente = id;
00144
00146 if (id == "") {
00147 _depura("END SubForm2Bt::setIdCliente", 0, "idcliente invalido");
00148 return;
00149 }
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 }
00164
00165 if (curcliente->valor("recargoeqcliente") == "t") {
00166 rec->setDBvalue("reqeq" + m_tablename, cur1->valor("porcentretasa_iva"));
00167 }
00168
00169 }
00170 delete cur1;
00171 delete cur;
00172 }
00173 }
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 }
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 }
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 }
00216 if (curproveedor->valor("recargoeqproveedor") == "t") {
00217 rec->setDBvalue("reqeq"+m_tablename, cur1->valor("porcentretasa_iva"));
00218 }
00219
00220 }
00221 delete cur1;
00222 delete cur;
00223 }
00224 }
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
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00329
00330
00331
00332
00333 return QItemDelegate::createEditor(parent, option, index);
00334 }
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
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 } else {
00392 QItemDelegate::setModelData(editor, model, index);
00393 }
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
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 } else {
00444 QItemDelegate::setEditorData(editor, index);
00445 }
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 }
00472 case Qt::Key_Tab:
00473 return TRUE;
00474 }
00475 return QItemDelegate::eventFilter(obj, event);
00476 }
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 }
00492 case Qt::Key_Tab:
00493 QApplication::sendEvent(m_subform->mui_list, event);
00494 return TRUE;
00495 }
00496 return QItemDelegate::eventFilter(obj, event);
00497 }
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