subform3.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Tomeu Borras Riera                              *
00003  *   tborras@conetxia.com                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <QKeyEvent>
00022 #include <QEvent>
00023 #include <QFile>
00024 #include <QHeaderView>
00025 #include <QTextStream>
00026 #include <QMenu>
00027 #include <QShortcut>
00028 #include <QLocale>
00029 #include <QRegExp>
00030 #include <QDomDocument>
00031 #include <QDomNode>
00032 
00033 #include "subform3.h"
00034 
00035 
00037 
00040 SubForm3::SubForm3(QWidget *parent) : BLWidget(parent) {
00041     _depura("SubForm3::SubForm3", 0);
00042     setupUi(this);
00045     m_prevCol = -1;
00046     m_prevRow = -1;
00047 
00049     m_procesacambios = FALSE;
00050 
00051     m_textoceldaParaRowSpan = "";
00052     m_filaInicialRowSpan = -1;
00053 
00055     int res = g_plugins->lanza("SubForm3_SubForm3", this);
00056     if (res != 0) {
00057         m_procesacambios = TRUE;
00058         return;
00059     } // end if
00060 
00061     mui_list->setSelectionMode(QAbstractItemView::SingleSelection);
00062     mui_list->setSelectionBehavior(QAbstractItemView::SelectRows);
00063     mui_list->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
00064     mui_list->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
00065     mui_list->setSortingEnabled(FALSE);
00067     mui_list->horizontalHeader()->setMovable(TRUE);
00069     setListadoPijama(TRUE);
00070     QPalette p;
00071     p = mui_list->palette();
00072     m_colorfondo1 = p.color(QPalette::Normal, QPalette::Base);
00073     m_colorfondo2 = p.color(QPalette::Normal, QPalette::AlternateBase);
00074 
00077     QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+B"), this);
00078     connect(shortcut, SIGNAL(activated()), this, SLOT(toogleConfig()));
00079 
00080     m_insercion = FALSE;
00081     m_primero = TRUE;
00082     m_sorting = FALSE;
00083     m_orden = FALSE;
00084     m_ordenporquery = FALSE;
00085 
00087     QStringList headers;
00088     headers << "" << tr("Nombre") << tr("Nombre de campo") << tr("Visible");
00089     mui_listcolumnas->setColumnCount(4);
00090     mui_listcolumnas->setHorizontalHeaderLabels(headers);
00091     mui_listcolumnas->setShowGrid(FALSE);
00092     mui_listcolumnas->setColumnWidth(0, 25);
00093     mui_listcolumnas->setColumnWidth(1, 100);
00094     mui_listcolumnas->setColumnWidth(2, 175);
00095     mui_listcolumnas->setColumnWidth(3, 0);
00096     mui_listcolumnas->setSelectionBehavior(QAbstractItemView::SelectRows);
00097     mui_listcolumnas->verticalHeader()->hide();
00098     mui_listcolumnas->setEditTriggers(QAbstractItemView::NoEditTriggers);
00099     mui_listcolumnas->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
00100 
00102     mui_paginaact->setValue(1);
00104     hideConfig();
00106     m_lista.clear();
00107     m_listaborrar.clear();
00108 
00111     m_prevCol = -1;
00112     m_prevRow = -1;
00113     setDelete(TRUE);
00114 
00116     g_plugins->lanza("SubForm3_SubForm3_Post", this);
00117     m_procesacambios = TRUE;
00118     _depura("END SubForm3::SubForm3", 0);
00119 }
00120 
00121 
00122 
00124 
00126 SubForm3::~SubForm3() {
00127     _depura("SubForm3::~SubForm3", 0);
00129     m_procesacambios = FALSE;
00130     guardaconfig();
00131     _depura("END SubForm3::~SubForm3", 0);
00132 }
00133 
00134 
00136 
00139 void SubForm3::setEmpresaBase(EmpresaBase *emp) {
00140     _depura("PEmpresaBase::setEmpresaBase", 0);
00141     PEmpresaBase::setEmpresaBase(emp);
00142     cargaSpecs();
00143     _depura("END PEmpresaBase::setEmpresaBase", 0);
00144 }
00145 
00146 
00148 
00150 void SubForm3::cargaSpecs() {
00151     _depura("SubForm3::cargaSpecs", 0 );
00152 //    QFile file(confpr->valor(CONF_DIR_USER) + m_fileconfig + "_" + empresaBase()->nameDB() + "_specs.spc");
00153     QFile file("/etc/bulmages/" + m_fileconfig + "_" + empresaBase()->nameDB() + "_specs.spc");
00154     QDomDocument doc("mydocument");
00155     if (!file.open(QIODevice::ReadOnly))
00156         return;
00157     if (!doc.setContent(&file)) {
00158         file.close();
00159         return;
00160     }
00161     file.close();
00162 
00163     QDomElement docElem = doc.documentElement();
00164     QDomElement principal = docElem.firstChildElement("SUBFORM");
00166     QString tablename = principal.firstChildElement("TABLENAME").toElement().text();
00167     QString campoid = principal.firstChildElement("CAMPOID").toElement().text();
00168 
00169     QDomNodeList nodos = docElem.elementsByTagName("HEADER");
00170     for (int i = 0; i < nodos.count(); i++) {
00171         QDomNode ventana = nodos.item(i);
00172         QDomElement e1 = ventana.toElement(); 
00173         if ( !e1.isNull() ) { 
00174             DBCampo::dbtype type= DBCampo::DBvarchar;
00175             QString nomheader = e1.firstChildElement("NOMHEADER").toElement().text();
00176             QString nompheader = e1.firstChildElement("NOMPHEADER").toElement().text();
00177             QString typeheader = e1.firstChildElement("DBTYPEHEADER").toElement().text();
00178             if (typeheader == "DBVARCHAR") {
00179                 type = DBCampo::DBvarchar;
00180             } else if (typeheader == "DBINT") {
00181                 type = DBCampo::DBint;
00182             } else if (typeheader == "DBNUMERIC") {
00183                 type = DBCampo::DBnumeric;
00184             } else if (typeheader == "DBBOOLEAN") {
00185                 type = DBCampo::DBboolean;
00186             } else if (typeheader == "DBDATE") {
00187                 type = DBCampo::DBdate;
00188             } // end if
00189 
00190             int restricciones = (int) DBCampo::DBNothing;
00191             QDomElement restrict = e1.firstChildElement("RESTRICTIONSHEADER");
00192             while (!restrict.isNull()) {
00193                 QString trestrict = restrict.text();
00194                 if (trestrict == "DBNOTHING") {
00195                    restricciones |= DBCampo::DBvarchar;
00196                 } else if (trestrict == "DBNOTNULL") {
00197                    restricciones |= DBCampo::DBNotNull;
00198                 } else if (trestrict == "DBPRIMARYKEY") {
00199                    restricciones |= DBCampo::DBPrimaryKey;
00200                 } else if (trestrict == "DBNOSAVE") {
00201                    restricciones |= DBCampo::DBNoSave;
00202                 } else if (trestrict == "DBAUTO") {
00203                    restricciones |= DBCampo::DBAuto;
00204                 } else if (trestrict == "DBAUTO") {
00205                    restricciones |= DBCampo::DBAuto;
00206                 } else if (trestrict == "DBDUPPRIMARYKEY") {
00207                    restricciones |= DBCampo::DBDupPrimaryKey;
00208                 } else if (trestrict == "DBREQUIRED") {
00209                    restricciones |= DBCampo::DBRequired;
00210                 } else if (trestrict == "DBNOLOAD") {
00211                    restricciones |= DBCampo::DBNoLoad;
00212                 } // end if
00213                 restrict = restrict.nextSiblingElement("RESTRICTIONSHEADER");
00214             } // end while
00215 
00216             int opciones = (int) SHeader::DBNone;
00217             QDomElement opci = e1.firstChildElement("OPTIONSHEADER");
00218             while (!opci.isNull()) {
00219                 QString topci = opci.text();
00220                 if (topci == "DBNONE") {
00221                    opciones |= SHeader::DBNone;
00222                 } else if (topci == "DBREADONLY") {
00223                    opciones |= SHeader::DBReadOnly;
00224                 } else if (topci == "DBNOVIEW") {
00225                    opciones |= SHeader::DBNoView;
00226                 } else if (topci == "DBNOWRITE") {
00227                    opciones |= SHeader::DBNoWrite;
00228                 } else if (topci == "DBBLOCKVIEW") {
00229                    opciones |= SHeader::DBBlockView;
00230                 } // end if
00231                 opci = opci.nextSiblingElement("OPTIONSHEADER");
00232             } // end while
00233 
00234             addSHeader(nomheader, type, (DBCampo::dbrestrict) restricciones, (SHeader::dboptions) opciones, nompheader);
00235         } // end if
00236     } // end for
00237 
00238     _depura("END SubForm3::cargaSpecs", 0);
00239 }
00240 
00241 
00243 
00246 QList<SDBRecord *> *SubForm3::lista() {
00247     _depura("SubForm3::lista", 0);
00248     return &m_lista;
00249     _depura("END SubForm3::lista", 0);
00250 }
00251 
00252 
00254 
00257 QList<SHeader *> *SubForm3::cabecera() {
00258     _depura("SubForm3::cabecera", 0);
00259     return &m_lcabecera;
00260     _depura("END SubForm3::cabecera", 0);
00261 }
00262 
00263 
00265 
00268 void SubForm3::setHorizontalScrollMode(QAbstractItemView::ScrollMode mode) {
00269     _depura("SubForm3::setHorizontalScrollMode", 0);
00270     mui_list->setHorizontalScrollMode(mode);
00271     _depura("END SubForm3::setHorizontalScrollMode", 0);
00272 }
00273 
00274 
00276 
00279 void SubForm3::setDelete(bool f) {
00280     _depura("SubForm3::setDelete", 0);
00281     m_delete = f;
00282     _depura("END SubForm3::setDelete", 0);
00283 }
00284 
00285 
00287 
00292 SDBCampo *SubForm3::item(int row, int col) {
00293     _depura("SubForm3::item", 0);
00294     _depura("END SubForm3::item", 0);
00295     return (SDBCampo *) mui_list->item(row, col);
00296 }
00297 
00298 
00300 
00304 void SubForm3::setCurrentItem(int row, int col) {
00305     _depura("SubForm3::setCurrentItem", 0);
00306     mui_list->setCurrentItem( item(row, col));
00307     _depura("END SubForm3::setCurrentItem", 0);
00308 }
00309 
00310 
00312 
00315 int SubForm3::columnCount() {
00316     _depura("SubForm3::columnCount", 0);
00317     return mui_list->columnCount();
00318     _depura("END SubForm3::columnCount", 0);
00319 }
00320 
00321 
00323 
00326 void SubForm3::showColumn(int i) {
00327     _depura("SubForm3::showColumn", 0);
00328     mui_list->showColumn(i);
00329     _depura("END SubForm3::showColumn", 0);
00330 }
00331 
00332 
00334 
00338 int SubForm3::columnWidth(int i) {
00339     _depura("SubForm3::columnWidth", 0);
00340     _depura("END SubForm3::columnWidth", 0);
00341     return mui_list->columnWidth(i);
00342 }
00343 
00344 
00346 
00350 void SubForm3::setColumnWidth(int i, int j) {
00351     _depura("SubForm3::setColumnWidth", 0);
00352     mui_list->setColumnWidth(i, j);
00353     _depura("END SubForm3::setColumnWidth", 0);
00354 }
00355 
00356 
00358 
00361 void SubForm3::hideColumn(int i) {
00362     _depura("SubForm3::hideColumn", 0);
00363     mui_list->hideColumn(i);
00364     _depura("END SubForm3::hideColumn", 0);
00365 }
00366 
00367 
00369 
00372 int SubForm3::currentRow() {
00373     _depura("SubForm3::currentRow", 0);
00374     _depura("END SubForm3::currentRow", 0);
00375     return mui_list->currentRow();
00376 }
00377 
00378 
00380 
00383 int SubForm3::rowCount() {
00384     _depura("SubForm3::rowCount", 0);
00385     _depura("END SubForm3::rowCount", 0);
00386     return mui_list->rowCount();
00387 }
00388 
00389 
00391 
00394 int SubForm3::currentColumn() {
00395     _depura("SubForm3::currentColumn", 0);
00396     return mui_list->currentColumn();
00397     _depura("END SubForm3::currentColumn", 0);
00398 }
00399 
00400 
00402 
00405 void SubForm3::setResizeMode(QHeaderView::ResizeMode modo) {
00406     _depura("SubForm3::setResizeMode", 0);
00407     mui_list->horizontalHeader()->setResizeMode(modo);
00408     _depura("END SubForm3::setResizeMode", 0);
00409 }
00410 
00411 
00413 
00415 void SubForm3::resizeColumnsToContents() {
00416     _depura("SubForm3::resizeColumnsToContents", 0);
00417     mui_list->resizeColumnsToContents();
00418     _depura("END SubForm3::resizeColumnsToContents", 0);
00419 }
00420 
00421 
00423 
00425 void SubForm3::resizeRowsToContents() {
00426     _depura("SubForm3::resizeRowsToContents", 0);
00427     mui_list->resizeRowsToContents();
00428     _depura("END SubForm3::resizeRowsToContents", 0);
00429 }
00430 
00431 
00433 
00436 void SubForm3::resizeColumnToContents(int i) {
00437     _depura("SubForm3::resizeColumnToContents", 0);
00438     mui_list->resizeColumnToContents(i);
00439     _depura("END SubForm3::resizeColumnToContents", 0);
00440 }
00441 
00442 
00444 
00447 void SubForm3::resizeRowToContents(int i) {
00448     _depura("SubForm3::resizeRowToContents", 0);
00449     mui_list->resizeRowToContents(i);
00450     _depura("END SubForm3::resizeRowToContents", 0);
00451 }
00452 
00453 
00455 
00457 void SubForm3::hideConfig() {
00458     _depura("SubForm3::hideConfig", 0);
00459     mui_configurador->hide();
00460     _depura("END SubForm3::hideConfig", 0);
00461 }
00462 
00463 
00465 
00467 void SubForm3::showConfig() {
00468     _depura("SubForm3::showConfig", 0);
00469     mui_configurador->show();
00470     _depura("END SubForm3::showConfig", 0);
00471 }
00472 
00473 
00475 
00478 void SubForm3::setDBTableName(QString nom) {
00479     _depura("SubForm3::setDBTableName", 0);
00480     m_tablename = nom;
00481     m_fileconfig = nom;
00482     _depura("END SubForm3::setDBTableName", 0);
00483 }
00484 
00485 
00487 
00490 QString SubForm3::tableName() {
00491     _depura("SubForm3::tableName", 0);
00492     _depura("END SubForm3::tableName", 0);
00493     return m_tablename;
00494 }
00495 
00496 
00498 
00501 void SubForm3::setFileConfig(QString nom) {
00502     _depura("SubForm3::setFileConfig", 0);
00503     m_fileconfig = nom;
00504     _depura("END SubForm3::setFileConfig", 0);
00505 }
00506 
00507 
00509 
00512 void SubForm3::setDBCampoId(QString nom) {
00513     _depura("SubForm3::setDBCampoId", 0);
00514     m_campoid = nom;
00515     _depura("END SubForm3::setDBCampoId", 0);
00516 }
00517 
00518 
00520 
00522 void SubForm3::clear() {
00523     _depura("SubForm3::clear", 0);
00524     mui_list->clear();
00525     _depura("END SubForm3::clear", 0);
00526 }
00527 
00528 
00530 
00533 void SubForm3::setRowCount(int i) {
00534     _depura("SubForm3::setRowCount", 0);
00535     mui_list->setRowCount(i);
00536     _depura("END SubForm3::setRowCount", 0);
00537 }
00538 
00539 
00541 
00544 void SubForm3::setColumnCount(int i) {
00545     _depura("SubForm3::setColumnCount", 0);
00546     mui_list->setColumnCount(i);
00547     _depura("END SubForm3::setColumnCount", 0);
00548 }
00549 
00550 
00552 
00554 void SubForm3::creaMenu(QMenu *) {
00555     _depura("SubForm3:: CreaMenu", 0, "funcion para ser sobreescrita");
00556 }
00557 
00558 
00560 
00562 void SubForm3::procesaMenu(QAction *) {
00563     _depura("SubForm3:: procesaMenu", 0, "funcion para ser sobreescrita");
00564 }
00565 
00566 
00568 
00571 void SubForm3::setListadoPijama(bool pijama) {
00572     _depura("SubForm3::setListadoPijama", 0);
00573     if (pijama) {
00574         mui_list->setAlternatingRowColors(TRUE);
00575     } else {
00576         mui_list->setAlternatingRowColors(FALSE);
00577     } // end if
00578     _depura("END SubForm3::setListadoPijama", 0);
00579 }
00580 
00581 
00583 
00586 bool SubForm3::listadoPijama() {
00587     _depura("SubForm3::listadoPijama", 0);
00588     return mui_list->alternatingRowColors();
00589     _depura("END SubForm3::listadoPijama", 0);
00590 }
00591 
00592 
00593 
00595 
00598 void SubForm3::setSortingEnabled(bool sorting) {
00599     _depura("SubForm3::setSortingEnabled", 0);
00600     mui_list->setSortingEnabled(sorting);
00601     m_sorting = sorting;
00602     _depura("END SubForm3::setSortingEnabled", 0);
00603 }
00604 
00605 
00607 
00610 bool SubForm3::sortingEnabled() {
00611     _depura("SubForm3::sortingEnabled", 0);
00612     _depura("END SubForm3::sortingEnabled", 0);
00613     return m_sorting;
00614 }
00615 
00616 
00618 
00621 void SubForm3::setOrdenEnabled(bool sorting) {
00622     _depura("SubForm3::setOrdenEnabled", 0);
00623     m_orden = sorting;
00624     _depura("END SubForm3::setOrdenEnabled", 0);
00625 }
00626 
00627 
00629 
00632 bool SubForm3::ordenEnabled() {
00633     _depura("SubForm3::ordenEnabled", 0);
00634     return m_orden;
00635     _depura("END SubForm3::ordenEnabled", 0);
00636 }
00637 
00638 
00640 
00643 void SubForm3::on_mui_list_itemDoubleClicked(QTableWidgetItem *item) {
00644     _depura("SubForm3::on_mui_list_itemDoubleClicked", 0);
00645     emit itemDoubleClicked(item);
00646     _depura("END SubForm3::on_mui_list_itemDoubleClicked", 0);
00647 }
00648 
00650 
00653 void SubForm3::on_mui_list_itemClicked(QTableWidgetItem *item) {
00654     _depura("SubForm3::on_mui_list_itemClicked", 0);
00655     emit itemClicked(item);
00656     _depura("END SubForm3::on_mui_list_itemClicked", 0);
00657 }
00658 
00659 
00661 
00665 void SubForm3::on_mui_list_cellDoubleClicked(int row, int col) {
00666     _depura("SubForm3::on_mui_list_cellDoubleClicked", 0);
00667     emit cellDoubleClicked(row, col);
00668     _depura("END SubForm3::on_mui_list_cellDoubleClicked", 0);
00669 }
00670 
00671 
00673 
00677 bool SubForm3::existsHeader(const QString &head) {
00678     _depura("SubForm3::existsHeader", 0);
00679     SHeader *linea;
00680     for (int i = 0; i < m_lcabecera.size(); ++i) {
00681         linea = m_lcabecera.at(i);
00682         if (linea->nomcampo() == head) {
00683             _depura("END SubForm3::existsHeader", 0);
00684             return TRUE;
00685         } // end if
00686     } // end for
00687     _depura("END SubForm3::existsHeader", 0);
00688     return FALSE;
00689 }
00690 
00691 
00695 
00698 SDBRecord *SubForm3::newSDBRecord() {
00699     _depura("SubForm3::newSDBRecord", 0);
00700     SDBRecord *rec = new SDBRecord(empresaBase());
00701     rec->setDBTableName(m_tablename);
00702     rec->setDBCampoId(m_campoid);
00703 
00704     SHeader *linea;
00705     for (int i = 0; i < m_lcabecera.size(); ++i) {
00706         linea = m_lcabecera.at(i);
00707         rec->addDBCampo(linea->nomcampo(), linea->tipo(), linea->restricciones(), linea->nompresentacion());
00708     } // end for
00709 
00710     SDBCampo *camp;
00711     for (int i = 0; i < rec->lista()->size(); ++i) {
00712         camp = (SDBCampo *) rec->lista()->at(i);
00713         SHeader *head = m_lcabecera.at(i);
00714         Qt::ItemFlags flags = 0;
00715         flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable;
00716 
00717         if (!(head->options() & SHeader::DBNoWrite))
00718             flags |= Qt::ItemIsEditable;
00719         if (head->tipo() == DBCampo::DBboolean) {
00720             flags |= Qt::ItemIsUserCheckable;
00721         } // end if
00722 
00723         camp->setFlags(flags);
00724 
00726         if (head->tipo() == DBCampo::DBint || head->tipo() == DBCampo::DBnumeric || head->tipo() == DBCampo::DBdate) {
00727             camp->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
00728         } else {
00729             camp->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
00730         } // end if
00731     } // end for
00732     _depura("END SubForm3::newSDBRecord", 0);
00733     return rec;
00734 }
00735 
00736 
00739 
00742 void SubForm3::nuevoRegistro() {
00743     _depura("SubForm3::nuevoRegistro", 0);
00744     if (!m_insercion)
00745         return;
00746 
00748     mui_list->setSortingEnabled(FALSE);
00749 
00750     SDBRecord *rec = newSDBRecord();
00751 
00752     m_lista.append(rec);
00753 
00754     mui_list->insertRow(m_lista.size() - 1);
00755     SDBCampo *camp;
00756     for (int i = 0; i < rec->lista()->size(); ++i) {
00757         camp = (SDBCampo *) rec->lista()->at(i);
00758         mui_list->setItem(m_lista.size() - 1, i, camp);
00759     } // end for
00760 
00762     mui_list->setCurrentCell(m_lista.size() - 1, 2);
00763 
00765     mui_list->setSortingEnabled(m_sorting);
00766     _depura("END SubForm3::nuevoRegistro", 0);
00767 }
00768 
00769 
00771 
00773 void SubForm3::pintaCabeceras() {
00774     _depura("SubForm3::pintaCabeceras", 0);
00775     QStringList headers;
00776     SHeader *linea;
00777     for (int i = 0; i < m_lcabecera.size(); ++i) {
00778         linea = m_lcabecera.at(i);
00779         headers << linea->nompresentacion();
00780         if (linea->options() & SHeader::DBNoView) {
00781             mui_list->hideColumn(i);
00782         } else {
00783             mui_list->showColumn(i);
00784         } // end if
00785     } // end for
00786     mui_list->setHorizontalHeaderLabels(headers);
00787     mui_list->horizontalHeader()->setResizeMode(0, QHeaderView::Interactive);
00788     _depura("END SubForm3::pintaCabeceras", 0);
00789 }
00790 
00791 
00793 
00797 void SubForm3::situarse(unsigned int row, unsigned int col) {
00798     _depura("SubForm3::situarse", 0, QString::number(row) + " " + QString::number(col));
00799     unsigned int nrow = row;
00800     unsigned int ncol = col;
00801     SHeader *linea = m_lcabecera.at(ncol);
00802     if (!linea)
00803         return;
00804     bool invalido = TRUE;
00805 
00807     while (invalido && nrow < row + 2) {
00808         ncol++;
00809         if (ncol == (unsigned int) m_lcabecera.count()) {
00810             ncol = 0;
00811             nrow++;
00812         } // end if
00813         linea = m_lcabecera.at(ncol);
00814         invalido = FALSE;
00815         if (linea->options() & SHeader::DBNoView)
00816             invalido = TRUE;
00817         if (linea->options() & SHeader::DBNoWrite)
00818             invalido = TRUE;
00819     } // end while
00820     mui_list->setCurrentCell(nrow, ncol);
00821     _depura("END SubForm3::situarse", 0, QString::number(nrow) + " " + QString::number(ncol));
00822 }
00823 
00824 
00826 
00832 void SubForm3::situarse1(unsigned int row, unsigned int col) {
00833     _depura("SubForm3::situarse1", 0, QString::number(row) + " " + QString::number(col));
00834     unsigned int nrow = row;
00835     unsigned int ncol = col;
00836     SHeader *linea = m_lcabecera.at(ncol);
00837     if (!linea) {
00838         return;
00839     } // end if
00840     bool invalido = TRUE;
00841     while (invalido) {
00842         if (ncol == (unsigned int) m_lcabecera.count()) {
00843             ncol = 0;
00844             nrow++;
00845         } // end if
00846         linea = m_lcabecera.at(ncol);
00847         invalido = FALSE;
00848         if (linea->options() & SHeader::DBNoView)
00849             invalido = TRUE;
00850         if (linea->options() & SHeader::DBNoWrite)
00851             invalido = TRUE;
00852         if (invalido)
00853             ncol++;
00854     } // end while
00855     mui_list->setCurrentCell(nrow, ncol);
00856     _depura("END SubForm3::situarse1", 0);
00857 }
00858 
00859 
00863 
00865 void SubForm3::pintar() {
00866     _depura("SubForm3::pintar", 0);
00867     m_procesacambios = FALSE;
00868     mui_list->setColumnCount(m_lcabecera.count());
00869     pintaCabeceras();
00870     if (m_primero) {
00871         cargaconfig();
00872     } // end if
00873     nuevoRegistro();
00874     m_procesacambios = TRUE;
00875     _depura("END SubForm3::pintar", 0);
00876 }
00877 
00878 
00880 
00883 int SubForm3::inicializar() {
00884     _depura("SubForm3::inicializar", 0);
00885     m_procesacambios = FALSE;
00886     mui_query->setPlainText("");
00887     SDBRecord *rec;
00888 
00889     int filpag = mui_filaspagina->text().toInt();
00890     if (filpag <= 0)
00891         filpag = 500;
00892 
00893     int pagact = mui_paginaact->text().toInt();
00894     if (pagact <= 0)
00895         pagact = 1;
00896 
00898     mui_list->clear();
00899     mui_list->setRowCount(0);
00900 
00902     while (m_lista.count()) {
00903         rec = m_lista.takeFirst();
00904         if (rec)
00905             delete rec;
00906     } // end while
00907 
00909     mui_numfilas->setText("0");
00910     int numpag = 0;
00911     mui_numpaginas->setText(QString::number(numpag));
00913     mui_list->setColumnCount(m_lcabecera.count());
00914     pintaCabeceras();
00915     if (m_primero) {
00916         cargaconfig();
00917     } // end if
00918 
00919     nuevoRegistro();
00921     mui_list->ordenar();
00923     on_mui_confcol_clicked();
00924     m_procesacambios = TRUE;
00925     _depura("END SubForm3::inicializar", 0);
00926     return 0;
00927 }
00928 
00929 
00931 
00934 void SubForm3::setColumnToRowSpan(QString campo) {
00935     _depura("SubForm3::setColumnToRowSpan", 0);
00936     m_columnaParaRowSpan = campo;
00937     _depura("END SubForm3::setColumnToRowSpan", 0);
00938 }
00939 
00940 
00942 
00945 void SubForm3::setColorFondo1(QString color) {
00946     _depura("SubForm3::setColorFondo1", 0);
00947     m_colorfondo1 = QColor(color);
00948     _depura("END SubForm3::setColorFondo1", 0);
00949 }
00950 
00951 
00953 
00956 void SubForm3::setColorFondo2(QString color) {
00957     _depura("SubForm3::setColorFondo2", 0);
00958     m_colorfondo2 = QColor(color);
00959     _depura("END SubForm3::setColorFondo1", 0);
00960 }
00961 
00962 
00964 
00970 void SubForm3::ponItemColorFondo(QTableWidget *twidget, int filainicial, int totalfilas, QColor colorfondo) {
00971     SDBRecord *reg3;
00973     if (listadoPijama() == FALSE) {
00975         for (int k = filainicial; k < filainicial + totalfilas; ++k) {
00976             reg3 = m_lista.at(k);
00977             for (int r = 0; r < reg3->lista()->size(); ++r) {
00979                 twidget->item(k, r)->setBackground(QBrush(colorfondo));
00980             } // end for
00981         } // end for
00982     } // end if
00983 }
00984 
00985 
00987 
00992 void SubForm3::cargar(cursor2 *cur) {
00993     _depura("SubForm3::cargar", 0, objectName());
00994     m_procesacambios = FALSE;
00995 
00996     SDBRecord *reg;
00997     SDBRecord *reg2;
00998     SDBCampo *camp;
00999     SDBCampo *camp2;
01000     QColor colorfondo = m_colorfondo1;
01001     bool coloraponerfondo = FALSE;
01002 
01004     mui_list->setSortingEnabled(FALSE);
01005 
01007     for (int i = 0; i < m_lista.size(); ++i) {
01008         reg = m_lista.at(i);
01009         for (int j = 0; j < reg->lista()->size(); ++j) {
01010             SHeader *head = m_lcabecera.at(j);
01011             if (head->nomcampo() == m_columnaParaRowSpan) {
01012                 mui_list->setSpan(i, j, 1, 1);
01013             } // end if
01014         } // end for
01015     } // end for
01016 
01018     mui_list->clear();
01019     mui_list->setRowCount(0);
01020 
01022     SDBRecord *rec;
01023     while (m_lista.count()) {
01024         rec = m_lista.takeFirst();
01025         if (rec)
01026             delete rec;
01027     } // end while
01028 
01030     mui_list->setColumnCount(m_lcabecera.count());
01031     pintaCabeceras();
01032     if (m_primero) {
01033         cargaconfig();
01034     } // end if
01035 
01037     if (cur == NULL) return;
01038 
01040     mui_query->setPlainText(cur->query());
01041 
01043     int filpag = mui_filaspagina->text().toInt();
01044     if (filpag <= 0) {
01045         filpag = 500;
01046     } // end if
01047 
01048     int pagact = mui_paginaact->text().toInt();
01049     if (pagact <= 0) {
01050         pagact = 1;
01051     } // end if
01052 
01054     mui_numfilas->setText(QString::number(cur->numregistros()));
01055     int numpag = cur->numregistros() / filpag + 1;
01056     mui_numpaginas->setText(QString::number(numpag));
01057 
01059     if (filpag == cur->numregistros()) {
01060         mui_pagsiguiente->setEnabled(TRUE);
01061     } else {
01062         mui_pagsiguiente->setDisabled(TRUE);
01063     } // end if
01064 
01066     if (pagact ==  1) {
01067         mui_paganterior->setDisabled(TRUE);
01068     } else {
01069         mui_paganterior->setEnabled(TRUE);
01070     } // end if
01071 
01073     int porcentajecarga = 0;
01074     while (!cur->eof() && m_lista.count() < filpag) {
01075         SDBRecord *rec = newSDBRecord();
01076         rec->DBload(cur);
01077         m_lista.append(rec);
01078         cur->siguienteregistro();
01079         porcentajecarga++;
01080     } // end while
01081 
01083     mui_list->setRowCount(m_lista.count());
01084     for (int i = 0; i < m_lista.size(); ++i) {
01085         reg = m_lista.at(i);
01086         QRegExp patronFecha("^.*00:00:00.*$"); 
01087         for (int j = 0; j < reg->lista()->size(); ++j) {
01088             camp = (SDBCampo *) reg->lista()->at(j);
01090             if (patronFecha.exactMatch(camp->valorcampo())) {
01091                 camp->set
01092                 (camp->valorcampo().left(10));
01093             } // end if
01095             mui_list->setItem(i, j, camp);
01096         } // end for
01097     } // end for
01098 
01100     QString textoCeldaAnterior;
01101     QString textoCeldaActual;
01102 
01104     m_filaInicialRowSpan = -1;
01105 
01107     for (int i = 0; i < m_lista.size(); ++i) {
01108         reg = m_lista.at(i);
01109         for (int j = 0; j < reg->lista()->size(); ++j) {
01110             SHeader *head = m_lcabecera.at(j);
01111             if (head->nomcampo() == m_columnaParaRowSpan) {
01112                 camp = (SDBCampo *) reg->lista()->at(j);
01113                 textoCeldaActual = camp->valorcampo();
01115                 if (i > 0) {
01116                     reg2 = m_lista.at(i - 1);
01117                     camp2 = (SDBCampo *) reg2->lista()->at(j);
01118                     textoCeldaAnterior = camp2->valorcampo();
01119                     if (textoCeldaActual == textoCeldaAnterior) {
01121                         if (m_filaInicialRowSpan == -1) {
01122                             m_filaInicialRowSpan = i - 1;
01123                         } // end if
01125                         if (i == (m_lista.size() - 1)) {
01126                             ponItemColorFondo(mui_list, m_filaInicialRowSpan, i - m_filaInicialRowSpan + 1, colorfondo);
01127                             mui_list->setSpan(m_filaInicialRowSpan, j, i - m_filaInicialRowSpan + 1, 1);
01128 
01129                             if (coloraponerfondo == FALSE) {
01130                                 colorfondo = m_colorfondo2;
01131                                 coloraponerfondo = TRUE;
01132                             } else {
01133                                 colorfondo = m_colorfondo1;
01134                                 coloraponerfondo = FALSE;
01135                             } // end if
01136 
01137                         } // end if
01138                     } else {
01140                         if (m_filaInicialRowSpan != -1) {
01142                             ponItemColorFondo(mui_list, m_filaInicialRowSpan, i - m_filaInicialRowSpan, colorfondo);
01143                             mui_list->setSpan(m_filaInicialRowSpan, j, i - m_filaInicialRowSpan, 1);
01144 
01145                             if (coloraponerfondo == FALSE) {
01146                                 colorfondo = m_colorfondo2;
01147                                 coloraponerfondo = TRUE;
01148                             } else {
01149                                 colorfondo = m_colorfondo1;
01150                                 coloraponerfondo = FALSE;
01151                             } // end if
01152                         } else {
01154                             ponItemColorFondo(mui_list, i - 1, 1, colorfondo);
01155                             if (coloraponerfondo == FALSE) {
01156                                 colorfondo = m_colorfondo2;
01157                                 coloraponerfondo = TRUE;
01158                             } else {
01159                                 colorfondo = m_colorfondo1;
01160                                 coloraponerfondo = FALSE;
01161                             } // end if
01162                         } // end if
01163                         m_filaInicialRowSpan = -1;
01164                     } // end if
01165                 } // end if
01166             } // end if
01167         } // end for
01168     } // end for
01169 
01171     if (!m_ordenporquery) {
01172         if (m_orden) {
01174             for (int i = 0; i < m_lcabecera.size(); ++i) {
01175                 if (m_lcabecera.at(i)->nomcampo() == "orden" + m_tablename)
01176                     mui_list->sortItems(i);
01177             } // end for
01178         } else {
01181             mui_list->ordenar();
01182         } // end if
01183     } // end if
01184 
01186     nuevoRegistro();
01187 
01189     on_mui_confcol_clicked();
01190 
01192     mui_list->setSortingEnabled(m_sorting);
01193 
01194     m_procesacambios = TRUE;
01195 
01196     _depura("END SubForm3::cargar", 0);
01197 }
01198 
01199 
01201 
01204 void SubForm3::setOrdenPorQuery(bool ordenactivado) {
01205     _depura("SubForm3::setOrdenPorQuery", 0);
01206     m_ordenporquery = ordenactivado;
01207     _depura("END SubForm3::setOrdenPorQuery", 0);
01208 }
01209 
01210 
01212 
01215 void SubForm3::cargar(QString query) {
01216     _depura("SubForm3::cargar", 0);
01218     if (query == "") return;
01219 
01220     try {
01221         m_query = query;
01222 
01224         int limit = mui_filaspagina->text().toInt();
01225         if (limit <= 0) {
01226             limit = 500;
01227         } // end if
01228 
01229         int pagact = mui_paginaact->text().toInt();
01230         if (pagact <= 0) {
01231             pagact = 1;
01232         } // end if
01233         int offset = limit * (pagact -1);
01234 
01235         cursor2 *cur = empresaBase()->cargacursor(query, "", limit, offset);
01236         cargar(cur);
01237         delete cur;
01238     } catch (...) {
01239         _depura("SubForm3::cargar", 2, "Error en la carga de datos");
01240     } // end try
01241     _depura("END SubForm3::cargar", 0);
01242 }
01243 
01244 
01246 
01249 SDBRecord *SubForm3::lineaact() {
01250     _depura("SubForm3::lineaact", 0);
01251     _depura("END SubForm3::lineaact", 0);
01252     return lineaat(mui_list->currentRow());
01253 }
01254 
01255 
01257 
01261 SDBRecord *SubForm3::lineaat(int row) {
01262     _depura("SubForm3::lineaat()", 0, QString::number(row));
01263     try {
01265         if (mui_list->rowCount() < row || row < 0) {
01266             throw -1;
01267         } // end if
01268 
01270         SDBCampo *camp = (SDBCampo*) mui_list->item(row, 0);
01271         if (!camp) {
01272             throw -1;
01273         } // end if
01274         SDBRecord *rec = (SDBRecord *) camp->pare();
01275 
01276         m_procesacambios = TRUE;
01277 
01278         _depura("END SubForm3::lineaat()", 0);
01279         return rec;
01280     } catch (...) {
01281         _depura ("SubForm3::lineaat linea inexistente", 2, QString::number(row));
01282         m_procesacambios = TRUE;
01283         return NULL;
01284     }
01285 }
01286 
01287 
01289 
01293 bool SubForm3::campoCompleto(int row) {
01294     _depura("SubForm3::campoCompleto", 0);
01295     SDBCampo *camp;
01296     SHeader *header;
01298     for (int i = 0; i < mui_list->columnCount(); i++) {
01299         camp = (SDBCampo *) mui_list->item(row, i);
01300 
01302         if (!camp) return FALSE;
01303 
01304         header = m_lcabecera.at(i);
01305         if (camp->restrictcampo() & DBCampo::DBNotNull
01306                 && camp->text() == ""
01307                 && !(header->options() & SHeader::DBNoView)
01308                 && camp->tipo() != DBCampo::DBboolean) {
01309             _depura("SubForm3::campoCompleto", 0, "El campo no es completo.");
01310             return FALSE;
01311         } // end if
01312         if (camp->restrictcampo() & DBCampo::DBRequired
01313                 && camp->text() == "") {
01314             _depura("SubForm3::campoCompleto", 0, "El campo no es completo.");
01315             return FALSE;
01316         } // end if
01317 
01318     } // end for
01319     _depura("END SubForm3::campoCompleto", 0);
01320     return TRUE;
01321 }
01322 
01323 
01326 
01330 void SubForm3::on_mui_list_cellRePosition(int row, int col) {
01331     _depura("SubForm3::on_mui_list_cellReposition", 0, "Row: " + QString::number(row) + " col: " + QString::number(col));
01332 
01333     bool creado = FALSE;
01334 
01335     int key = mui_list->m_teclasalida;
01336 
01337     if (row == mui_list->rowCount() - 1 && campoCompleto(row)) {
01338         nuevoRegistro();
01339         creado = TRUE;
01340     } // end if
01341 
01342     switch (key) {
01343     case Qt::Key_Return:
01344     case Qt::Key_Enter:
01345     case Qt::Key_Tab:
01346         if (!m_insercion) {
01349             QTableWidgetItem *item = mui_list->currentItem();
01350             emit itemDoubleClicked(item);
01351             emit cellDoubleClicked(row, col);
01352         } else {
01353             situarse(row, col);
01354         } // end if
01355         break;
01356     case Qt::Key_Down:
01357         situarse(row, col);
01358         situarse1(row, col);
01359         if (creado) {
01360             mui_list->setCurrentCell(row + 1, col);
01361         } // end if
01362         break;
01363     } // end switch
01364 
01365     _depura("END SubForm3::on_mui_list_cellRePosition", 0);
01366 }
01367 
01368 
01370 
01374 void SubForm3::on_mui_list_cellChanged(int row, int col) {
01375     _depura("SubForm3::on_mui_list_cellChanged", 0, "Row: "+QString::number(row) + " col: "+QString::number(col));
01376     emit editFinish(row, col);
01377     _depura("END SubForm3::on_mui_list_cellChanged", 0);
01378 }
01379 
01380 
01382 
01392 int SubForm3::addSHeader(QString nom, DBCampo::dbtype typ, int res, int opt, QString nomp) {
01393     _depura("SubForm3::addSHeader (" + nom + ")", 0);
01394     SHeader *camp = new SHeader(nom, typ, res, opt, nomp);
01395     camp->set("");
01396     m_lcabecera.append(camp);
01397     mui_listcolumnas->insertRow(mui_listcolumnas->rowCount());
01400     QTableWidgetItem2 *it = new QTableWidgetItem2("");
01401     it->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
01402 
01403     if (opt & SHeader::DBNoView) {
01404         mui_list->hideColumn(mui_listcolumnas->rowCount() -1);
01405         it->setCheckState(Qt::Unchecked);
01406     } else {
01407         it->setCheckState(Qt::Checked);
01408     } // end if
01409 
01410     if (opt & SHeader::DBBlockView) {
01411         it->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
01412     } // end if
01413 
01414     mui_listcolumnas->setItem(mui_listcolumnas->rowCount() - 1, 0, it);
01415     it = new QTableWidgetItem2(nom);
01416     mui_listcolumnas->setItem(mui_listcolumnas->rowCount() - 1, 1, it);
01417     it = new QTableWidgetItem2(nomp);
01418     mui_listcolumnas->setItem(mui_listcolumnas->rowCount() - 1, 2, it);
01419     it = new QTableWidgetItem2("");
01420     mui_listcolumnas->setItem(mui_listcolumnas->rowCount() - 1, 3, it);
01421 
01422     _depura("END SubForm3::addSHeader (" + nom + ")", 0);
01423     return 0;
01424 }
01425 
01426 
01433 void SubForm3::setColumnValue(QString campo, QString valor) {
01434     _depura("SubForm3::setColumnValue", 0, campo +" -- "+valor);
01435     SDBRecord *rec;
01436 
01437     for (int i = 0; i < mui_list->rowCount(); ++i) {
01438         rec = lineaat(i);
01439         if (rec) {
01440             rec->setDBvalue(campo, valor);
01441         } // end if
01442     } // end for
01443     _depura("END SubForm3::setColumnValue", 0);
01444 }
01445 
01446 
01448 
01452 Fixed SubForm3::sumarCampo(QString campo) {
01453     _depura("SubForm3::sumarCampo", 0);
01454     Fixed total;
01455     SDBRecord *rec;
01456     for (int i = 0; i < mui_list->rowCount(); ++i) {
01457         rec =  lineaat(i);
01458         if (rec) {
01459             Fixed subtotal = Fixed(rec->DBvalue(campo));
01460             total = total + subtotal;
01461         } // end if
01462     } // end for
01463     _depura("END SubForm3::sumarCampo", 0);
01464     return total;
01465 }
01466 
01467 
01469 
01473 QString SubForm3::DBvalue(const QString &campo, int row) {
01474     _depura("SubForm3::DBvalue", 0);
01475     try {
01476         SDBRecord *rec;
01477         if (row == -1)
01478             rec = lineaact();
01479         else
01480             rec=lineaat(row);
01481         if (rec == NULL)
01482             throw -1;
01483         _depura("END SubForm3::DBvalue", 0);
01484         return rec->DBvalue(campo);
01485     } catch (...) {
01486         mensajeInfo("Fila inexistente");
01487         throw -1;
01488     }
01489 }
01490 
01491 
01493 
01498 void SubForm3::setDBvalue(const QString &campo, int row, const QString &valor) {
01499     _depura("SubForm3::setDBvalue", 0);
01500     try {
01501         SDBRecord *rec;
01502         if (row == -1)
01503             rec = lineaact();
01504         else
01505             rec=lineaat(row);
01506         if (rec == NULL)
01507             throw -1;
01508         rec->setDBvalue(campo, valor);
01509         _depura("END SubForm3::setDBvalue", 0);
01510     } catch (...) {
01511         mensajeInfo("Fila inexistente");
01512         throw -1;
01513     }
01514 }
01515 
01516 
01518 
01521 int SubForm3::guardar() {
01522     _depura("SubForm3::guardar", 0);
01523     try {
01524         SDBRecord *rec;
01526         while (!m_listaborrar.isEmpty()) {
01527             rec = m_listaborrar.takeFirst();
01528             if (rec) {
01529                 rec->borrar();
01530             } // end if
01531         } // end while
01532 
01535         if (campoCompleto(mui_list->rowCount() - 1)) {
01536             nuevoRegistro();
01537         } // end if
01538 
01540         if (mui_list->rowCount() == 0 || ((mui_list->rowCount() == 1) && m_insercion)) {
01541             return 0;
01542         } // end if
01543 
01545         for (int j = 0; j < mui_list->rowCount() - 1; ++j) {
01546             rec = lineaat(j);
01547             if (rec) {
01549                 if (m_orden) {
01550                     rec->setDBvalue("orden" + m_tablename, QString::number(j));
01551                 } // end if
01552                 rec->refresh();
01553                 rec->guardar();
01554             } // end if
01555         } // end for
01556 
01558         if (!m_insercion) {
01559             rec = lineaat(mui_list->rowCount() - 1);
01560             if (m_orden)
01561                 rec->setDBvalue("orden" + m_tablename, QString::number(mui_list->rowCount() - 1));
01562             rec->refresh();
01563             rec->guardar();
01564         } // end if
01565 
01567         while (!m_listaborrar.isEmpty()) {
01568             rec = m_listaborrar.takeFirst();
01569             if (rec) {
01570                 delete rec;
01571             } // end if
01572         } // end while
01573 
01574         _depura("END SubForm3::guardar", 0);
01575         return 0;
01576     } catch (int e) {
01577         if (e == 100) {
01578             throw -1;
01579         } // end if
01580     } catch (...) {
01581         mensajeError("Error inesperado en el guardado. [SubForm3::guardar]");
01582         throw -1;
01583     } // end try
01584     return -1;
01585 }
01586 
01587 
01589 
01592 int SubForm3::borrar() {
01593     _depura("SubForm3::borrar", 0);
01594     SDBRecord *rec;
01595     int i = 0;
01596     int error = 0;
01597     try {
01598         for (rec = m_lista.at(i++); i < m_lista.count(); rec = m_lista.at(i++)) {
01599             error = rec->borrar();
01600             if (error)
01601                 return -1;
01602         } // end for
01603         if (!m_insercion) {
01604             rec = m_lista.at(m_lista.count() - 1);
01605             error = rec->borrar();
01606         } // end if
01607         _depura("END SubForm3::borrar", 0);
01608         return error;
01609     } catch (...) {
01610         mensajeError("Error al borrar. [SubForm3::borrar]");
01611         return -1;
01612     } // end try
01613 }
01614 
01615 
01617 
01621 int SubForm3::borrar(int row) {
01622     _depura("SubForm3::borrar", 0);
01623     try {
01624         SDBRecord *rec, *rac;
01625         SDBCampo *camp;
01626 
01627         rac = new SDBRecord(empresaBase());
01628 
01630         rec = lineaat(row);
01631         if (!rec)
01632             return -1;
01633 
01635         m_listaborrar.append(rac);
01636         m_lista.takeAt(m_lista.indexOf(rec));
01637 
01638         rac->setDBTableName(rec->tableName());
01639         rac->setDBCampoId(rec->campoId());
01640         rac->setNuevo(FALSE);
01641 
01643         for (int i = 0; i < mui_list->columnCount(); i++) {
01644             camp = (SDBCampo *) mui_list->item(row, i);
01645             SDBCampo *it = new SDBCampo(rac, empresaBase(), camp->nomcampo(), camp->tipo(), camp->restrictcampo(), camp->nompresentacion());
01646             rac->lista()->append(it);
01647             it->set(camp->valorcampo());
01648         } // end for
01649 
01652         cerrarEditor();
01653 
01654         mui_list->removeRow(row);
01655         delete rec;
01656 
01658         if (m_insercion == TRUE && rowCount() == 0) {
01659             nuevoRegistro();
01660         } // end if
01661 
01663         _depura("END SubForm3::borrar", 0);
01664         return 0;
01665 
01666     } catch (...) {
01667         mensajeInfo( "Error al intentar borrar");
01668         _depura("SubForm3::borrar error al borrar", 3);
01669         throw -1;
01670     } // end try
01671 }
01672 
01673 
01675 
01678 int SubForm3::cerrarEditor() {
01679     _depura("END SubForm3::cerrarEditor", 0);
01680     return 0;
01681 }
01682 
01683 
01685 
01687 void SubForm3::guardaconfig() {
01688     _depura("SubForm3::guardaconfig", 0);
01689     QString aux = "";
01690     QFile file(confpr->valor(CONF_DIR_USER) + m_fileconfig + "tablecfn.cfn");
01692     if (file.open(QIODevice::WriteOnly)) {
01693         QTextStream stream(&file);
01694         stream << mui_list->colorden() << "\n";
01695         stream << mui_list->tipoorden() << "\n";
01696         stream << mui_filaspagina->text() << "\n";
01697 
01699         for (int i = 0; i < mui_list->columnCount(); i++) {
01700             mui_list->showColumn(i);
01701             stream << mui_list->columnWidth(i) << "\n";
01702         } // end for
01703 
01705         for (int i = 0; i < mui_listcolumnas->rowCount(); ++i) {
01706             if (mui_listcolumnas->item(i, 0)->checkState() == Qt::Checked)
01707                 stream << "1" << "\n";
01708             else
01709                 stream << "0" << "\n";
01710         } // end for
01711         file.close();
01712     } // end if
01713     _depura("END SubForm3::guardaconfig", 0);
01714 }
01715 
01716 
01718 
01720 void SubForm3::cargaconfig() {
01721     _depura("SubForm3::cargaconfig", 0);
01722     QFile file(confpr->valor(CONF_DIR_USER) + m_fileconfig + "tablecfn.cfn");
01723     QString line;
01724     int error = 1;
01725     if (file.open(QIODevice::ReadOnly)) {
01726         error = 0;
01727         QTextStream stream(&file);
01729         QString linea = stream.readLine();
01730         mui_list->setcolorden(linea.toInt());
01731 
01733         linea = stream.readLine();
01734         mui_list->settipoorden(linea.toInt());
01735 
01737         linea = stream.readLine();
01738         if (linea.toInt() > 0) {
01739             mui_filaspagina->setValue(linea.toInt());
01740         } // end if
01741 
01743         for (int i = 0; i < mui_list->columnCount(); i++) {
01744             linea = stream.readLine();
01745             if (linea.toInt() > 0) {
01746                 mui_list->setColumnWidth(i, linea.toInt());
01747             } else {
01748                 mui_list->setColumnWidth(i, 30);
01749                 error = 1;
01750             } // end if
01751         } // end for
01752 
01754         for (int i = 0; i < mui_listcolumnas->rowCount(); ++i) {
01755             linea = stream.readLine();
01756             if (linea == "1") {
01757                 mui_listcolumnas->item(i, 0)->setCheckState(Qt::Checked);
01758             } else if (linea == "0") {
01759                 mui_listcolumnas->item(i, 0)->setCheckState(Qt::Unchecked);
01760             } else {
01761                 error = 1;
01762             } // end if
01763         } // end for
01764         file.close();
01765         on_mui_confcol_clicked();
01766     } // end if
01767 
01769     if (error)
01770         mui_list->resizeColumnsToContents();
01771 
01772     m_primero = FALSE;
01773     _depura("END SubForm3::cargaconfig", 0);
01774 }
01775 
01776 
01778 
01780 void SubForm3::on_mui_confcol_clicked() {
01781     _depura("SubForm3::on_mui_confcol_clicked", 0);
01782     for (int i = 0; i < mui_listcolumnas->rowCount(); ++i) {
01783         if (mui_listcolumnas->item(i, 0)->checkState() == Qt::Checked)
01784             mui_list->showColumn(i);
01785         else
01786             mui_list->hideColumn(i);
01787     } // end for
01788     _depura("END SubForm3::on_mui_confcol_clicked", 0);
01789 }
01790 
01791 
01793 
01795 void SubForm3::on_mui_list_pressedSlash(int, int) {
01796     _depura ("SubForm3::on_mui_list_pressedSlash", 1, "pulsadoSlash aun no implementado");
01797 }
01798 
01799 
01801 
01803 void SubForm3::on_mui_list_pressedAsterisk(int, int) {
01804     _depura ("SubForm3::on_mui_list_pressedAsterisk", 1, "pressedAsterisk aun no implementado");
01805 }
01806 
01807 
01809 
01811 void SubForm3::on_mui_list_pressedPlus(int, int) {
01812     _depura ("SubForm3::on_mui_list_pressedPlus", 1, "pulsadoPlus aun no implementado");
01813 }
01814 
01815 
01817 
01819 void SubForm3::on_mui_list_pressedMinus(int, int) {
01820     _depura ("SubForm3::on_mui_list_pressedMinus", 1, "pressedMinus aun no implementado");
01821 }
01822 
01823 
01825 
01828 QString SubForm3::imprimir() {
01829     _depura("SubForm3::imprimir", 0);
01830     QString fitxersortidarml = "<tr>\n";
01831     for (int h = 0; h < mui_listcolumnas->rowCount(); ++h) {
01832         if (mui_listcolumnas->item(h, 0)->checkState() == Qt::Checked) {
01833             fitxersortidarml += "    <td>" + XMLProtect(mui_listcolumnas->item(h, 2)->text()) + "</td>\n";
01834         } // end if
01835     } // end for
01836     fitxersortidarml += "</tr>\n";
01837     for (int i = 0; i < mui_list->rowCount(); ++i) {
01838         fitxersortidarml += "<tr>\n";
01839         for (int j = 0; j < mui_listcolumnas->rowCount(); ++j) {
01840             if (mui_listcolumnas->item(j, 0)->checkState() == Qt::Checked) {
01841                 QString restante;
01842                 fitxersortidarml += "    <td>" + XMLProtect(mui_list->item(i, j)->text()) + "</td>\n";
01843             } // end if
01844         } // end for
01845         fitxersortidarml += "</tr>\n";
01846     } // end for
01847     _depura("END SubForm3::imprimir", 0);
01848     return fitxersortidarml;
01849 }
01850 
01851 
01853 
01856 void SubForm3::on_mui_confquery_clicked() {
01857     _depura("SubForm3::on_mui_confquery_clicked ", 0);
01858     if (empresaBase() == NULL) {
01859         mensajeInfo("no se ha inicializado bien la clase");
01860         return;
01861     } // end if
01862     mui_paginaact->setValue(1);
01863     cargar(mui_query->toPlainText());
01864 //  cargar(m_query);
01865     _depura("END SubForm3::on_mui_confquery_clicked ", 0);
01866 }
01867 
01868 
01870 
01873 void SubForm3::confquery() {
01874     _depura("SubForm3::confquery", 0);
01875     if (empresaBase() == NULL) {
01876         mensajeInfo("no se ha inicializado bien la clase");
01877         return;
01878     } // end if
01879 
01880     cargar(m_query);
01881 
01882     _depura("END SubForm3::confquery ", 0);
01883 }
01884 
01885 
01888 
01893 void SubForm3::on_mui_list_ctrlSubir(int row, int col) {
01894     _depura("SubForm3::on_mui_list_ctrlSubir", 0," (" + QString::number(row) + "," + QString::number(col) + ")");
01895     if ( ! m_orden)
01896         return;
01897     if (row >= mui_list->rowCount() -1 || row == 0)
01898         return;
01899 
01900 
01902     mui_list->setSortingEnabled(FALSE);
01903     mui_list->setCurrentCell(0, 0);
01904 
01905     m_procesacambios = FALSE;
01906 
01907     for (int i = 0; i < mui_list->columnCount(); ++i) {
01908         QTableWidgetItem *it = mui_list->takeItem(row, i);
01909         QTableWidgetItem *ot = mui_list->takeItem(row - 1, i);
01910         mui_list->setItem(row, i, ot);
01911         mui_list->setItem(row - 1, i, it);
01912     } // end for
01913     mui_list->setCurrentCell(row - 1, col);
01915     mui_list->setSortingEnabled(m_sorting);
01916 
01917     m_procesacambios = TRUE;
01918     _depura("END SubForm3::on_mui_list_ctrlSubir", 0);
01919 }
01920 
01921 
01924 
01929 void SubForm3::on_mui_list_ctrlBajar(int row, int col) {
01930     _depura("SubForm3::on_mui_list_ctrlBajar", 0);
01931     if (! m_orden)
01932         return;
01933     if (row >= mui_list->rowCount() -2)
01934         return;
01936     mui_list->setSortingEnabled(FALSE);
01937     m_procesacambios = FALSE;
01938 
01939     if (row != 0)
01940         mui_list->setCurrentCell(0, 0);
01941     else
01942         mui_list->setCurrentCell(mui_list->rowCount() - 1, 0);
01943 
01944     for (int i = 0; i < mui_list->columnCount(); ++i) {
01945         QTableWidgetItem *it = mui_list->takeItem(row, i);
01946         mui_list->setItem(row, i, mui_list->takeItem(row + 1, i));
01947         mui_list->setItem(row + 1, i, it);
01948     } // end for
01949     mui_list->setCurrentCell(row + 1, col);
01951     mui_list->setSortingEnabled(m_sorting);
01952     m_procesacambios = TRUE;
01953 
01954     _depura("END SubForm3::on_mui_list_ctrlBajar", 0);
01955 }
01956 
01957 
01959 
01961 void SubForm3::on_mui_pagsiguiente_clicked() {
01962     _depura("SubForm3::on_mui_pagsiguiente_clicked", 0);
01963     int pag = mui_paginaact->text().toInt();
01964     pag++;
01965     mui_paginaact->setValue(pag);
01966     confquery();
01967     _depura("END SubForm3::on_mui_pagsiguiente_clicked", 0);
01968 }
01969 
01971 
01973 void SubForm3::on_mui_paganterior_clicked() {
01974     _depura("SubForm3::on_mui_paganterior_clicked", 0);
01975     int pag = mui_paginaact->text().toInt();
01976     if (pag > 1)
01977         pag--;
01978     mui_paginaact->setValue(pag);
01979     confquery();
01980     _depura("END SubForm3::on_mui_paganterior_clicked", 0);
01981 }
01982 
01983 
01985 
01988 void SubForm3::imprimirPDF(const QString &titular) {
01989     _depura("SubForm3::imprimir", 0);
01990 
01992     QString archivo = confpr->valor(CONF_DIR_OPENREPORTS) + "listado.rml";
01993     QString archivod = confpr->valor(CONF_DIR_USER) + "listado.rml";
01994     QString archivologo = confpr->valor(CONF_DIR_OPENREPORTS) + "logo.jpg";
01996 #ifdef WINDOWS
01997 
01998     archivo = "copy " + archivo + " " + archivod;
01999 #else
02000 
02001     archivo = "cp " + archivo + " " + archivod;
02002 #endif
02003 
02004     system(archivo.toAscii());
02006 #ifdef WINDOWS
02007 
02008     archivologo = "copy " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
02009 #else
02010 
02011     archivologo = "cp " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
02012 #endif
02013 
02014     system(archivologo.toAscii());
02015 
02016     QFile file;
02017     file.setFileName(archivod);
02018     file.open(QIODevice::ReadOnly);
02019 
02020     QTextStream stream(&file);
02021     QString buff = stream.readAll();
02022     file.close();
02023     QString fitxersortidatxt;
02024 
02025     fitxersortidatxt = "<blockTable style=\"tabla\" repeatRows=\"1\">";
02026     fitxersortidatxt += imprimir();
02027     fitxersortidatxt += "</blockTable>";
02028 
02030     buff.replace("[story]", fitxersortidatxt);
02033     buff.replace("[titulo]", titular);
02034 
02035     if (file.open(QIODevice::WriteOnly)) {
02036 
02037         QTextStream stream(&file);
02038         stream << buff;
02039 
02040         file.close();
02041     } // end if
02042 
02043     invocaPDF("listado");
02044     _depura("END SubForm3::imprimir", 0);
02045 }
02046 
02048 
02051 void SubForm3::contextMenuEvent(QContextMenuEvent *) {
02052     _depura("SubForm3::contextMenuEvent", 0);
02053     QAction *del = NULL;
02054     int row = currentRow();
02055     if (row < 0)
02056         return;
02057     int col = currentColumn();
02058     if (row < 0)
02059         return;
02060 
02061     QMenu *popup = new QMenu(this);
02062 
02064     emit pintaMenu(popup);
02065 
02067     creaMenu(popup);
02068 
02069     if (m_delete) {
02070         del = popup->addAction(tr("Borrar registro"));
02071         popup->addSeparator();
02072     } // end if
02073     QAction *ajustc = popup->addAction(tr("Ajustar columa"));
02074     QAction *ajustac = popup->addAction(tr("Ajustar altura"));
02075 
02076     QAction *ajust = popup->addAction(tr("Ajustar columnas"));
02077     QAction *ajusta = popup->addAction(tr("Ajustar alturas"));
02078 
02079     popup->addSeparator();
02080     QAction *verconfig = popup->addAction(tr("Ver/Ocultar configurador de subformulario"));
02081 
02082     QAction *opcion = popup->exec(QCursor::pos());
02083 
02085     if (!opcion) return;
02086     if (opcion == del)
02087         borrar(row);
02088     if (opcion == ajust)
02089         resizeColumnsToContents();
02090     if (opcion == ajusta)
02091         resizeRowsToContents();
02092     if (opcion == ajustc)
02093         resizeColumnToContents(col);
02094     if (opcion == ajustac)
02095         resizeRowToContents(row);
02096     if (opcion == verconfig)
02097         toogleConfig();
02098 
02099     emit trataMenu(opcion);
02100 
02102     procesaMenu(opcion);
02103 
02104     delete popup;
02105     _depura("END SubForm3::contextMenuEvent", 0);
02106 }
02107 
02109 
02111 void SubForm3::toogleConfig() {
02112     _depura("SubForm3::toogleConfig", 0);
02113     mui_configurador->setVisible(mui_configurador->isHidden());
02114     emit toogledConfig(mui_configurador->isVisible());
02115     _depura("END SubForm3::toogleConfig", 0);
02116 }
02117 
02118 
02120 
02122 void SubForm3::on_mui_botonCerrar_clicked() {
02123     _depura("SubForm3::on_mui_botonCerrar_clicked", 0);
02124     toogleConfig();
02125     _depura("END SubForm3::on_mui_botonCerrar_clicked", 0);
02126 }
02127 
02128 
02130 
02132 void SubForm3::on_mui_list_itemChanged(QTableWidgetItem *) {
02133     _depura("SubForm3::on_mui_list_itemChanged", 0);
02134     _depura("END SubForm3::on_mui_list_itemChanged", 0);
02135 }
02136 
02137 
02139 
02142 void SubForm3::setinsercion(bool b) {
02143     _depura("SubForm3::setinsercion", 0);
02144     m_insercion = b;
02145     _depura("END SubForm3::setinsercion", 0);
02146 }
02147 
02148 
02150 
02153 void SubForm3::setProcesarCambios(bool proc) {
02154     _depura("SubForm3::setProcesarCambios", 0);
02155     m_procesacambios = proc;
02156     _depura("END SubForm3::setProcesarCambios", 0);
02157 }
02158 
02159 
02161 
02164 bool SubForm3::procesaCambios() {
02165     _depura("SubForm3::procesaCambios", 0);
02166     _depura("END SubForm3::procesaCambios", 0);
02167     return m_procesacambios;
02168 }
02169 
02170 
02172 
02175 QString SubForm3::columnDBfieldName(int columna) {
02176     SHeader *linea;
02177     linea = m_lcabecera.at(columna);
02178     return linea->nomcampo();
02179 }
02180 

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