Organize source files into src subdirectories (gui/forms, gui/widgets, models, utils); replace magic numbers with ElementType enumeration in formproduct.cpp and formbudget.cpp (TODO completed); move mainwindow and related files to src/gui/

This commit is contained in:
Javi
2026-05-28 00:42:46 +02:00
parent b3b0116699
commit 3437103c28
72 changed files with 5893 additions and 0 deletions
-143
View File
@@ -1,143 +0,0 @@
#include "dialogcreateenterprise.h"
#include "ui_dialogcreateenterprise.h"
#include "sqltable.h"
#include "mapplication.h"
#include <QtSql>
dialogCreateEnterprise::dialogCreateEnterprise(QWidget *parent) :
QDialog(parent),
ui(new Ui::dialogCreateEnterprise)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true);
}
dialogCreateEnterprise::~dialogCreateEnterprise()
{
delete ui;
}
void dialogCreateEnterprise::on_pushBack_released()
{
}
void dialogCreateEnterprise::on_pushNext_released()
{
// TODO: guardar y crear la empresa
if(ui->editName->text().isEmpty())
{
return;
}
if(ui->editCIF->text().isEmpty())
{
return;
}
createEnterprise();
close();
}
void dialogCreateEnterprise::createEnterprise()
{
QString CIF = ui->editCIF->text().toUpper();
QString path = dApp->dataFolder() + CIF + QDir::separator();
QDir dir;
dir.mkpath(path);
QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE", CIF);
database.setDatabaseName(path + CIF + ".db");
if(!database.open())
return;
// Crear la base de datos:
for(auto table : dbTables)
{
QSqlQuery qry(database);
if (!qry.exec(table))
{
// TODO: mandar un mensaje y repetir si es necesario
}
}
QString ENTERPRISES = "INSERT INTO ENTERPRISES ("
"NAME, CIF, DBNAME, PATH"
") VALUES ("
":NAME, :CIF, :DBNAME, :PATH"
");";
QString ENTERPRISESINFO = "INSERT INTO ENTERPRISESINFO ("
"NAME, CIF, ADDRESS, POSTCODE, CITY, PROVINCE, COUNTRY, PHONE, MOBILE, FAX, "
"EMAIL, WEB, CIF_COMMUNITY, IAE, CNAE, DCNAE, LOGO1, LOGO2"
") VALUES ("
":NAME, :CIF, :ADDRESS, :POSTCODE, :CITY, :PROVINCE, :COUNTRY, :PHONE, :MOBILE, :FAX, "
":EMAIL, :WEB, :CIF_COMMUNITY, :IAE, :CNAE, :DCNAE, :LOGO1, :LOGO2"
");";
QSqlQuery qry(database);
//QSqlQuery *qry = new QSqlQuery(dApp->getDBConnection());
qry.prepare(ENTERPRISESINFO);
qry.bindValue(":NAME", ui->editName->text());
qry.bindValue(":CIF", ui->editCIF->text());
qry.bindValue(":ADDRESS", ui->editAddress->toPlainText());
qry.bindValue(":POSTCODE", ui->editCP->text());
qry.bindValue(":CITY", ui->editCity->text());
qry.bindValue(":PROVINCE", ui->editProvince->text());
qry.bindValue(":COUNTRY", ui->editCountry->text());
qry.bindValue(":PHONE", ui->editPhone->text());
//qry.bindValue(":MOBILE", ui->edit->text());
qry.bindValue(":FAX", ui->editFax->text());
qry.bindValue(":EMAIL", ui->editEmail->text());
qry.bindValue(":WEB", ui->editWebside->text());
//qry.bindValue(":CIF_COMMUNITY", ui->edit->text());
//qry.bindValue(":IAE", ui->editName->text());
//qry.bindValue(":CNAE", ui->editName->text());
//qry.bindValue(":DCENAE", ui->editName->text());
//qry.bindValue(":LOGO1", ui->editName->text());
//qry.bindValue(":lOGO2", ui->editName->text());
if (!qry.exec())
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
return;
}
qry.prepare(DBInfoCommand);
qry.bindValue(":VERSION", dApp->applicationVersion().isEmpty() ? "0" : dApp->applicationVersion());
qry.bindValue(":SUBVERSION", "0");
if (!qry.exec())
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
return;
}
qry.clear();
qry.finish();
database.close();
QSqlDatabase::removeDatabase(CIF);
// 2. Poner la compañia en la lista:
dApp->EnterpriseList().open();
QSqlQuery qryList(dApp->EnterpriseList());
qryList.prepare(ENTERPRISES);
qryList.bindValue(":NAME", ui->editName->text());
qryList.bindValue(":CIF", ui->editCIF->text());
qryList.bindValue(":DBNAME", CIF);
qryList.bindValue(":PATH", path);
if (!qryList.exec())
{
qDebug() << "Error ejecutando el query: " << qryList.lastError().text() << "\n";
return;
}
dApp->Enterprise().close();
// 3. Abrir la empresa
dApp->openCompany(CIF);
}
-28
View File
@@ -1,28 +0,0 @@
#ifndef DIALOGCREATEENTERPRISE_H
#define DIALOGCREATEENTERPRISE_H
#include <QDialog>
namespace Ui
{
class dialogCreateEnterprise;
}
class dialogCreateEnterprise : public QDialog
{
Q_OBJECT
public:
explicit dialogCreateEnterprise(QWidget *parent = 0);
~dialogCreateEnterprise();
private slots:
void on_pushNext_released();
void on_pushBack_released();
private:
Ui::dialogCreateEnterprise *ui;
void createEnterprise();
};
#endif // DIALOGCREATEENTERPRISE_H
-444
View File
@@ -1,444 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>dialogCreateEnterprise</class>
<widget class="QDialog" name="dialogCreateEnterprise">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>550</width>
<height>500</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="frame_2">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="4">
<widget class="QLineEdit" name="editCIF">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="lineEdit_2">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Nombre/Razón social</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="label_3">
<property name="text">
<string>C.I.F.</string>
</property>
</widget>
</item>
<item row="2" column="2" colspan="5">
<widget class="QLineEdit" name="editName"/>
</item>
<item row="1" column="5">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Forma jurídica</string>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QComboBox" name="comboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Código</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Nombre comercial</string>
</property>
</widget>
</item>
<item row="4" column="2" colspan="5">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="1" column="0" rowspan="4">
<widget class="AvatarWidget" name="label_14">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>75</width>
<height>75</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::WinPanel</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabGeneralInfo">
<attribute name="title">
<string>Datos generales</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>CP / Población</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Pais</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Provincia</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="editCity"/>
</item>
<item row="3" column="1" colspan="2">
<widget class="QLineEdit" name="editProvince"/>
</item>
<item row="0" column="0" alignment="Qt::AlignTop">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Dirección</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QLineEdit" name="editCountry"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="editCP">
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QPlainTextEdit" name="editAddress">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>66</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>1</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(191, 191, 191);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_4" native="true">
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Webside</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="editFax"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Email</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Teléfono / Fax</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="editEmail"/>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="editWebside"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="editPhone"/>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabOthers">
<attribute name="title">
<string>Otros datos</string>
</attribute>
<widget class="QWidget" name="widget_5" native="true">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>381</width>
<height>121</height>
</rect>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Page</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushBack">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Anterior</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushNext">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Siguiente</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AvatarWidget</class>
<extends>QLabel</extends>
<header>avatarwidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
-51
View File
@@ -1,51 +0,0 @@
#include "dialogopencompany.h"
#include "ui_dialogopencompany.h"
#include "companylistitemdelegate.h"
#include "mapplication.h"
#include <QStandardItemModel>
dialogOpenCompany::dialogOpenCompany(QWidget *parent) :
QDialog(parent),
ui(new Ui::dialogOpenCompany)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true);
QListView *view = ui->listView;
model = new QStandardItemModel();
CompanyListItemDelegate *listdelegate = new CompanyListItemDelegate();
view->setItemDelegate(listdelegate); //connect the delegate to view
view->setModel(model); //connect the model to view.
}
dialogOpenCompany::~dialogOpenCompany()
{
delete ui;
}
void dialogOpenCompany::setData(QString Name, QString CIF, QString path)
{
QStandardItem *item = new QStandardItem();
QIcon icon(":/new/prefix1/about.png");
item->setData(Name, Qt::DisplayRole); // Nombre
item->setData(CIF, Qt::UserRole); // CIF
item->setData(path, Qt::UserRole + 1); // path
model->appendRow(item);
}
void dialogOpenCompany::on_buttonOpen_released()
{
on_listView_doubleClicked(ui->listView->currentIndex());
}
void dialogOpenCompany::on_listView_doubleClicked(const QModelIndex &index)
{
if(!index.isValid())
return;
dApp->openCompany(index.data(Qt::UserRole).toString());
close();
}
-32
View File
@@ -1,32 +0,0 @@
#ifndef DIALOGOPENCOMPANY_H
#define DIALOGOPENCOMPANY_H
#include <QDialog>
class QStandardItemModel;
namespace Ui
{
class dialogOpenCompany;
}
class dialogOpenCompany : public QDialog
{
Q_OBJECT
public:
explicit dialogOpenCompany(QWidget *parent = nullptr);
~dialogOpenCompany();
void setData(QString Name, QString CIF, QString path);
private slots:
void on_buttonOpen_released();
void on_listView_doubleClicked(const QModelIndex &index);
private:
Ui::dialogOpenCompany *ui;
QStandardItemModel *model;
};
#endif // DIALOGOPENCOMPANY_H
-75
View File
@@ -1,75 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>dialogOpenCompany</class>
<widget class="QDialog" name="dialogOpenCompany">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>400</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListView" name="listView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonOpen">
<property name="text">
<string>Abrir</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
-52
View File
@@ -1,52 +0,0 @@
#include "formbase.h"
#include "ui_formbase.h"
formBase::formBase(QString aID, int aEditMode, QWidget *parent) :
QWidget(parent),
mDocumentID(aID),
mNeedSave(false),
ui(new Ui::formBase)
{
if(aID.isEmpty())
{
newDocument();
}
else
{
openDocument(aID);
}
}
formBase::~formBase()
{
delete ui;
}
void formBase::newDocument()
{
mEditMode = false;
}
void formBase::openDocument(QString id)
{
mEditMode = true;
}
void formBase::save()
{
}
bool formBase::needsave()
{
return mNeedSave;
}
void formBase::setEditMode(bool aMode)
{
mEditMode = aMode;
}
-35
View File
@@ -1,35 +0,0 @@
#ifndef FORMBASE_H
#define FORMBASE_H
#include <QWidget>
namespace Ui {
class formBase;
}
class formBase : public QWidget
{
Q_OBJECT
public:
explicit formBase(QString aID = "", int aEditMode = 0, QWidget *parent = nullptr);
~formBase();
virtual void newDocument() = 0;
virtual void openDocument(QString id) = 0;
virtual void save() = 0;
virtual bool needsave() = 0;
virtual void setEditMode(bool aMode) = 0;
virtual void closeDocument(){};
private:
Ui::formBase *ui;
protected:
QString mDocumentID;
bool mEditMode;
bool mNeedSave;
};
#endif // FORMBASE_H
-19
View File
@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>formBase</class>
<widget class="QWidget" name="formBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>705</width>
<height>492</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<resources/>
<connections/>
</ui>
-27
View File
@@ -1,27 +0,0 @@
#include "formbaselist.h"
#include "ui_formbaselist.h"
#include <QResizeEvent>
FormBaseList::FormBaseList(QWidget *parent)
: QWidget(parent)
, ui(new Ui::FormBaseList)
{
ui->setupUi(this);
}
FormBaseList::~FormBaseList()
{
delete ui;
}
void FormBaseList::resizeEvent(QResizeEvent *event)
{
QStringList texts = { tr("Nuevo"), tr("Editar"), tr("Clonar"), tr("Borrar"), tr("Actualizar") };
QList<QPushButton*> buttons = { ui->buttonNew, ui->buttonEdit, ui->buttonClone, ui->buttonDelete, ui->buttonUpdate };
for (int i = 0; i < buttons.size(); ++i) {
int sz = event->size().width();
buttons[i]->setText(sz > 400 ? texts[i] : "");
}
}
-25
View File
@@ -1,25 +0,0 @@
#ifndef FORMBASELIST_H
#define FORMBASELIST_H
#include <QWidget>
namespace Ui {
class FormBaseList;
}
class FormBaseList : public QWidget
{
Q_OBJECT
public:
explicit FormBaseList(QWidget *parent = nullptr);
~FormBaseList();
protected:
void resizeEvent(QResizeEvent *event) override;
private:
Ui::FormBaseList *ui;
};
#endif // FORMBASELIST_H
-115
View File
@@ -1,115 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FormBaseList</class>
<widget class="QWidget" name="FormBaseList">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>412</width>
<height>297</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTableView" name="tableView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_2">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="buttonNew">
<property name="text">
<string>Nuevo</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/add-file.svg</normaloff>:/resources/icons/add-file.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonEdit">
<property name="text">
<string>Editar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/pencil.svg</normaloff>:/resources/icons/pencil.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonClone">
<property name="text">
<string>Duplicar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/copy.svg</normaloff>:/resources/icons/copy.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonDelete">
<property name="text">
<string>Borrar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/delete.svg</normaloff>:/resources/icons/delete.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonUpdate">
<property name="text">
<string>Actualizar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/recycle.svg</normaloff>:/resources/icons/recycle.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../editabletreemodel.qrc"/>
</resources>
<connections/>
</ui>
-617
View File
@@ -1,617 +0,0 @@
#include "formbudget.h"
#include "ui_formbudget.h"
#include "qmtreeview.h"
#include "treemodel.h"
#include "treeitem.h"
#include "mapplication.h"
#include "../src/elementtype.h"
#include "widgetcomboboxpopuptable.h"
#include "itemnumberdelegate.h"
#include "itemtextdelegate.h"
#include "itemtextpopupdelegate.h"
#include "itemcomboboxdelegate.h"
#include <QStringList>
#include <QFile>
#include <QAction>
#include <QtSql>
formBudget::formBudget(QString aID, int amEditMode, QWidget *parent) :
formBase(aID, amEditMode, parent),
ui(new Ui::formBudget)
{
ui->setupUi(this);
QStringList headers;
headers << tr("Índice") << tr("Código") << tr("Título") << tr("Descriction")
<< tr("Cantidad") << tr("Cantidad total") << tr("Unidad")
<< tr("N. Precio Unitario")<< tr("N. Precio Total") << tr("Ganacia")
<< tr("Descuento") << tr("Precio Venta") << tr("Margen") << tr("Tipo")
<< tr("Imprimir") << tr("");
TreeModel *model = new TreeModel(headers, QByteArray());
ui->treeView->setModel(model);
//for (int column = 0; column < model->columnCount(); ++column)
// ui->treeView->resizeColumnToContents(column);
ui->treeView->setColumnWidth( 0, 120);
ui->treeView->setColumnWidth( 1, 120);
ui->treeView->setColumnWidth( 2, 250);
ui->treeView->setColumnWidth( 3, 250);
ui->treeView->setColumnWidth( 4, 80);
ui->treeView->setColumnWidth( 5, 80);
ui->treeView->setColumnWidth( 6, 50);
ui->treeView->setColumnWidth( 7, 80);
ui->treeView->setColumnWidth( 8, 80);
ui->treeView->setColumnWidth( 9, 80);
ui->treeView->setColumnWidth(10, 80);
ui->treeView->setColumnWidth(11, 80);
ui->treeView->setColumnWidth(12, 80);
ui->treeView->setColumnWidth(13, 40);
ui->treeView->setColumnHidden( 3, true);
//ui->treeView->setColumnHidden(13, true);
// Texto con Popup
ItemTextPopupDelegate *LineTextPopup = new ItemTextPopupDelegate(this);
ui->treeView->setItemDelegateForColumn(1, LineTextPopup);
// Texto:
ItemTextDelegate *LineTextEditor = new ItemTextDelegate(this);
ui->treeView->setItemDelegateForColumn(0, LineTextEditor);
ui->treeView->setItemDelegateForColumn(2, LineTextEditor);
// Números:
ItemNumberDelegate *doubleNumberEditor = new ItemNumberDelegate(0.0, 999999.99, 0.05, 2, this);
ui->treeView->setItemDelegateForColumn(4, doubleNumberEditor);
ui->treeView->setItemDelegateForColumn(7, doubleNumberEditor);
ui->treeView->setItemDelegateForColumn(9, doubleNumberEditor);
ui->treeView->setItemDelegateForColumn(10, doubleNumberEditor);
// Combobox:
ItemComboboxDelegate *ComboboxEditor = new ItemComboboxDelegate(this);
ui->treeView->setItemDelegateForColumn(6, ComboboxEditor);
connect(model, &TreeModel::dataChanged, this, &formBudget::on_ModelSetData);
// Prueba:
connect(dApp, &QApplication::focusChanged, this, [=](QWidget* old, QWidget* now)
{
//qDebug() << "old: " << old << "\n" << "new: " << now;
if (!this->isAncestorOf(old))
qDebug() << "Se deshabilita la toolbox";
//Q_UNUSED(old);
//if (now != this && !this->isAncestorOf(now))
if (now == this && !this->isAncestorOf(now))
{
//hide();
qDebug() << "Se habilita la toolbox";
}
});
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
if (qry.exec(QString("SELECT ID FROM SALEPROPOSAL ORDER BY ID DESC LIMIT 1;")))
{
int val = 0;
while(qry.next())
val = qry.value(qry.record().indexOf("ID")).toInt();
ui->editCode->setText(QString("(PRO%1)").arg(val + 1));
}
dApp->Enterprise().close();
}
formBudget::~formBudget()
{
delete ui;
}
void formBudget::setupTreeView()
{
QStringList headers = {
tr("Índice"), tr("Código"), tr("Título"), tr("Descripción"),
tr("Cantidad"), tr("Cantidad total"), tr("Unidad"),
tr("N. Precio Unitario"), tr("N. Precio Total"), tr("Ganacia"),
tr("Descuento"), tr("Precio Venta"), tr("Margen"), tr("Tipo"),
tr("Imprimir"), tr("")
};
m_treeModel = new TreeModel(headers, QByteArray(), this);
ui->treeView->setModel(m_treeModel);
// Configurar anchos de columna
QVector<int> widths = {120, 120, 250, 250, 80, 80, 50, 80, 80, 80, 80, 80, 80, 40};
for (int i = 0; i < widths.size(); ++i) {
ui->treeView->setColumnWidth(i, widths[i]);
}
ui->treeView->setColumnHidden(3, true);
// Configurar delegados
setupDelegates();
}
void formBudget::setupDelegates()
{
// Texto con Popup
auto* lineTextPopup = new ItemTextPopupDelegate(this);
ui->treeView->setItemDelegateForColumn(1, lineTextPopup);
// Texto simple
auto* lineTextEditor = new ItemTextDelegate(this);
ui->treeView->setItemDelegateForColumn(0, lineTextEditor);
ui->treeView->setItemDelegateForColumn(2, lineTextEditor);
// Números
auto* doubleNumberEditor = new ItemNumberDelegate(0.0, 999999.99, 0.05, 2, this);
ui->treeView->setItemDelegateForColumn(4, doubleNumberEditor);
ui->treeView->setItemDelegateForColumn(7, doubleNumberEditor);
ui->treeView->setItemDelegateForColumn(9, doubleNumberEditor);
ui->treeView->setItemDelegateForColumn(10, doubleNumberEditor);
// Combobox
auto* comboboxEditor = new ItemComboboxDelegate(this);
ui->treeView->setItemDelegateForColumn(6, comboboxEditor);
connect(m_treeModel, &TreeModel::dataChanged,
this, &formBudget::onModelDataChanged);
}
void formBudget::setupConnections()
{
connect(ui->buttonInsertRow, &QPushButton::released,
this, &formBudget::insertRow);
connect(ui->buttonInsertChild, &QPushButton::released,
this, &formBudget::insertChild);
connect(ui->buttonRemoveRow, &QPushButton::released,
this, &formBudget::removeRow);
// ... otras conexiones ...
}
void formBudget::initializeDocument()
{
if (m_dbUtils.isConnected()) {
QString lastId = m_dbUtils.getLastDocumentId("SALEPROPOSAL");
ui->editCode->setText(QString("(PRO%1)").arg(lastId.toInt() + 1));
}
}
void formBudget::newDocument()
{
}
void formBudget::openDocument(QString id)
{
formBase::openDocument(id);
}
void formBudget::save()
{
QString budget;
QString budgetdata;
if(mEditMode == false)
{
budget = "INSERT INTO SALEPROPOSAL ("
"ID, TYPE, CODE, TITLE, VERSION, "
"CUSTOMER_CODE, CUSTOMER_NAME, PROJECT_CODE, PROJECT_TITLE, "
"COST, PRICE, TAX, STATE, STATE_NUMBER, DESCRIPTION, "
"CREATEDAT, VALIDUNTILL, DELIVERY_DATE, CREATEDBY"
") VALUES ("
":ID, :TYPE, :CODE, :TITLE, :VERSION, "
":CUSTOMER_CODE, :CUSTOMER_NAME, :PROJECT_CODE, :PROJECT_TITLE, "
":COST, :PRICE, :TAX, :STATE, :STATE_NUMBER, :DESCRIPTION, "
":CREATEDAT, :VALIDUNTILL, :DELIVERY_DATE, :CREATEDBY"
");";
budgetdata = "INSERT INTO SALEPROPOSALDATA ("
"ID, SALEDOCUMENT_CODE, VERSION, NODEINDEX, "
"ELEMENT_CODE, ELEMENT_TYPE, ELEMENT_INDEX, ELEMENT_TITLE, ELEMENT_DESCRIPTION, "
"ELEMENT_UNIT_AMOUNT, ELEMENT_TOTAL_AMOUNT, ELEMENT_UNIT, ELEMENT_PRICE, "
"BENEFIT, DISCOUNT, TAX, PRINT, "
"CREATEDAT, CREATEDBY"
") VALUES ("
":ID, :SALEDOCUMENT_CODE, :VERSION, :NODEINDEX, "
":ELEMENT_CODE, :ELEMENT_TYPE, :ELEMENT_INDEX, :ELEMENT_TITLE, :ELEMENT_DESCRIPTION, "
":ELEMENT_UNIT_AMOUNT, :ELEMENT_TOTAL_AMOUNT, :ELEMENT_UNIT, :ELEMENT_PRICE, "
":BENEFIT, :DISCOUNT, :TAX, :PRINT, "
":CREATEDAT, :CREATEDBY"
");";
}
else
{
budget = "UPDATE SALEPROPOSAL SET "
":ID, :TYPE, :CODE, :TITLE, :VERSION, "
":CUSTOMER_CODE, :CUSTOMER_NAME, :PROJECT_CODE, :PROJECT_TITLE, "
":COST, :PRICE, :TAX, :STATE, :STATE_NUMBER, :DESCRIPTION, "
":CREATEDAT, :VALIDUNTILL, :DELIVERY_DATE, :CREATEDBY "
"WHERE CODE = :CODE"
";";
budgetdata = "UPDATE SALEPROPOSALDATA SET "
":ID, :SALEDOCUMENT_CODE, :VERSION, :NODEINDEX, "
":ELEMENT_CODE, :ELEMENT_TYPE, :ELEMENT_INDEX, :ELEMENT_TITLE, :ELEMENT_DESCRIPTION, "
":ELEMENT_UNIT_AMOUNT, :ELEMENT_TOTAL_AMOUNT, :ELEMENT_UNIT, :ELEMENT_PRICE, "
":BENEFIT, :DISCOUNT, :TAX, :PRINT, "
":CREATEDAT, :CREATEDBY "
"WHERE CODE = :CODE"
";";
}
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
// 1. Guardar los datos:
QAbstractItemModel *model = ui->treeView->model();
// Borrar toda las filas al final que están vacias
// -- de momento se hace chequeando si la columna 13 está vacía
/*
int count = model->rowCount() - 1;
for (int i = model->rowCount() - 1; i >= 0; i--)
{
count = i;
QString dat = model->index(i, 13).data().toString();
if(!dat.isEmpty())
break;
}
for (int i = 0; i <= count; i++)
{
qry.prepare(budgetdata);
qry.bindValue(":ID", i);
qry.bindValue(":SALEDOCUMENT_CODE", ui->editCode->text());
qry.bindValue(":VERSION", ui->editVersion->currentText());
qry.bindValue(":NODEINDEX", model->index(i, 0).data().toString());
qry.bindValue(":ELEMENT_CODE", model->index(i, 1).data().toString());
qry.bindValue(":ELEMENT_TYPE", model->index(i, 13).data().toString());
qry.bindValue(":ELEMENT_TITLE", model->index(i, 2).data().toString());
qry.bindValue(":ELEMENT_DESCRIPTION", model->index(i, 3).data().toString());
qry.bindValue(":ELEMENT_UNIT_AMOUNT", model->index(i, 4).data().toDouble());
//qry.bindValue(":ELEMENT_TOTAL_AMOUNT", model->index(i, 2).data().toDouble());
qry.bindValue(":ELEMENT_UNIT", model->index(i, 6).data().toString());
qry.bindValue(":ELEMENT_PRICE", model->index(i, 7).data().toString());
qry.bindValue(":BENEFIT", model->index(i, 9).data().toString());
qry.bindValue(":DISCOUNT", model->index(i, 10).data().toString());
//qry.bindValue(":TAX", model->index(i, 10).data().toString());
//qry.bindValue(":PRINT", model->index(i, 10).data().toBool());
if(!qry.exec())
{
qDebug() << "" << qry.lastError().text();
continue;
}
}
*/
// 2. Si todo fue bien, guardar el documento:
qry.prepare(budget);
//qry.bindValue(":ID",);
qry.bindValue(":TYPE", "");
qry.bindValue(":CODE", ui->editCode->text());
qry.bindValue(":TITLE", ui->editTitle->text());
qry.bindValue(":VERSION", ui->editVersion->currentText());
qry.bindValue(":CUSTOMER_CODE", ui->editClientCode->currentText());
qry.bindValue(":CUSTOMER_NAME", ui->editClientName->text());
qry.bindValue(":PROJECT_CODE", ui->editProjectCode->currentText());
qry.bindValue(":PROJECT_TITLE", ui->editProjectName->text());
qry.bindValue(":COST", ui->editCost->text());
qry.bindValue(":PRICE", ui->editPrice->text());
//qry.bindValue(":TAX", );
qry.bindValue(":STATE", ui->editPrice->text());
qry.bindValue(":STATE_NUMBER", ui->editPrice->text());
//qry.bindValue(":DESCRIPTION", );
qry.bindValue(":CREATEDAT", ui->editdateCreated->text());
qry.bindValue(":VALIDUNTILL", ui->editdateValidUntill->text());
//qry.bindValue(":DELIVERY_DATE", ui->editPrice->text());
//qry.bindValue(":CREATEDBY", ui->editPrice->text());
if(!qry.exec())
{
qDebug() << "" << qry.lastError().text();
}
else
mEditMode = true;
dApp->Enterprise().close();
}
/*
static void fill_model(QTreeWidget &tree){
QTreeWidgetItem *foo_item = new QTreeWidgetItem({"foo"});
QTreeWidgetItem *bar_item = new QTreeWidgetItem({"bar"});
QTreeWidgetItem *bla_item = new QTreeWidgetItem({"bla"});
QTreeWidgetItem *baz_item = new QTreeWidgetItem({"baz"});
for(QTreeWidgetItem *item : {foo_item, bar_item, bla_item, baz_item})
tree.addTopLevelItem(item);
QTreeWidgetItem *beer_item = new QTreeWidgetItem({"beer"});
QTreeWidgetItem *beer_child_item = new QTreeWidgetItem({"beer_child"});
QTreeWidgetItem *ice_item = new QTreeWidgetItem({"ice"});
for(QTreeWidgetItem *item : {beer_item, ice_item})
bar_item->addChild(item);
beer_item->addChild(beer_child_item);
beer_child_item->addChild(new QTreeWidgetItem({"beer_child_child"}));
}
static void save_to_db(const QString & tablename, QTreeWidgetItem* parent, int parent_id=0){
for(int i=0; i< parent->childCount(); ++i){
QTreeWidgetItem *child_item = parent->child(i);
QSqlQuery query(QString("INSERT INTO %1 (parentId, name) VALUES (?, ?)").arg(tablename));
if(parent_id != 0)
query.bindValue(0, parent_id);
query.bindValue(1, child_item->text(0));
if(!query.exec())
qDebug()<< query.lastError().text();
save_to_db(tablename, child_item, query.lastInsertId().toInt());
}
}
*/
void formBudget::saveModel(QSqlQuery qry, QString aCommand, QAbstractItemModel *aModel, int aLevel)
{
//QObjectList list = aModel->parent()->children();
//for (auto aChil : list)
for (int i = 0; i <= aModel->rowCount() - 1; i++)
{
qry.prepare(aCommand);
qry.bindValue(":ID", i);
qry.bindValue(":SALEDOCUMENT_CODE", ui->editCode->text());
qry.bindValue(":VERSION", ui->editVersion->currentText());
qry.bindValue(":NODEINDEX", aModel->index(i, 0).data().toString());
qry.bindValue(":ELEMENT_CODE", aModel->index(i, 1).data().toString());
qry.bindValue(":ELEMENT_TYPE", aModel->index(i, 13).data().toString());
qry.bindValue(":ELEMENT_TITLE", aModel->index(i, 2).data().toString());
qry.bindValue(":ELEMENT_DESCRIPTION", aModel->index(i, 3).data().toString());
qry.bindValue(":ELEMENT_UNIT_AMOUNT", aModel->index(i, 4).data().toDouble());
//qry.bindValue(":ELEMENT_TOTAL_AMOUNT", aModel->index(i, 2).data().toDouble());
qry.bindValue(":ELEMENT_UNIT", aModel->index(i, 6).data().toString());
qry.bindValue(":ELEMENT_PRICE", aModel->index(i, 7).data().toString());
qry.bindValue(":BENEFIT", aModel->index(i, 9).data().toString());
qry.bindValue(":DISCOUNT", aModel->index(i, 10).data().toString());
//qry.bindValue(":TAX", aModel->index(i, 10).data().toString());
//qry.bindValue(":PRINT", aModel->index(i, 10).data().toBool());
if(!qry.exec())
{
qDebug() << "" << qry.lastError().text();
continue;
}
if(aModel->index(i, 13).data().toString() == "CO")
{
//QAbstractItemModel * childModel = aModel->index(i, 13).child(0, 0);
//saveModel(qry, aCommand, childModel, aLevel + 1);
}
}
}
bool formBudget::needsave()
{
return formBase::needsave();
}
void formBudget::setEditMode(bool aMode)
{
formBase::setEditMode(aMode);
}
void formBudget::closeDocument()
{
if(mNeedSave)
{
}
save();
}
void formBudget::on_editPrice_textChanged(const QString &arg1)
{
}
void formBudget::on_buttonInsertRow_released()
{
ui->treeView->insertRow();
}
void formBudget::on_buttonInsertChild_released()
{
QModelIndex selindex = ui->treeView->selectionModel()->currentIndex();
QAbstractItemModel *treemodel = ui->treeView->model();
ui->treeView->insertChild();
QModelIndex child = treemodel->index(selindex.row(), 13, selindex.parent());
treemodel->setData(child, QVariant("CO"), Qt::EditRole);
}
void formBudget::on_buttonRemoveRow_released()
{
ui->treeView->removeRow();
}
void formBudget::on_buttonMaterials_released()
{
ui->treeView->insertRow();
setLineType("MT", ui->treeView->selectionModel()->currentIndex());
}
void formBudget::on_buttoMachinary_released()
{
ui->treeView->insertRow();
setLineType("MQ", ui->treeView->selectionModel()->currentIndex());
}
void formBudget::on_buttonManpower_released()
{
ui->treeView->insertRow();
setLineType("MO", ui->treeView->selectionModel()->currentIndex());
}
void formBudget::on_buttonPercent_released()
{
ui->treeView->insertRow();
setLineType("%", ui->treeView->selectionModel()->currentIndex());
}
void formBudget::setLineType(QString type, QModelIndex index)
{
setCellText(type, index, 13);
}
void formBudget::setCellText(QString val, QModelIndex index, int col)
{
QAbstractItemModel *treemodel = ui->treeView->model();
QModelIndex child = treemodel->index(index.row(), col, index.parent().isValid() ? index.parent() : QModelIndex());
treemodel->setData(child, QVariant(val), Qt::EditRole);
}
bool formBudget::InsertElement(QString ID, QModelIndex index)
{
if (ID.isEmpty())
return false;
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
if (qry.exec(QString("SELECT * FROM ELEMENT WHERE CODE = '%1';").arg(ID)))
{
qry.first();
setCellText(qry.value(qry.record().indexOf("TITLE")).toString(), index, 2); // TITLE
setCellText(qry.value(qry.record().indexOf("DESCRIPTION")).toString(), index, 3); // DESCRIPTION
setCellText(qry.value(qry.record().indexOf("UNIT_ID")).toString(), index, 6); // UNIT
if (qry.value(qry.record().indexOf("TYPE1")).toInt() == 0)
{
QSqlQuery comp = QSqlQuery(dApp->Enterprise());
QAbstractItemModel *treemodel = ui->treeView->model();
if (comp.exec(QString("SELECT * FROM ELEMENTCOMPOSITION WHERE CODE = '%1';").arg(ID)))
{
QList<QPair<QString, QString> > list;
while(comp.next())
{
list.append(qMakePair(comp.value(comp.record().indexOf("ELEMENT_CODE")).toString(),
comp.value(comp.record().indexOf("ELEMENT_AMOUNT")).toString()));
}
int row = 0;
while (row < list.size())
{
if(!treemodel->insertRow(treemodel->rowCount(index), treemodel->index(index.row(), 0, index.parent())))
break;
qDebug() << treemodel->rowCount(index);
QModelIndex child = treemodel->index(row, 0, treemodel->index(index.row(), 0, index.parent()));
setCellText(list.at(row).first, child, 1);
setCellText(list.at(row).second, child, 4); //AMOUNT*/
row++;
}
}
}
else
{
setCellText(qry.value(qry.record().indexOf("PURCHASE_PRICE")).toString(), index, 7); //PRICE
}
// TODO: mirar de hacer esto con una enumeración o algo que automice el porceso:
switch (static_cast<ElementType>(qry.value(qry.record().indexOf("TYPE1")).toInt()))
{
case ElementType::Composed:
setLineType("CO", index); // type
break;
case ElementType::Material:
setLineType("MT", index); // type
break;
case ElementType::ManPower:
setLineType("MO", index); // type
break;
case ElementType::Machinery:
setLineType("MQ", index); // type
break;
default:
break;
}
}
else
{
qDebug() << qry.lastError().text();
}
dApp->Enterprise().close();
return false;
}
void formBudget::on_buttonValidate_released()
{
// TODO: generar el código definitivo
mDocumentID = ui->editCode->text();
setWindowTitle(mDocumentID);
QTabWidget * prt = static_cast<QTabWidget*>(parent()->parent());
prt->setTabText(prt->currentIndex(), mDocumentID);
}
void formBudget::on_buttonSave_released()
{
save();
}
void formBudget::on_ModelSetData(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
if(mEditMode)
return;
Q_UNUSED(bottomRight);
if(topLeft.column() == 1)
{
qDebug() << topLeft.data().toString();
InsertElement(topLeft.data().toString(), topLeft);
}
}
void formBudget::focusInEvent(QFocusEvent *event)
{
qDebug() << "focusInEvent";
}
void formBudget::focusOutEvent(QFocusEvent *event)
{
qDebug() << "focusOutEvent";
}
void formBudget::on_tabWidget_currentChanged(int index)
{
if (index == 1)
{
ui->ToolbarLines->setVisible(true);
}
else
{
ui->ToolbarLines->setVisible(false);
}
}
-68
View File
@@ -1,68 +0,0 @@
#ifndef FORMBUDGET_H
#define FORMBUDGET_H
#include "formbase.h"
#include <QWidget>
class QString;
class TreeItem;
class QSqlQuery;
class QAbstractItemModel;
class TreeModel;
namespace Ui
{
class formBudget;
}
class formBudget : public formBase
{
Q_OBJECT
public:
explicit formBudget(QString aID = "", int aEditMode = 0, QWidget *parent = nullptr);
~formBudget() override;
//void openDocument(QString id);
void newDocument() override;
void openDocument(QString id) override;
void save() override;
bool needsave() override;
void setEditMode(bool aMode) override;
void closeDocument() override;
private slots:
void on_editPrice_textChanged(const QString &arg1);
void on_buttonInsertRow_released();
void on_buttonInsertChild_released();
void on_buttonPercent_released();
void on_buttonRemoveRow_released();
void on_buttonMaterials_released();
void on_buttoMachinary_released();
void on_buttonManpower_released();
void on_buttonValidate_released();
void on_buttonSave_released();
void on_ModelSetData(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void on_tabWidget_currentChanged(int index);
private:
TreeModel *m_treeModel;
Ui::formBudget *ui;
void setLineType(QString type, QModelIndex index);
void setCellText(QString val, QModelIndex index, int col);
bool InsertElement(QString ID, QModelIndex index);
void saveModel(QSqlQuery qry, QString aCommand, QAbstractItemModel *aModel, int aLevel);
void setupTreeView();
void setupDelegates();
void setupConnections();
void initializeDocument();
protected:
virtual void focusInEvent(QFocusEvent *event) override;
virtual void focusOutEvent(QFocusEvent *event) override;
};
#endif // FORMBUDGET_H
-1600
View File
File diff suppressed because it is too large Load Diff
-14
View File
@@ -1,14 +0,0 @@
#include "formbudgetlist.h"
#include "ui_formbudgetlist.h"
FormBudgetList::FormBudgetList(FormBaseList *parent)
: FormBaseList(parent)
, ui(new Ui::FormBudgetList)
{
ui->setupUi(this);
}
FormBudgetList::~FormBudgetList()
{
delete ui;
}
-23
View File
@@ -1,23 +0,0 @@
#ifndef FORMBUDGETLIST_H
#define FORMBUDGETLIST_H
#include <QWidget>
#include <gui/formbaselist.h>
namespace Ui {
class FormBudgetList;
}
class FormBudgetList : public FormBaseList
{
Q_OBJECT
public:
explicit FormBudgetList(FormBaseList *parent = nullptr);
~FormBudgetList();
private:
Ui::FormBudgetList *ui;
};
#endif // FORMBUDGETLIST_H
-19
View File
@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FormBudgetList</class>
<widget class="QWidget" name="FormBudgetList">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<resources/>
<connections/>
</ui>
@@ -93,20 +93,17 @@ void formElementList::on_buttonDelete_released()
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
// Check if it's a composed element (TYPE1 = 0) and delete its composition first
QModelIndex parentIndex = index.parent();
QModelIndex childIndex = model->index(index.row(), 2, parentIndex); // Obtén el índice del hijo
int type = childIndex.data().toInt(); // Accede al dato
if (type == 0) // ElementType::Composed
/*
if (index.parent().child(index.row(), 2).data().toInt() == 0)
{
// Delete composition elements first
// TODO: borrar la composición
if(!qry.exec(QString("DELETE FROM ELEMENTCOMPOSITION WHERE CODE = '%1';").arg(ID)))
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
goto error;
}
}
*/
if(!qry.exec(QString("DELETE FROM ELEMENT WHERE CODE = '%1';").arg(ID)))
{
+178
View File
@@ -0,0 +1,178 @@
#include "formelementlist.h"
#include "qpainter.h"
#include "ui_formelementlist.h"
#include "formproduct.h"
#include "mainwindow.h"
#include "mapplication.h"
#include "msqlquerymodel.h"
#include "utils/filtertableheader.h"
#include "gui/formbaselist.h"
#include <QDrag>
formElementList::formElementList(QWidget *parent) :
QWidget(parent),
ui(new Ui::formElementList)
{
ui->setupUi(this);
mModel = new MSqlQueryModel(this);
ui->tableView->setModel(mModel);
updateList();
ui->tableView->setColumnWidth(0, 150);
ui->tableView->setColumnWidth(1, 80);
ui->tableView->setColumnWidth(2, 120);
ui->tableView->setColumnWidth(3, 350);
ui->tableView->setColumnWidth(4, 80);
ui->tableView->setColumnWidth(5, 80);
ui->tableView->setColumnWidth(6, 40);
// Set up filter row
auto *m_tableHeader = new FilterTableHeader(ui->tableView);
ui->tableView->setHorizontalHeader(m_tableHeader);
m_tableHeader->setFilter(0, "");
m_tableHeader->setFocusColumn(0);
ui->tableView->horizontalHeader()->model()->setHeaderData(0, Qt::Horizontal, tr("Tipo"));
ui->tableView->horizontalHeader()->model()->setHeaderData(1, Qt::Horizontal, tr("Clase"));
ui->tableView->horizontalHeader()->model()->setHeaderData(2, Qt::Horizontal, tr("Código"));
ui->tableView->horizontalHeader()->model()->setHeaderData(3, Qt::Horizontal, tr("Resumen"));
ui->tableView->horizontalHeader()->model()->setHeaderData(4, Qt::Horizontal, tr("Coste"));
ui->tableView->horizontalHeader()->model()->setHeaderData(5, Qt::Horizontal, tr("Venta"));
ui->tableView->horizontalHeader()->model()->setHeaderData(6, Qt::Horizontal, tr("Activo"));
ui->tableView->setDragEnabled(true); // Habilita el drag
connect(ui->tableView, &QTableView::pressed, this, &formElementList::startDrag);
}
formElementList::~formElementList()
{
delete ui;
}
void formElementList::updateList()
{
dApp->Enterprise().open();
mModel->setQuery("SELECT TYPE1, TYPE2, CODE, TITLE, PURCHASE_PRICE, SALE_PRICE, STATE FROM ELEMENT" /*" ORDER BY CODE ASC"*/,
dApp->Enterprise());
dApp->Enterprise().close();
}
void formElementList::on_buttonNew_released()
{
formProduct *form = dApp->mainWindow()->createFormProduct(); // sustistuir por Mainwindow::createFormProduct();
form->show();
}
void formElementList::on_buttonEdit_released()
{
openDocument(ui->tableView->currentIndex());
}
void formElementList::on_buttonClone_released()
{
}
void formElementList::on_buttonDelete_released()
{
QModelIndex index = ui->tableView->currentIndex();
QAbstractItemModel *model = const_cast<QAbstractItemModel*>(index.model()); // Obtén el modelo asociado
if (index.column() != 0)
{
//index = index.parent().child(index.row(), 0);
index = model->index(index.row(), 0, index.parent());
}
QString ID = index.data().toString();
QModelIndex parentIndex = index.parent();
QModelIndex childIndex = model->index(index.row(), 2, parentIndex); // Obtén el índice del hijo
int type = childIndex.data().toInt(); // Accede al dato
//int type = index.parent().child(index.row(), 2).data().toInt();
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
/*
if (index.parent().child(index.row(), 2).data().toInt() == 0)
{
// TODO: borrar la composición
if(!qry.exec(QString("DELETE FROM ELEMENTCOMPOSITION WHERE CODE = '%1';").arg(ID)))
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
goto error;
}
}
*/
if(!qry.exec(QString("DELETE FROM ELEMENT WHERE CODE = '%1';").arg(ID)))
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
}
updateList();
error:
dApp->Enterprise().close();
}
void formElementList::on_buttonUpdate_released()
{
updateList();
}
void formElementList::on_tableView_doubleClicked(const QModelIndex &index)
{
openDocument(index);
}
void formElementList::openDocument(QModelIndex index)
{
QAbstractItemModel *model = ui->tableView->model();
//QModelIndex item = index;
formProduct *form = dApp->mainWindow()->createFormProduct();
//if (index.column() != 2)
// item = index.parent().child(index.row(), 2);
form->openDocument(model->index(index.row(), 2).data().toString());// item.data().toString());
form->show();
}
void formElementList::startDrag(const QModelIndex &index) {
if (!index.isValid())
return;
// Crear datos MIME
QMimeData *mimeData = new QMimeData();
QString data = mModel->data(index).toString();
mimeData->setText(data);
// Iniciar arrastre
QDrag *drag = new QDrag(ui->tableView);
drag->setMimeData(mimeData);
// Crear un ícono para el cursor
QPixmap pixmap(100, 30);
pixmap.fill(Qt::transparent); // Fondo transparente
QPainter painter(&pixmap);
painter.setBrush(Qt::yellow);
painter.drawRoundedRect(0, 0, pixmap.width(), pixmap.height(), 5, 5);
painter.setPen(Qt::black);
painter.drawText(pixmap.rect(), Qt::AlignCenter, data);
painter.end();
drag->setPixmap(pixmap); // Asignar el ícono al cursor
//drag->setHotSpot(QPoint(pixmap.width() / 2, pixmap.height() / 2)); // Centro del ícono como punto caliente
drag->exec(Qt::MoveAction);
}
-40
View File
@@ -1,40 +0,0 @@
#ifndef FORMELEMENTLIST_H
#define FORMELEMENTLIST_H
#include <QWidget>
class QSqlQueryModel;
namespace Ui
{
class formElementList;
}
class formElementList : public QWidget
{
Q_OBJECT
public:
explicit formElementList(QWidget *parent = nullptr);
~formElementList();
private slots:
void on_buttonNew_released();
void on_buttonEdit_released();
void on_buttonClone_released();
void on_buttonDelete_released();
void on_buttonUpdate_released();
void on_tableView_doubleClicked(const QModelIndex &index);
void startDrag(const QModelIndex &index);
private:
Ui::formElementList *ui;
QSqlQueryModel *mModel;
void updateList();
void openDocument(QModelIndex index);
};
#endif // FORMELEMENTLIST_H
-126
View File
@@ -1,126 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>formElementList</class>
<widget class="QWidget" name="formElementList">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>631</width>
<height>436</height>
</rect>
</property>
<property name="windowTitle">
<string>Elementos</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTableView" name="tableView">
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="buttonNew">
<property name="text">
<string>Nuevo</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/add-file.svg</normaloff>:/resources/icons/add-file.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonEdit">
<property name="text">
<string>Editar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/pencil.svg</normaloff>:/resources/icons/pencil.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonClone">
<property name="text">
<string>Duplicar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/copy.svg</normaloff>:/resources/icons/copy.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonDelete">
<property name="text">
<string>Borrar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/recycle.svg</normaloff>:/resources/icons/recycle.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonUpdate">
<property name="text">
<string>Actualizar</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../editabletreemodel.qrc"/>
</resources>
<connections/>
</ui>
-14
View File
@@ -1,14 +0,0 @@
#include "forminvoiceinlist.h"
#include "ui_forminvoiceinlist.h"
formInvoiceInList::formInvoiceInList(QWidget *parent) :
FormBaseList(parent),
ui(new Ui::formInvoiceInList)
{
//ui->setupUi(this);
}
formInvoiceInList::~formInvoiceInList()
{
delete ui;
}
-24
View File
@@ -1,24 +0,0 @@
#ifndef FORMINVOICEINLIST_H
#define FORMINVOICEINLIST_H
#include <QDockWidget>
#include "formbaselist.h"
namespace Ui {
class formInvoiceInList;
}
class formInvoiceInList : public FormBaseList
{
Q_OBJECT
public:
explicit formInvoiceInList(QWidget *parent = nullptr);
~formInvoiceInList();
private:
Ui::formInvoiceInList *ui;
};
#endif // FORMINVOICEINLIST_H
-19
View File
@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>formInvoiceInList</class>
<widget class="QDockWidget" name="formInvoiceInList">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>596</width>
<height>320</height>
</rect>
</property>
<property name="windowTitle">
<string>DockWidget</string>
</property>
</widget>
<resources/>
<connections/>
</ui>
-509
View File
@@ -1,509 +0,0 @@
#include "formproduct.h"
#include "ui_formproduct.h"
#include "mapplication.h"
#include "treemodelcomposeelement.h"
#include "itemnumberdelegate.h"
#include "itemtextdelegate.h"
#include "itemtextpopupdelegate.h"
#include "itemcomboboxdelegate.h"
#include "QtSql"
formProduct::formProduct(QString aID, int aEditMode, QWidget *parent) :
formBase(aID, aEditMode, parent),
ui(new Ui::formProduct),
editMode(false)
{
ui->setupUi(this);
ui->editDischargeDate->setDate(QDate::currentDate());
ui->editUpdateDate->setDate(QDate::currentDate());
QStringList headers;
headers << tr("Código") //Código del elemento (editable)
<< tr("Título") //Título del elemento (NO editable)
<< tr("Cantidad") //Cantidad del elemento (editable)
<< tr("Cantidad total") //Cantidad total del elemento (NO editable)
<< tr("Unidad") //Unidad del elemento (editable)
<< tr("N. Precio Unitario") //Precio unitario del elemento (editable)
<< tr("N. Precio Total") //Precio total del elemento (NO editable)
<< tr("Tipo")
<< ("");
TreeModelComposeElement *model = new TreeModelComposeElement(headers, QByteArray());
ui->treeView->setModel(model);
// Texto con Popup
ItemTextPopupDelegate *LineTextPopup = new ItemTextPopupDelegate(this);
ui->treeView->setItemDelegateForColumn(0, LineTextPopup);
// Texto:
//ItemTextDelegate *LineTextEditor = new ItemTextDelegate(this);
//ui->treeView->setItemDelegateForColumn(0, LineTextEditor);
//ui->treeView->setItemDelegateForColumn(2, LineTextEditor);
// Números:
ItemNumberDelegate *doubleNumberEditor = new ItemNumberDelegate(0.0, 999999.99, 0.05, 2, this);
ui->treeView->setItemDelegateForColumn(2, doubleNumberEditor);
// Combobox:
//ItemComboboxDelegate *ComboboxEditor = new ItemComboboxDelegate(this);
//ui->treeView->setItemDelegateForColumn(6, ComboboxEditor);
connect(model, &TreeModelComposeElement::dataChanged, this, &formProduct::on_ModelSetData);
ui->treeView->setColumnWidth( 0, 150);
ui->treeView->setColumnWidth( 1, 250);
ui->treeView->setColumnWidth( 2, 80);
ui->treeView->setColumnWidth( 3, 80);
ui->treeView->setColumnWidth( 4, 50);
ui->treeView->setColumnWidth( 5, 80);
ui->treeView->setColumnWidth( 6, 80);
//Arg1: the number
//Arg2: how many 0 you want?
//Arg3: The base (10 - decimal, 16 hexadecimal - if you don't understand, choose 10)
// It seems like only decimal can support negative numbers.
ui->editCode->setText(QString("EL%1").arg(2, 10, 10, QChar('0')));
// Unidades:
dApp->Enterprise().open();
QSqlQueryModel *unitModel = new QSqlQueryModel(this);
unitModel->setQuery("SELECT * FROM UNIT", dApp->Enterprise());
//ui->comboUnit->setModel(unitModel);
QTableView* tableView = new QTableView( this );
QHeaderView* header = tableView->verticalHeader();
header->setDefaultSectionSize(20); // 20 px height
header->sectionResizeMode(QHeaderView::Fixed);
tableView->setModel( unitModel );
tableView->verticalHeader()->setVisible(false);
tableView->horizontalHeader()->setVisible(false);
tableView->setColumnWidth ( 0, 60 );
tableView->setColumnWidth ( 1, 160 );
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setAutoScroll(false);
ui->comboUnit->setModel( unitModel );
ui->comboUnit->setView( tableView );
ui->comboUnit->view()->setMinimumWidth(220);
dApp->Enterprise().close();
}
formProduct::~formProduct()
{
delete ui;
}
void formProduct::openDocument(QString id)
{
setEditMode();
ui->editCode->setText(id);
ui->editCode->setReadOnly(true);
ui->treeView->model()->removeRows(0, ui->treeView->model()->rowCount());
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
if(qry.exec(QString("SELECT * FROM ELEMENT WHERE CODE = '%1';").arg(id)))
{
qry.first();
ui->comboType1->setCurrentIndex(qry.value(qry.record().indexOf("TYPE1")).toInt());
ui->comboType2->setCurrentIndex(qry.value(qry.record().indexOf("TYPE2")).toInt());
ui->editTitle->setText(qry.value(qry.record().indexOf("TITLE")).toString());
ui->editDescription->setHtml(qry.value(qry.record().indexOf("DESCRIPTION")).toString());
//ui->editTitle->setText(qry.value(4).toString()); // FAMILY_ID
ui->comboUnit->setCurrentText(qry.value(qry.record().indexOf("UNIT_ID")).toString()); // UNIT_ID
ui->editUpdateDate->setDate(qry.value(qry.record().indexOf("DATE_UPDATE")).toDate());
//ui->editDischargeDate->setDate(qry.value().toDate());
ui->editPVP->setValue(qry.value(qry.record().indexOf("REAL_PRICE")).toDouble());
ui->editDiscount->setValue(qry.value(qry.record().indexOf("DISCOUNT")).toDouble());
ui->editPC->setValue(qry.value(qry.record().indexOf("PURCHASE_PRICE")).toDouble());
ui->editMargin->setValue(qry.value(qry.record().indexOf("BENEFIT")).toDouble());
ui->editPV->setValue(qry.value(qry.record().indexOf("SALE_PRICE")).toDouble());
ui->comboIVA->setCurrentText(qry.value(qry.record().indexOf("TAX")).toString());
ui->checkState->setChecked(qry.value(qry.record().indexOf("STATE")).toBool());
ui->editWeight->setValue(qry.value(qry.record().indexOf("WEIGHT")).toDouble());
ui->editHeight->setValue(qry.value(qry.record().indexOf("HEIGHT")).toDouble());
ui->editWidth->setValue(qry.value(qry.record().indexOf("WIDTH")).toDouble());
ui->editLength->setValue(qry.value(qry.record().indexOf("LENGHT")).toDouble());
if(qry.value(qry.record().indexOf("TYPE1")).toInt() == 0)
{
setComposeElement(true);
QList<QPair<QString, QString> > list;
if(qry.exec(QString("SELECT * FROM ELEMENTCOMPOSITION WHERE CODE = '%1';").arg(id)))
{
while(qry.next())
{
list.append(qMakePair(qry.value(qry.record().indexOf("ELEMENT_CODE")).toString(),
qry.value(qry.record().indexOf("ELEMENT_AMOUNT")).toString()));
}
int row = 0;
while(row < list.size())
{
ui->treeView->addRow();
QModelIndex index = ui->treeView->model()->index(row, 0);
setCellText(list.at(row).first, index, 0); // CODE
setCellText(list.at(row).second, index, 2); // AMOUNT
row ++;
}
ui->treeView->addRow();
}
else
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
}
}
else
{
setComposeElement(false);
}
}
else
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
}
dApp->Enterprise().close();
}
void formProduct::closeDocument()
{
close();
}
void formProduct::setEditMode()
{
editMode = true;
ui->editCode->setReadOnly(true);// ->setEnabled(false);
}
void formProduct::on_editPC_valueChanged(double arg1)
{
CalculatePrice();
}
void formProduct::on_editMargin_valueChanged(double arg1)
{
CalculatePrice();
}
void formProduct::on_editPV_valueChanged(double arg1)
{
}
void formProduct::on_editPV_editingFinished()
{
double pc = ui->editPC->value();
if (pc == 0)
return;
double ma;
double pv = ui->editPV->value();
ma = (pv/pc - 1) * 100;
if(ma != ui->editMargin->value())
ui->editMargin->setValue(ma);
}
void formProduct::on_comboIVA_currentIndexChanged(const QString &arg1)
{
CalculatePrice();
}
void formProduct::CalculatePrice()
{
double pc = ui->editPC->value();
double ma = ui->editMargin->value();
QString ivatext = ui->comboIVA->currentText().replace("%", "");
double iva = ivatext.toDouble();
double pv = pc * (1 + ma / 100);
ui->editPV->setValue(pv);
ui->editPVIVA->setValue( pv * (1 + iva / 100));
}
void formProduct::save()
{
// INSERT
QString Element;
QString ElementComp;
if(editMode == false)
{
Element = "INSERT INTO ELEMENT ("
"CODE, TYPE1, TYPE2, TITLE, DESCRIPTION, FAMILY_ID, UNIT_ID, "
"DATE_UPDATE, REAL_PRICE, DISCOUNT, PURCHASE_PRICE, BENEFIT, TAX, SALE_PRICE, "
"BARCODE, IMAGE, STATE, MANUFACTURER, GAMMA, "
"WEIGHT, HEIGHT, WIDTH, LENGHT"
") VALUES ("
":CODE, :TYPE1, :TYPE2, :TITLE, :DESCRIPTION, :FAMILY_ID, :UNIT_ID, "
":DATE_UPDATE, :REAL_PRICE, :DISCOUNT, :PURCHASE_PRICE, :BENEFIT, :TAX, :SALE_PRICE, "
":BARCODE, :IMAGE, :STATE, :MANUFACTURER, :GAMMA, "
":WEIGHT, :HEIGHT, :WIDTH, :LENGHT"
");";
ElementComp = "INSERT INTO ELEMENTCOMPOSITION ("
"CODE, ELEMENT_CODE, ELEMENT_AMOUNT"
") VALUES ("
":CODE, :ELEMENT_CODE, :ELEMENT_AMOUNT"
");";
}
// UPDATE
else
{
Element = "UPDATE ELEMENT SET "
"TYPE1 = :TYPE1, TYPE2 = :TYPE2, TITLE = :TITLE, DESCRIPTION = :DESCRIPTION, FAMILY_ID = :FAMILY_ID, "
"UNIT_ID = :UNIT_ID, DATE_UPDATE = :DATE_UPDATE, REAL_PRICE = :REAL_PRICE, DISCOUNT = :DISCOUNT, "
"PURCHASE_PRICE = :PURCHASE_PRICE, BENEFIT = :BENEFIT, TAX = :TAX, SALE_PRICE = :SALE_PRICE, BARCODE = :BARCODE, IMAGE = :IMAGE, "
"STATE = :STATE, MANUFACTURER = :MANUFACTURER, GAMMA = :GAMMA, WEIGHT = :WEIGHT, HEIGHT = :HEIGHT, "
"WIDTH = :WIDTH, LENGHT = :LENGHT "
"WHERE CODE = :CODE"
";";
ElementComp = "UPDATE ELEMENTCOMPOSITION SET "
"ELEMENT_AMOUNT = :ELEMENT_AMOUNT "
"WHERE CODE = :CODE AND ELEMENT_CODE = :ELEMENT_CODE";
}
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
// 1. Si es compuesto crear la lista de elementos que lo componen:
if(ui->comboType1->currentIndex() == 0)
{
QAbstractItemModel *model = ui->treeView->model();
for (int i = 0; i < model->rowCount(); i++)
{
// Obtiene los datos de la primera columna
QString elementCode = model->index(i, 0).data().toString();
// Verifica si los datos son válidos
if (elementCode.isEmpty())
continue;
qry.prepare(ElementComp);
qry.bindValue(":CODE", ui->editCode->text());
qry.bindValue(":ELEMENT_CODE", elementCode);
qry.bindValue(":ELEMENT_AMOUNT", model->index(i, 2).data().toDouble());
if(!qry.exec())
{
// barrar lo creado: eliminar las composiciones ya insertadas para este producto
if (!insertedElementCodes.isEmpty())
{
QSqlQuery qryDel = QSqlQuery(dApp->Enterprise());
qryDel.prepare(QString("DELETE FROM ELEMENTCOMPOSITION WHERE CODE = :CODE AND ELEMENT_CODE IN (%1)").arg(QString(insertedElementCodes.size(), '?').replace('?', ":ELEMENT_CODE")));
qryDel.bindValue(":CODE", ui->editCode->text());
for (int j = 0; j < insertedElementCodes.size(); ++j)
{
qryDel.bindValue(QString(":ELEMENT_CODE%1").arg(j), insertedElementCodes.at(j));
}
qryDel.exec();
}
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
dApp->Enterprise().close();
return;
}}
}
}
// 2. Crear el elemento principal
qry.prepare(Element);
qry.bindValue(":CODE", ui->editCode->text());
qry.bindValue(":TYPE1", ui->comboType1->currentIndex());
qry.bindValue(":TYPE2", ui->comboType2->currentIndex());
qry.bindValue(":TITLE", ui->editTitle->text());
qry.bindValue(":DESCRIPTION", ui->editDescription->toHtml());
//qry.bindValue(":FAMILY_ID", ui->editCode->text());
qry.bindValue(":UNIT_ID", ui->comboUnit->currentText());
qry.bindValue(":DATE_UPDATE", ui->editUpdateDate->date());
qry.bindValue(":REAL_PRICE", ui->editPVP->value());
qry.bindValue(":DISCOUNT", ui->editDiscount->value());
qry.bindValue(":PURCHASE_PRICE", ui->editPC->value());
qry.bindValue(":BENEFIT", ui->editMargin->value());
qry.bindValue(":TAX", ui->comboIVA->currentText().replace("%", ""));
qry.bindValue(":SALE_PRICE", ui->editPV->text());
//qry.bindValue(":BARCODE", ui->edit->text());
//qry.bindValue(":IMAGE", ui->editCode->text());
qry.bindValue(":STATE", ui->checkState->isChecked());
//qry.bindValue(":MANUFACTURER", ui->editCode->text());
//qry.bindValue(":GAMMA", ui->editCode->text());
qry.bindValue(":WEIGHT", ui->editWeight->text());
qry.bindValue(":HEIGHT", ui->editHeight->text());
qry.bindValue(":WIDTH", ui->editWidth->text());
qry.bindValue(":LENGHT", ui->editLength->text());
if(!qry.exec())
{
//goto error;
}
setWindowTitle(mDocumentID);
QTabWidget * prt = static_cast<QTabWidget*>(parent()->parent());
prt->setTabText(prt->currentIndex(), ui->editCode->text() + " - " + ui->editTitle->text());
dApp->Enterprise().close();
setEditMode();
return;
error:
dApp->Enterprise().close();
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
}
void formProduct::on_buttonSave_released()
{
// Salvar
save();
}
void formProduct::on_editPVIVA_valueChanged(const QString &arg1)
{
ui->editUpdateDate->setDate(QDate::currentDate());
}
void formProduct::on_ModelSetData(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
Q_UNUSED(bottomRight);
if(topLeft.column() == 0)
{
InsertElement(topLeft.data(roles.first()).toString(), topLeft);
}
else if(topLeft.column() == 2)
{
QAbstractItemModel /*TreeModelComposeElement*/ *aModel = ui->treeView->model();
double pt = 0;
for(int i = 0; i < aModel->rowCount(); i++)
{
QModelIndex idx = aModel->index(i, 6);
pt += idx.data().toDouble();
}
ui->editPC->setValue(pt);
}
}
void formProduct::setLineType(QString type, QModelIndex index)
{
setCellText(type, index, 7);
}
void formProduct::setCellText(QString val, QModelIndex index, int col)
{
//QModelIndex selindex = ui->treeView->selectionModel()->currentIndex();
QAbstractItemModel *treemodel = ui->treeView->model();
QModelIndex child = treemodel->index(index.row(), col, index.parent().isValid() ? index.parent() : QModelIndex());
treemodel->setData(child, QVariant(val), Qt::EditRole);
}
bool formProduct::InsertElement(QString ID, QModelIndex index)
{
if (ID.isEmpty())
return false;
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
if (qry.exec(QString("SELECT * FROM ELEMENT WHERE CODE = '%1';").arg(ID)))
{
qry.first();
setCellText(qry.value(qry.record().indexOf("TITLE")).toString(), index, 1); // TITLE
setCellText(qry.value(qry.record().indexOf("UNIT_ID")).toString(), index, 4); // UNIT ----QSqlQuery::value: not positioned on a valid record
/*
if (qry.value(qry.record().indexOf("TYPE")).toInt() == 0)
{
on_buttonInsertChild_released();
QSqlQuery comp = QSqlQuery(dApp->Enterprise());
if (comp.exec(QString("SELECT * FROM ELEMENTCOMPOSITION WHERE CODE = '%1';").arg(ID)))
{
while (comp.next())
{
on_buttonInsertRow_released();
InsertElement(comp.value(1).toString());
setCellText(4, comp.value(comp.record().indexOf("ELEMENT_AMOUNT")).toString()); //AMOUNT
}
}
}
else*/
{
setCellText(qry.value(qry.record().indexOf("PURCHASE_PRICE")).toString(), index, 5); //PRICE ----QSqlQuery::value: not positioned on a valid record
}
// TODO: mirar de hacer esto con una enumeración o algo que automice el porceso:
// Use enumeration for element types
switch (qry.value(qry.record().indexOf("TYPE1")).toInt())
{
case ElementType::Composed:
setLineType("CO", index); // type
break;
case ElementType::Material:
setLineType("MT", index); // type
break;
case ElementType::ManPower:
setLineType("MO", index); // type
break;
case ElementType::Machinery:
setLineType("MQ", index); // type
break;
case ElementType::Subcontracted:
setLineType("SC", index); // type
break;
case ElementType::Other:
setLineType("OT", index); // type
break;
default:
setLineType("UNKNOWN", index); // type
break;
}
}
else
{
qDebug() << qry.lastError().text();
}
dApp->Enterprise().close();
return false;
}
void formProduct::on_comboType2_currentIndexChanged(int index)
{
if(index == 0)
setComposeElement(true);
else
setComposeElement(false);
}
void formProduct::setComposeElement(bool val)
{
ui->editPVP->setEnabled(!val);
ui->editDiscount->setEnabled(!val);
ui->editPC->setReadOnly(val);
ui->groupBox_6->setVisible(!val);
//ui->tabCompose->setVisible(val);
ui->comboType1->setEnabled(!val);
//ui->comboType2->setEnabled(!val);
}
@@ -3,7 +3,6 @@
#include <QWidget>
#include "formbase.h"
#include "../src/elementtype.h"
namespace Ui
{
-1533
View File
File diff suppressed because it is too large Load Diff
-249
View File
@@ -1,249 +0,0 @@
#include "formthird.h"
#include "ui_formthird.h"
#include "mapplication.h"
#include "formbase.h"
#include <QFileDialog>
#include <QtSql>
formThird::formThird(QString aID, int aEditMode, QWidget *parent) :
formBase(aID, aEditMode, parent),
ui(new Ui::formThird),
rowid(-1)
{
ui->setupUi(this);
ui->tabClient->setVisible(false);
ui->tabSupplier->setVisible(false);
ui->editDischargeDate->setDate(QDate::currentDate());
ui->editUpdateDate->setDate(QDate::currentDate());
connect(ui->Logo, &AvatarWidget::addClicked, this, &formThird::LoadLogo);
//connect(ui->Logo, &AvatarWidget::clicked, this, &formThird::LoadLogo);
mEditMode = false;
}
formThird::~formThird()
{
delete ui;
}
void formThird::openDocument(QString id)
{
mEditMode = true;
//ui->editCode->setText(id);
//ui->editCode->setReadOnly(true);
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
QString command = QString("SELECT * FROM THIRD WHERE ID = '%1';").arg(id);
if (qry.exec(command))
{
qry.first();
ui->editName->setText(qry.value(qry.record().indexOf("NAME")).toString());
ui->editNickname->setText(qry.value(qry.record().indexOf("NICKNAME")).toString());
ui->editCIF->setText(qry.value(qry.record().indexOf("CIF")).toString());
ui->editIntraCode->setText(qry.value(qry.record().indexOf("INTRA_FC")).toString());
ui->comboState->setCurrentIndex(qry.value(qry.record().indexOf("STATE")).toInt());
ui->comboClient->setCurrentIndex(qry.value(qry.record().indexOf("CLIENT_STATE")).toInt());
ui->comboClient->setCurrentIndex(qry.value(qry.record().indexOf("SUPPLIER_STATE")).toInt());
ui->editClientCode->setText(qry.value(qry.record().indexOf("CLIENT_CODE")).toString());
ui->editSupplierCode->setText(qry.value(qry.record().indexOf("SUPPLIER_CODE")).toString());
ui->editAddress->setPlainText(qry.value(qry.record().indexOf("ADDRESS")).toString());
ui->editCP->setText(qry.value(qry.record().indexOf("POSTCODE")).toString());
ui->editCity->setText(qry.value(qry.record().indexOf("CITY")).toString());
ui->editProvince->setText(qry.value(qry.record().indexOf("PROVINCE")).toString());
ui->comboCountry->setCurrentText(qry.value(qry.record().indexOf("COUNTRY_ID")).toString());
ui->editPhone->setText(qry.value(qry.record().indexOf("PHONE")).toString());
ui->editFax->setText(qry.value(qry.record().indexOf("FAX")).toString());
ui->editMobile->setText(qry.value(qry.record().indexOf("MOBILE")).toString());
ui->editEmail->setText(qry.value(qry.record().indexOf("EMAIL")).toString());
ui->editWebside->setText(qry.value(qry.record().indexOf("WEBSIDE")).toString());
ui->editPublicNotes->setHtml(qry.value(qry.record().indexOf("NOTE_PUBLIC")).toString());
ui->editPrivateNotes->setHtml(qry.value(qry.record().indexOf("NOTE_PRIVATE")).toString());
ui->editDischargeDate->setDate(qry.value(qry.record().indexOf("CREATEDAT")).toDate());
ui->editUpdateDate->setDate(qry.value(qry.record().indexOf("UPDATEDAT")).toDate());
}
else
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
}
dApp->Enterprise().close();
}
void formThird::closeDocument()
{
close();
qDebug() << " Terceros: closeDocument";
}
void formThird::on_cbClient_currentIndexChanged(int index)
{
if(index == 0)
ui->tabClient->setVisible(false);
else
ui->tabClient->setVisible(true);
}
void formThird::on_cbSupplier_currentIndexChanged(int index)
{
if(index == 0)
ui->tabSupplier->setVisible(false);
else
ui->tabSupplier->setVisible(true);
}
void formThird::on_buttonSave_released()
{
save();
}
void formThird::LoadLogo()
{
QString imageFile = QFileDialog::getOpenFileName(this,
tr("Elige una imagen"),
"",
tr("Todas las imagenes(*.png *.jpg *.gif *.bmp)"));
/*
if(imageFile.isEmpty())
return;
imageProfile = ImageCropperDialog::getCroppedImage(imageFile, 600, 400, CropperShape::SQUARE);
if (imageProfile.isNull())
return;
ui->profilePicture->setAvatarPixmap(imageProfile);
*/
ui->Logo->setAvatarPath(imageFile);
}
void formThird::save()
{
QString command;
if (mEditMode)
command = "UPDATE THIRD SET "
"FORM = :FORM, CIF = :CIF, NAME = :NAME, NICKNAME = :NICKNAME, FAMILY = :FAMILY, "
"INTRA_FC = :INTRA_FC, STATE = :STATE, CLIENT_STATE = :CLIENT_STATE, CLIENT_CODE = :CLIENT_CODE, "
"CLIENT_ACCOUNT = :CLIENT_ACCOUNT, SUPPLIER_STATE = :SUPPLIER_STATE, SUPPLIER_CODE = :SUPLLIR_CODE, "
"SUPPLIER_ACCOUNT = :SUPPLIER_ACCOUNT, ADDRESS = :ADDRESS, POSTCODE = :POSTCODE, CITY = :CITY, "
"PROVINCE = :PROVINCE, COUNTRY_ID = :COUNTRY_ID, PHONE = :PHONE, FAX = :FAX, "
"EMAIL = :EMAIL, WEBSIDE = :WEBSIDE, PAYMENT_METHOD = :PAYMENT_METHOD, PAYMENT_TYPE = :PAYMENT_TYPE, "
"LOGO = :LOGO, NOTE_PUBLIC = :NOTE_PUBLIC, NOTE_PRIVATE = :NOTE_PRIVATE, UPDATEDAT = :UPDATEDAT, "
"CREATEDAT = :CREATEDAT, CREATEDBY = :CREATEBY "
"WHERE CIF = '" + ui->editCIF->text() +
"';";
else
command = "INSERT INTO THIRD ("
"FORM, CIF, NAME, NICKNAME, FAMILY, INTRA_FC, STATE, CLIENT_STATE, CLIENT_CODE, "
"CLIENT_ACCOUNT, SUPPLIER_STATE, SUPPLIER_CODE, SUPPLIER_ACCOUNT, ADDRESS, "
"POSTCODE, CITY, PROVINCE, COUNTRY_ID, PHONE, FAX, EMAIL, WEBSIDE, "
"PAYMENT_METHOD, PAYMENT_TYPE, LOGO, NOTE_PUBLIC, NOTE_PRIVATE, UPDATEDAT, "
"CREATEDAT, CREATEDBY"
") VALUES ("
":FORM, :CIF, :NAME, :NICKNAME, :FAMILY, :INTRA_FC, :STATE, :CLIENT_STATE, :CLIENT_CODE, "
":CLIENT_ACCOUNT, :SUPPLIER_STATE, :SUPPLIER_CODE, :SUPPLIER_ACCOUNT, :ADDRESS, "
":POSTCODE, :CITY, :PROVINCE, :COUNTRY_ID, :PHONE, :FAX, :EMAIL, :WEBSIDE, "
":PAYMENT_METHOD, :PAYMENT_TYPE, :LOGO, :NOTE_PUBLIC, :NOTE_PRIVATE, :UPDATEDAT, "
":CREATEDAT, :CREATEDBY"
");";
qDebug() << command;
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
qry.prepare(command);
//qry.bindValue(":FORM", );
qry.bindValue(":CIF", ui->editCIF->text());
qry.bindValue(":NAME", ui->editName->text());
qry.bindValue(":NICKNAME", ui->editNickname->text());
//qry.bindValue(":FAMILY", );
qry.bindValue(":INTRA_FC", ui->editIntraCode->text());
qry.bindValue(":STATE", ui->comboState->currentIndex());
qry.bindValue(":CLIENT_STATE", ui->comboClient->currentIndex());
qry.bindValue(":CLIENT_CODE", ui->editClientCode->text());
qry.bindValue(":CLIENT_ACCOUNT", ui->editAccountClient->text());
qry.bindValue(":SUPPLIER_STATE", ui->comboSupplier->currentIndex());
qry.bindValue(":SUPPLIER_CODE", ui->editSupplierCode->text());
qry.bindValue(":SUPPLIER_ACCOUNT", ui->editAccountSupplier->text());
qry.bindValue(":ADDRESS", ui->editAddress->toPlainText());
qry.bindValue(":POSTCODE", ui->editCP->text());
qry.bindValue(":CITY", ui->editCity->text());
qry.bindValue(":PROVINCE", ui->editProvince->text());
qry.bindValue(":COUNTRY_ID", ui->comboCountry->currentText());
//qry.bindValue(":COUNTRY", ui->editIntraCode->text());
qry.bindValue(":PHONE", ui->editPhone->text());
qry.bindValue(":FAX", ui->editFax->text());
qry.bindValue(":MOBILE", ui->editMobile->text());
qry.bindValue(":EMAIL", ui->editEmail->text());
qry.bindValue(":WEBSIDE", ui->editWebside->text());
//qry.bindValue(":PAYMENT_METHOD", ui->editPhone->text());
//qry.bindValue(":PAYMENT_TYPE", ui->editFax->text());
//qry.bindValue(":LOGO", ui->editMobile->text());
qry.bindValue(":NOTE_PUBLIC", ui->editPublicNotes->toHtml());
qry.bindValue(":NOTE_PRIVATE", ui->editPrivateNotes->toHtml());
qry.bindValue(":UPDATEDAT", ui->editUpdateDate->date());
qry.bindValue(":CREATEDAT", ui->editDischargeDate->date());
//qry.bindValue(":CREATEDBY", ui->editWebside->text());
if (!qry.exec())
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
}
else
{
setEditMode();
}
dApp->Enterprise().close();
}
void formThird::setEditMode()
{
mEditMode = true;
ui->editDischargeDate->setReadOnly(true);
}
void formThird::on_editName_textChanged(const QString &arg1)
{
mNeedSave = true;
}
void formThird::on_comboClient_currentIndexChanged(int index)
{
/*
// Ocultar pestaña
int indexToHide = 2;
QWidget *tab = ui->tabWidget->widget(indexToHide);
hiddenTabs[indexToHide] = tab; // Guarda la pestaña en un mapa
ui->tabWidget->removeTab(indexToHide);
// Mostrar pestaña
int indexToShow = 2;
if (hiddenTabs.contains(indexToShow)) {
ui->tabWidget->insertTab(indexToShow, hiddenTabs[indexToShow]);
hiddenTabs.remove(indexToShow);
}
*/
}
-46
View File
@@ -1,46 +0,0 @@
#ifndef FORMTHIRD_H
#define FORMTHIRD_H
#include <QWidget>
#include "formbase.h"
namespace Ui {
class formThird;
}
class formThird : public formBase
{
Q_OBJECT
public:
//explicit formThird(QWidget *parent = 0);
explicit formThird(QString aID = "", int aEditMode = 0, QWidget *parent = nullptr);
~formThird();
void newDocument() override {}
void openDocument(QString id) override;
void closeDocument() override;
void save() override;
bool needsave() override { return mNeedSave; }
void setEditMode(bool aMode) override {}
private slots:
void on_cbClient_currentIndexChanged(int index);
void on_cbSupplier_currentIndexChanged(int index);
void on_buttonSave_released();
void on_editName_textChanged(const QString &arg1);
void on_comboClient_currentIndexChanged(int index);
private:
Ui::formThird *ui;
int rowid;
QMap<int, QWidget*> hiddenTabs;
void LoadLogo();
void setEditMode();
};
#endif // FORMTHIRD_H
-1192
View File
File diff suppressed because it is too large Load Diff
-157
View File
@@ -1,157 +0,0 @@
#include "formthirdlist.h"
#include "ui_formthirdlist.h"
#include "mapplication.h"
#include "mainwindow.h"
#include "formthird.h"
#include "utils/filtertableheader.h"
#include <QSqlQueryModel>
#include <QResizeEvent>
formThirdList::formThirdList(QWidget *parent) :
QWidget(parent),
ui(new Ui::formThirdList)
{
ui->setupUi(this);
//QStringList header;
//header << tr("Código") << tr("Título") << tr("Tipo") << tr("Precio de Compra");
mModel = new QSqlQueryModel(this);
//ui->tableView->setModel(mModel);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(mModel);
ui->tableView->setModel(proxyModel);
// Set up filter row
m_tableHeader = new FilterTableHeader(ui->tableView);
ui->tableView->setHorizontalHeader(m_tableHeader);
m_tableHeader->setFilter(1, "");
m_tableHeader->setFocusColumn(1);
// Disconnect clicking in header to select column, since we will use it for sorting.
// Note that, in order to work, this cannot be converted to the standard C++11 format.
disconnect(m_tableHeader, SIGNAL(sectionPressed(int)),this, SLOT(selectColumn(int)));
//connect(m_frozen_table_view->filterHeader(), &FilterTableHeader::filterChanged, filterHeader(), &FilterTableHeader::filterChanged);
connect(m_tableHeader, &FilterTableHeader::filterChanged, this, &formThirdList::applyFilter);
updateList();
ui->tableView->setColumnHidden(0, true);
m_tableHeader->generateFilters(mModel->columnCount(), 0);
}
formThirdList::~formThirdList()
{
delete ui;
}
void formThirdList::updateList()
{
dApp->Enterprise().open();
mModel->setQuery("SELECT ID, CIF, NAME, NICKNAME, ADDRESS, CITY, PHONE, MOBILE, FAX, EMAIL FROM THIRD ORDER BY ID ASC",
dApp->Enterprise());
dApp->Enterprise().close();
}
void formThirdList::applyFilter()
{
dApp->Enterprise().open();
QString query = "SELECT ID, CIF, NAME, NICKNAME, ADDRESS, CITY, PHONE, MOBILE, FAX, EMAIL FROM THIRD";
QString filters = "";
for (int i = 1; i < mModel->columnCount(); i++)
{
if(m_tableHeader->filterValue(i).isEmpty())
continue;
if(!filters.isEmpty())
filters += " AND ";
//WHERE NAME LIKE '%ter%'
filters += mModel->headerData(i, Qt::Horizontal).toString() + " LIKE '%" + m_tableHeader->filterValue(i) + "%'";
}
if (!filters.isEmpty())
query += " WHERE " + filters;
//query += " ORDER BY ID ASC";
mModel->setQuery(query,
dApp->Enterprise());
if (mModel->lastError().isValid())
qDebug() << mModel->lastError();
dApp->Enterprise().close();
}
void formThirdList::on_buttonNew_released()
{
formThird *form = dApp->mainWindow()->createFormThird();
form->show();
}
void formThirdList::on_buttonEdit_released()
{
openDocument(ui->tableView->currentIndex());
}
void formThirdList::on_buttonClone_released()
{
}
void formThirdList::on_buttonDelete_released()
{
QModelIndex index = ui->tableView->currentIndex();
QAbstractItemModel *model = const_cast<QAbstractItemModel*>(index.model()); // Obtén el modelo asociado
QModelIndex parentIndex = index.parent(); // Obtén el índice del padre
if (index.column() != 0)
index = model->index(index.row(), 0, parentIndex); // Obtén el índice del hijo
QString ID = index.data().toString();
QModelIndex childIndex = model->index(index.row(), 2, parentIndex); // Obtén el índice del hijo
int type = childIndex.data().toInt(); // Accede al dato
dApp->Enterprise().open();
QSqlQuery qry = QSqlQuery(dApp->Enterprise());
if(!qry.exec(QString("DELETE FROM THIRD WHERE CODE = '%1';").arg(ID)))
{
qDebug() << "Error ejecutando el query: " << qry.lastError().text() << "\n";
}
updateList();
dApp->Enterprise().close();
}
void formThirdList::on_buttonUpdate_released()
{
updateList();
}
void formThirdList::on_tableView_doubleClicked(const QModelIndex &index)
{
openDocument(index);
}
void formThirdList::openDocument(QModelIndex index)
{
formThird *form = dApp->mainWindow()->createFormThird();
form->openDocument(index.model()->index(index.row(), 0).data().toString());
form->show();
}
void formThirdList::resizeEvent(QResizeEvent *event)
{
QStringList texts = { tr("Nuevo"), tr("Editar"), tr("Clonar"), tr("Borrar"), tr("Actualizar") };
QList<QPushButton*> buttons = { ui->buttonNew, ui->buttonEdit, ui->buttonClone, ui->buttonDelete, ui->buttonUpdate };
for (int i = 0; i < buttons.size(); ++i) {
buttons[i]->setText(event->size().width() > 390 ? texts[i] : "");
}
}
-45
View File
@@ -1,45 +0,0 @@
#ifndef FORMTHIRDLIST_H
#define FORMTHIRDLIST_H
#include <QWidget>
class QSqlQueryModel;
class FilterTableHeader;
namespace Ui
{
class formThirdList;
}
class formThirdList : public QWidget
{
Q_OBJECT
public:
explicit formThirdList(QWidget *parent = 0);
~formThirdList();
private slots:
void on_buttonNew_released();
void on_buttonEdit_released();
void on_buttonClone_released();
void on_buttonDelete_released();
void on_buttonUpdate_released();
void on_tableView_doubleClicked(const QModelIndex &index);
private:
Ui::formThirdList *ui;
QSqlQueryModel *mModel;
FilterTableHeader *m_tableHeader;
void updateList();
void openDocument(QModelIndex index);
void applyFilter();
protected:
void resizeEvent(QResizeEvent *event) override;
};
#endif // FORMTHIRDLIST_H
-130
View File
@@ -1,130 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>formThirdList</class>
<widget class="QWidget" name="formThirdList">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>285</height>
</rect>
</property>
<property name="windowTitle">
<string>Terceros</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTableView" name="tableView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_2">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="buttonNew">
<property name="text">
<string>Nuevo</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/add-file.svg</normaloff>:/resources/icons/add-file.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonEdit">
<property name="text">
<string>Editar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/pencil.svg</normaloff>:/resources/icons/pencil.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonClone">
<property name="text">
<string>Duplicar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/copy.svg</normaloff>:/resources/icons/copy.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonDelete">
<property name="text">
<string>Borrar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/delete.svg</normaloff>:/resources/icons/delete.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonUpdate">
<property name="text">
<string>Actualizar</string>
</property>
<property name="icon">
<iconset resource="../editabletreemodel.qrc">
<normaloff>:/resources/icons/recycle.svg</normaloff>:/resources/icons/recycle.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../editabletreemodel.qrc"/>
</resources>
<connections/>
</ui>
-43
View File
@@ -1,43 +0,0 @@
#include "qlistmodel.h"
#include <QIcon>
QListModel::QListModel(QObject *parent) :
QSqlQueryModel(parent)
{
}
QVariant QListModel::data(const QModelIndex &item, int role) const
{
if (!item.isValid())
return QVariant();
if(role == Qt::DecorationRole)
{
if(item.column() == 0)
{
if(item.data(13).toString() == "0") // Compuesto
{
return QIcon(":/resources/icons/box.svg");
}
else if(item.data(13).toString() == "1") // Materiales
{
return QIcon(":/resources/icons/blocks.svg");
}
else if(item.data(13).toString() == "2") // Mano de obra
{
return QIcon(":/resources/icons/helmet.svg");
}
else if(item.data(13).toString() == "3") // Maquinaria
{
return QIcon(":/resources/icons/gear.svg");
}
else if(item.data(13).toString() == "4") // Maquinaria
{
return QIcon(":/resources/icons/percentage.svg");
}
}
}
//return item.data(role);
}
-16
View File
@@ -1,16 +0,0 @@
#ifndef QLISTMODEL_H
#define QLISTMODEL_H
#include <QSqlQueryModel>
class QListModel : public QSqlQueryModel
{
public:
QListModel(QObject *parent = Q_NULLPTR);
QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override;
};
#endif // QLISTMODEL_H