Esempio n. 1
0
class FrmCategorias( QMainWindow, Ui_FrmCategorias ):
    '''
    classdocs
    '''

    def __init__( self, parent = None ):
        '''
        Constructor
        '''
        super( FrmCategorias, self ).__init__( parent )
        self.setupUi( self )
        QSqlDatabase.database().open()

        self.model = CategoriesModel()

        self.catproxymodel = TreeFilterProxyModel()
        self.catproxymodel.setSourceModel( self.model )
        self.catproxymodel.setFilterKeyColumn( 0 )
        self.catproxymodel.setFilterCaseSensitivity( Qt.CaseInsensitive )

        self.view.setModel( self.catproxymodel )
        self.view.setColumnWidth( 0, 200 )
        self.view.setColumnHidden( 1, True )

    @pyqtSlot()
    def on_actionAddSub_triggered( self ):
        index = self.view.selectionModel().currentIndex()
        model = self.view.model()

        dlg = dlgCategoriesMod( self )
        if dlg.exec_() == QDialog.Accepted:
            if not model.insertRow( 0, index ):
                return QMessageBox.critical( self, qApp.organizationName(),
                                             "No se pudo insertar la categoria" )

            for column in range( model.columnCount( index ) ):
                child = model.index( 0, column, index )
                model.setData( child, [dlg.txtName.text(), 0], Qt.EditRole )

    @pyqtSlot()
    def on_actionAdd_triggered( self ):
        index = self.view.selectionModel().currentIndex()
        model = self.view.model()

        dlg = dlgCategoriesMod( self )
        if dlg.exec_() == QDialog.Accepted:
            if not model.insertRow( index.row() + 1, index.parent() ):
                return QMessageBox.critical( self, qApp.organizationName(),
                                             "No se pudo insertar la categoria" )


            for column in range( model.columnCount( index.parent() ) ):
                child = model.index( index.row() + 1, column, index.parent() )
                model.setData( child, [ dlg.txtName.text(), 0], Qt.EditRole )

    @pyqtSlot()
    def on_actionEditar_triggered( self ):
        index = self.view.selectionModel().currentIndex()
        model = self.view.model()

        dlg = dlgCategoriesMod( self )
        dlg.txtName.setText( index.data().toString() )
        if dlg.exec_() == QDialog.Accepted:
            if not model.setData( index, [dlg.txtName.text(), index.data()] ):
                raise Exception( "No se pudo editar la categoria" )





    @pyqtSlot()
    def on_actionDelete_triggered( self ):
        index = self.view.selectionModel().currentIndex()
        if not self.model.removeRow( index.row(), index.parent() ):
            QMessageBox.critical( self, qApp.organizationName(),
                                  "No se pudo borrar la categoria"\
                                  + "tenga en cuenta que no podra borrar"\
                                  + " categorias que el sistema ya"\
                                  + "este utilizando" )

    @pyqtSlot( "QString" )
    def on_txtSearch_textEdited( self , text ):
        self.catproxymodel.setFilterRegExp( text )
Esempio n. 2
0
class FrmAccounts( QMainWindow, Ui_frmAccounts ):
    """

    """
    def __init__( self, parent = None ):
        super( FrmAccounts, self ).__init__( parent )

        self.setupUi( self )
        self.user = user.LoggedUser

        QSqlDatabase.database().open()
#        self.accountsTree.setModel( AccountsModel( 1 ) )



        self.model = AccountsModel( 1 )

        self.filtermodel = TreeFilterProxyModel()
        self.filtermodel.setShowAllChildren( True )
        self.filtermodel.setSourceModel( self.model )
        self.filtermodel.setFilterKeyColumn( DESCRIPCION )
        self.filtermodel.setFilterCaseSensitivity( Qt.CaseInsensitive )

        self.accountsTree.setModel( self.filtermodel )

        self.accountsTree.setColumnHidden( IDCUENTA, True )
        self.accountsTree.setColumnHidden( HIJOS, True )
        self.accountsTree.setColumnHidden( PADRE, True )

        self.accountsTree.setColumnWidth( CODIGO, 240 )
        self.accountsTree.setColumnWidth( DESCRIPCION, 240 )
        self.accountsTree.expandAll()

    @pyqtSlot()
    def on_btnAdd_clicked( self ):
        proxyindex = self.accountsTree.currentIndex()
        row = proxyindex.row()
        index = self.accountsTree.model().mapToSource( 
                           self.accountsTree.model().index( 
                                   row, CODIGO, proxyindex.parent() ) )


        dlg = DlgAccountMod( self )
        if dlg.exec_() == QDialog.Accepted:
            try:
                self.accountsTree.model().sourceModel().insertRows( 
                                                 index.row(),
                                                 1,
                                                 index,
                                                 " ".join( [txt.text() for txt in dlg.txtCodes ] ),
                                                 dlg.txtDescription.text(),
                                                 1 if dlg.cbEsdebe.checkState() == Qt.CheckState else 0
                                                   )
            except UserWarning as inst:
                logging.error( inst )
                QMessageBox.critical( self, qApp.organizationName(), unicode( inst ) )
            except Exception as inst:
                logging.critical( inst )

    @pyqtSlot()
    def on_btnModify_clicked( self ):
        index = self.accountsTree.currentIndex()
        dlg = DlgAccountMod( self )
        row = index.row()
        codes = self.accountsTree.model().index( row, CODIGO, index.parent() ).data().toString()
        codes = codes.split( ' ' )
        for id, code in enumerate( codes ):
            dlg.txtCodes[id].setText( code )

        dlg.txtDescription.setText( self.accountsTree.model().index( row, DESCRIPCION, index.parent() ).data().toString() )
        dlg.cbEsdebe.setCheckState( Qt.Checked if self.accountsTree.model().index( row, ESDEBE, index.parent() ).data().toInt()[0] else Qt.Unchecked )
        if dlg.exec_() == QDialog.Accepted:
            self.accountsTree.model().setData( 
              self.accountsTree.model().index( 
                      row, DESCRIPCION, index.parent() ), dlg.txtDescription.text() )
            self.accountsTree.model().setData( 
              self.accountsTree.model().index( 
                    row, CODIGO, index.parent() ), " ".join( [txt.text() for txt in dlg.txtCodes ] ) )

            self.accountsTree.model().setData( 
                    self.accountsTree.model().index( 
                        row, ESDEBE, index.parent() ), 1 if dlg.cbEsdebe.checkState() == Qt.Checked else 0 )


    @pyqtSlot( "QString" )
    def on_txtSearch_textEdited( self , text ):
        self.filtermodel.setFilterRegExp( text )