listivaview.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 #define COL_IDIVA           0
00022 #define COL_IDREGISTROIVA   1
00023 #define COL_IDTIPOIVA       2
00024 #define COL_IDCUENTA        3
00025 #define COL_NOMBRETIPOIVA   4
00026 #define COL_CODIGO          5
00027 #define COL_BASEIVA         6
00028 #define COL_IVAIVA          7
00029 
00030 #include <QMessageBox>
00031 #include <QKeyEvent>
00032 #include <QEvent>
00033 #include <QTextStream>
00034 
00035 #include "empresa.h"
00036 #include "listivaview.h"
00037 #include "funcaux.h"
00038 
00039 
00041 
00043 void ListIvaView::guardaconfig() {
00044     _depura("ListIvaView::guardaconfig", 0);
00045     QString aux = "";
00046     QFile file(confpr->valor(CONF_DIR_USER) + "confListIvaView.cfn");
00047     if (file.open(QIODevice::WriteOnly)) {
00048         QTextStream stream(&file);
00049         for (int i = 0; i < columnCount(); i++) {
00050             showColumn(i);
00051             stream << columnWidth(i) << "\n";
00052         } // end for
00053         file.close();
00054     } // end if
00055     _depura("END ListIvaView::guardaconfig", 0);
00056 }
00057 
00058 
00060 
00062 void ListIvaView::cargaconfig() {
00063     _depura("ListIvaView::cargaconfig", 0);
00064     QFile file( confpr->valor(CONF_DIR_USER) + "confListIvaView.cfn" );
00065     QString line;
00066     if (file.open(QIODevice::ReadOnly)) {
00067         QTextStream stream(&file);
00068         for (int i = 0; i < columnCount(); i++) {
00069             QString linea = stream.readLine();
00070             setColumnWidth(i, linea.toInt());
00071         } // end for
00072         file.close();
00073     } // end if
00074     _depura("END ListIvaView::cargaconfig", 0);
00075 }
00076 
00077 
00079 
00082 ListIvaView::ListIvaView(QWidget * parent) : QTableWidget(parent), ListIva() {
00083     _depura("ListIvaView::ListIvaView", 0);
00085     setColumnCount(8);
00086     setRowCount(0);
00087     QStringList etiquetas;
00088     etiquetas << tr("COL_IDIVA") << tr("COL_IDTIPOIVA") << tr("COL_IDCUENTA") << tr("COL_CODIGO") << tr("COL_NOMBRETIPOIVA") << tr("COL_IDREGISTROIVA") << tr("COL_BASEIVA") << tr("COL_IVAIVA");
00089     setHorizontalHeaderLabels(etiquetas);
00090 
00091     setColumnWidth(COL_IDIVA, 100);
00092     setColumnWidth(COL_IDTIPOIVA, 100);
00093     setColumnWidth(COL_IDCUENTA, 100);
00094     setColumnWidth(COL_CODIGO, 100);
00095     setColumnWidth(COL_NOMBRETIPOIVA, 100);
00096     setColumnWidth(COL_IDREGISTROIVA, 100);
00097     setColumnWidth(COL_BASEIVA, 100);
00098     setColumnWidth(COL_IVAIVA, 74);
00099 
00100     hideColumn(COL_IDIVA);
00101     hideColumn(COL_IDTIPOIVA);
00102     hideColumn(COL_IDCUENTA);
00103     hideColumn(COL_IDREGISTROIVA);
00104 
00105     setSelectionMode(QAbstractItemView::SingleSelection);
00108     QPalette palette;
00109     palette.setColor(this->backgroundRole(), confpr->valor(CONF_BG_LINPRESUPUESTOS));
00110     this->setPalette(palette);
00111 
00112     connect(this, SIGNAL(valueChanged(int, int)), this, SLOT(valueBudgetLineChanged(int, int)));
00113     connect(this, SIGNAL(contextMenuRequested(int, int, const QPoint &)), this, SLOT(contextMenu(int, int, const QPoint &)));
00114     installEventFilter(this);
00115     cargaconfig();
00116     _depura("END ListIvaView::ListIvaView", 0);
00117 }
00118 
00119 
00121 
00123 ListIvaView::~ListIvaView() {
00124     _depura("ListIvaView::~ListIvaView()", 0);
00125     guardaconfig();
00126     _depura("END ListIvaView::~ListIvaView()", 0);
00127 }
00128 
00129 
00131 
00133 void ListIvaView::pintaListIva() {
00134     _depura("ListIvaView::pintaListIva\n", 0);
00135     setRowCount(0);
00136     setRowCount(m_lista.count());
00138     uint i = 0;
00139     Iva *linea;
00140 
00141     QMutableListIterator<Iva*> m_ilista(m_lista);
00143     m_ilista.toFront();
00145     while (m_ilista.hasNext()) {
00147         linea = m_ilista.next();
00148         pintaIva(i);
00149         resizeRowToContents(i);
00150         i++;
00151     } // end while
00152 
00153     _depura("END ListIvaView::pintaListIva\n", 0);
00154 }
00155 
00156 
00158 
00162 void ListIvaView::contextMenu(int row, int, const QPoint & pos) {
00163     _depura("ListIvaView::contextMenu", 0);
00164     QMenu *popup = new QMenu();
00165     QAction *borrarlinea = popup->addAction(tr("Borrar linea"));
00166     QAction *opcion = popup->exec(pos);
00167     delete popup;
00168     if (opcion == borrarlinea) {
00169         borraIva(row);
00170     } // end if
00171     _depura("END ListIvaView::contextMenu", 0);
00172 }
00173 
00174 
00176 
00178 void ListIvaView::borraIvaAct() {
00179     _depura("ListIvaView::borraIvaAct", 0);
00180     borraIva(currentRow());
00181     _depura("END ListIvaView::borraIvaAct", 0);
00182 }
00183 
00184 
00186 
00189 void ListIvaView::pintaIva(int pos) {
00190     _depura("ListIvaView::pintaIva\n", 0);
00191     Iva *linea;
00192     linea = m_lista.at(pos);
00193 
00194     item(pos, COL_IDIVA)->setText(linea->idiva());
00195     item(pos, COL_IDTIPOIVA)->setText(linea->idtipoiva());
00196     item(pos, COL_IDCUENTA)->setText(linea->idcuenta());
00197     item(pos, COL_CODIGO)->setText(linea->codigo());
00198     item(pos, COL_NOMBRETIPOIVA)->setText(linea->nombretipoiva());
00199     item(pos, COL_IDREGISTROIVA)->setText(linea->idregistroiva());
00200     item(pos, COL_BASEIVA)->setText(linea->baseiva());
00201     item(pos, COL_IVAIVA)->setText(linea->ivaiva());
00202     resizeRowToContents(pos);
00203 
00204     _depura("END ListIvaView::pintaIva\n", 0);
00205 }
00206 
00207 
00209 
00214 bool ListIvaView::eventFilter(QObject *obj, QEvent *ev) {
00215     _depura("ListIvaView::eventFilter()\n", 1);
00216     /*
00217         QString idArticle;
00218         //    linpresupuesto *linea=lineaact();
00219         Iva *linea;//=m_lista.at(currentRow());
00220      
00221         if ( ev->type() == QEvent::KeyRelease ) {
00222             QKeyEvent *k = (QKeyEvent *)ev;
00223             int col=currentColumn();
00224             int row=currentRow();
00225             switch (k->key()) {
00226             case Qt::Key_Plus:
00227                 if (col == COL_DESCLPRESUPUESTO) {
00228                     setText(row,col,editaTexto(text(row,col)));
00229                     valueBudgetLineChanged(row,col);
00230                     return TRUE;
00231                 }// end if
00232                 break;
00233             case Qt::Key_Return:
00234             case Qt::Key_Enter:
00235                 // Esto se hace porque en la ltima linea del qtable tiene un comportamiento raro. Se reportar�como bug a trolltech.
00236                 switch (col) {
00237                 case COL_CODARTICULO:
00238                     setCurrentCell(row, COL_DESCLPRESUPUESTO);
00239                     break;
00240                 case COL_DESCLPRESUPUESTO:
00241                     setCurrentCell(row, COL_CANTLPRESUPUESTO);
00242                     break;
00243                 case COL_CANTLPRESUPUESTO:
00244                     setCurrentCell(row, COL_PVPLPRESUPUESTO);
00245                     break;
00246                 case COL_PVPLPRESUPUESTO:
00247                     setCurrentCell(row+1, COL_CODARTICULO);
00248                     break;
00249                 }// end switch
00250                 return TRUE;
00251                 break;
00252             }// end switch
00253         }// end if
00254     */
00255     return QTableWidget::eventFilter(obj, ev);
00256 }
00257 
00258 
00260 
00264 void ListIvaView::valueBudgetLineChanged(int row, int col) {
00265     _depura("valueBudgetLineChanged \n", 0);
00266     Iva *linea;
00267     linea = lineaat(row);
00268     if (linea != NULL) {
00269         switch (col) {
00270         case COL_BASEIVA: {
00271                 float baseiva = item(row, COL_BASEIVA)->text().replace(",", ".").toFloat();
00272                 linea->setbaseiva(QString::number(baseiva));
00273                 break;
00274             }
00275         case COL_IVAIVA: {
00276                 float ivaiva = item(row, COL_IVAIVA)->text().replace(",", ".").toFloat();
00277                 linea->setivaiva(QString::number(ivaiva));
00278                 break;
00279             } // end case
00280         } // end switch
00281         pintaIva(row);
00282     } // end if
00283     _depura("END valueBudgetLineChanged \n", 0);
00284 }
00285 
00286 
00288 
00291 Iva *ListIvaView::lineaact() {
00292     _depura("ListIvaView::lineaact()\n", 0);
00293     return lineaat(currentRow());
00294 }
00295 
00296 
00299 
00303 Iva *ListIvaView::lineaat(int row) {
00304     _depura("ListIvaView::lineaat\n", 0);
00305     Iva *linea;
00306     if (row >= 0) {
00307         while (m_lista.at(row) == 0) {
00308             fprintf(stderr, "Creamos la linea\n");
00309             linea = new Iva(companyact);
00310             linea->setidregistroiva(mdb_idregistroiva);
00311             m_lista.append(linea);
00312         } // end while
00313         return(m_lista.at(row));
00314     } else {
00315         _depura("Linea inexistente\n", 0);
00316         return NULL;
00317     }// end if
00318 }
00319 

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