primer dise?o del di?logo de informaci?n de c?mics

arreglado bug que al cambiar entre bibliotecas provocaba un cierre por acceso de memoria inv?lido

la modificaci?n en treemodel no tiene nada que ver con el bug, pero es m?s seguro as?

faltan por encontrar los memory leaks
This commit is contained in:
Luis Ángel San Martín 2012-06-07 00:34:15 +02:00
parent c0b000bdda
commit 0e59d311d4
4 changed files with 320 additions and 97 deletions

View File

@ -78,7 +78,8 @@ TreeModel::TreeModel( QSqlQuery &sqlquery, QObject *parent)
//! [1]
TreeModel::~TreeModel()
{
delete rootItem;
if(rootItem != 0)
delete rootItem;
}
//! [1]

View File

@ -564,9 +564,12 @@ void LibraryWindow::loadLibrary(const QString & name)
{
index = 0;
sm->clear();
foldersView->setModel(NULL); //TODO comprobar pq no sirve con usar simplemente las señales beforeReset y reset
comicView->setModel(NULL);
dm->setupModelData(path);
foldersView->setModel(dm);
loadCovers(QModelIndex());
//includeComicsCheckBox->setCheckState(Qt::Unchecked);
@ -623,6 +626,7 @@ void LibraryWindow::loadCovers(const QModelIndex & mi)
TreeItem *item = static_cast<TreeItem*>(mi.internalPointer());
folderId = item->id;
}
comicView->setModel(NULL);
dmCV->setupModelData(folderId,dm->getDatabase());
comicView->setModel(dmCV);
//TODO automatizar (valorar si se deja al modelo)

View File

@ -3,51 +3,230 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QSizePolicy>
#include <QFormLayout>
#include <QCheckBox>
#include <QLineEdit>
#include <QTabWidget>
#include <QPlainTextEdit>
PropertiesDialog::PropertiesDialog(QWidget * parent)
:QDialog(parent)
{
QHBoxLayout * l = new QHBoxLayout();
sa = new QScrollArea();
_cover = new QLabel();
_cover->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
_cover->setScaledContents(true);
_cover->setAlignment(Qt::AlignTop|Qt::AlignHCenter);
createCoverBox();
createGeneralInfoBox();
createAuthorsBox();
createPublishingBox();
createButtonBox();
createPlotBox();
sa->setWidget(_cover);
sa->setBackgroundRole(QPalette::Dark);
sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
sa->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
sa->setFrameStyle(QFrame::NoFrame);
sa->setAlignment(Qt::AlignCenter);
createTabBar();
QVBoxLayout * coverLayout = new QVBoxLayout();
coverLayout->addWidget(sa);
//coverLayout->addStretch();
mainLayout = new QGridLayout;
mainLayout->addWidget(coverBox,0,0);
mainLayout->addWidget(tabBar,0,1);
mainLayout->setColumnStretch(1,1);
/*mainLayout->addWidget(authorsBox,1,1);
mainLayout->addWidget(publishingBox,2,1);*/
mainLayout->addWidget(buttonBox,1,1,Qt::AlignBottom);
l->addLayout(coverLayout);
QVBoxLayout * info = new QVBoxLayout();
info->addWidget(_name = new QLabel("name"));
info->addWidget(_pages = new QLabel("pages"));
info->addWidget(_size = new QLabel("size"));
info->addStretch();
//coverLayout->setSizeConstraint(QLayout::SetMaximumSize);
l->addLayout(info);
l->addStretch();
//l->setSizeConstraint(QLayout::SetNoConstraint);
this->setLayout(l);
this->setLayout(mainLayout);
mainLayout->setSizeConstraint(QLayout::SetMinimumSize);
this->setWindowTitle(tr("Comic properties"));
int heightDesktopResolution = QApplication::desktop()->screenGeometry().height();
int widthDesktopResolution = QApplication::desktop()->screenGeometry().width();
int sHeight,sWidth;
sHeight = static_cast<int>(heightDesktopResolution*0.5);
sHeight = static_cast<int>(heightDesktopResolution*0.65);
sWidth = static_cast<int>(sHeight*1.4);
this->resize(sWidth,sHeight);
setCover(QPixmap(":/images/notCover.png"));
this->resize(sWidth,this->height());
this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2));
repaint();
}
void PropertiesDialog::createTabBar()
{
tabBar = new QTabWidget;
tabBar->addTab(generalInfoBox,tr("General info"));
tabBar->addTab(authorsBox,tr("Authors"));
tabBar->addTab(publishingBox,tr("Publishing"));
tabBar->addTab(plotBox,tr("Plot"));
}
void PropertiesDialog::createCoverBox()
{
coverBox = new QGroupBox(tr("Cover"));
sa = new QScrollArea();
cover = new QLabel();
cover->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
cover->setScaledContents(false);
cover->setAlignment(Qt::AlignTop|Qt::AlignHCenter);
/*sa->setWidget(cover);
sa->setBackgroundRole(QPalette::Dark);
sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
sa->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
sa->setFrameStyle(QFrame::NoFrame);
sa->setAlignment(Qt::AlignCenter);*/
QVBoxLayout * coverLayout = new QVBoxLayout();
coverLayout->addWidget(cover);
coverLayout->addWidget(new QLineEdit());
coverBox->setLayout(coverLayout);
}
QFrame * createLine()
{
QFrame * line = new QFrame();
line->setObjectName(QString::fromUtf8("line"));
//line->setGeometry(QRect(320, 150, 118, 3));
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
return line;
}
void PropertiesDialog::createGeneralInfoBox()
{
generalInfoBox = new QWidget;
QFormLayout *generalInfoLayout = new QFormLayout;
//generalInfoLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
generalInfoLayout->addRow(tr("Title:"), title = new QLineEdit());
QHBoxLayout * number = new QHBoxLayout;
number->addWidget(new QLineEdit());
number->addWidget(new QLabel("Bis:"));
number->addWidget(new QCheckBox());
number->addWidget(new QLabel("of:"));
number->addWidget(new QLineEdit());
number->addStretch(1);
/*generalInfoLayout->addRow(tr("&Issue number:"), );
generalInfoLayout->addRow(tr("&Bis:"), );*/
generalInfoLayout->addRow(tr("Issue number:"), number);
generalInfoLayout->addRow(tr("&Volume:"), pages = new QLineEdit());
QHBoxLayout * arc = new QHBoxLayout;
arc->addWidget(new QLineEdit());
arc->addWidget(new QLabel("Arc number:"));
arc->addWidget(new QLineEdit());
arc->addWidget(new QLabel("of:"));
arc->addWidget(new QLineEdit());
arc->addStretch(1);
generalInfoLayout->addRow(tr("&Story arc:"), arc);
generalInfoLayout->addRow(tr("&Genere:"), new QLineEdit());
generalInfoLayout->addRow(tr("&Size:"), size = new QLabel("size"));
generalInfoBox->setLayout(generalInfoLayout);
}
void PropertiesDialog::createAuthorsBox()
{
authorsBox = new QWidget;
QVBoxLayout *authorsLayout = new QVBoxLayout;
//authorsLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
QHBoxLayout * h1 = new QHBoxLayout;
QVBoxLayout * vl1 = new QVBoxLayout;
QVBoxLayout * vr1 = new QVBoxLayout;
vl1->addWidget(new QLabel(tr("Writer(s):")));
vl1->addWidget(new QPlainTextEdit());
h1->addLayout(vl1);
vr1->addWidget(new QLabel(tr("Penciller(s):")));
vr1->addWidget(new QPlainTextEdit());
h1->addLayout(vr1);
//authorsLayout->addRow(tr("Writer(s):"), new QPlainTextEdit());
//authorsLayout->addRow(tr("Penciller(s):"), new QPlainTextEdit());
QHBoxLayout * h2 = new QHBoxLayout;
QVBoxLayout * vl2 = new QVBoxLayout;
QVBoxLayout * vr2 = new QVBoxLayout;
vl2->addWidget(new QLabel(tr("Inker(s):")));
vl2->addWidget(new QPlainTextEdit());
h2->addLayout(vl2);
vr2->addWidget(new QLabel(tr("Colorist(s):")));
vr2->addWidget(new QPlainTextEdit());
h2->addLayout(vr2);
//authorsLayout->addRow(tr("Inker(s):"), new QPlainTextEdit());
//authorsLayout->addRow(tr("Colorist(s):"), new QPlainTextEdit());
QHBoxLayout * h3 = new QHBoxLayout;
QVBoxLayout * vl3 = new QVBoxLayout;
QVBoxLayout * vr3 = new QVBoxLayout;
vl3->addWidget(new QLabel(tr("Letterer(es):")));
vl3->addWidget(new QPlainTextEdit());
h3->addLayout(vl3);
vr3->addWidget(new QLabel(tr("Cover Artist(s):")));
vr3->addWidget(new QPlainTextEdit());
h3->addLayout(vr3);
//authorsLayout->addRow(tr("Letterer(es):"), new QPlainTextEdit());
//authorsLayout->addRow(tr("Cover Artist(s):"), new QPlainTextEdit());
authorsLayout->addLayout(h1);
authorsLayout->addLayout(h2);
authorsLayout->addLayout(h3);
authorsLayout->addStretch(1);
authorsBox->setLayout(authorsLayout);
}
void PropertiesDialog::createPublishingBox()
{
publishingBox = new QWidget;
QFormLayout *publishingLayout = new QFormLayout;
publishingLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
publishingLayout->addRow(tr("Year:"), new QLineEdit());
publishingLayout->addRow(tr("Month:"), new QLineEdit());
publishingLayout->addRow(tr("Publisher:"), new QLineEdit());
publishingLayout->addRow(tr("Format:"), new QLineEdit());
publishingLayout->addRow(tr("Color/BW:"), new QLineEdit());
publishingLayout->addRow(tr("Age rating:"), new QLineEdit());
publishingBox->setLayout(publishingLayout);
}
void PropertiesDialog::createPlotBox()
{
plotBox = new QWidget;
QFormLayout *plotLayout = new QFormLayout;
plotLayout->setRowWrapPolicy(QFormLayout::WrapAllRows);
plotLayout->addRow(tr("Synopsis:"), new QPlainTextEdit());
plotLayout->addRow(tr("Characters:"), new QPlainTextEdit());
plotLayout->addRow(tr("Notes:"), new QPlainTextEdit());
plotBox->setLayout(plotLayout);
}
void PropertiesDialog::createButtonBox()
{
buttonBox = new QDialogButtonBox;
closeButton = buttonBox->addButton(QDialogButtonBox::Close);
saveButton = buttonBox->addButton(QDialogButtonBox::Save);
//rotateWidgetsButton = buttonBox->addButton(tr("Rotate &Widgets"),QDialogButtonBox::ActionRole);
//connect(rotateWidgetsButton, SIGNAL(clicked()), this, SLOT(rotateWidgets()));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
connect(saveButton, SIGNAL(clicked()), this, SLOT(save()));
}
void PropertiesDialog::setComics(QList<Comic> comics)
@ -55,47 +234,54 @@ void PropertiesDialog::setComics(QList<Comic> comics)
}
void PropertiesDialog::updateComics(QList<Comic> comics)
{
}
//Deprecated
void PropertiesDialog::setCover(const QPixmap & cover)
void PropertiesDialog::setCover(const QPixmap & coverImage)
{
_cover->setPixmap(cover);
float aspectRatio = (float)cover.width()/cover.height();
int heightDesktopResolution = QApplication::desktop()->screenGeometry().height();
int widthDesktopResolution = QApplication::desktop()->screenGeometry().width();
int sHeight,sWidth;
sHeight = static_cast<int>(heightDesktopResolution*0.5);
cover->setPixmap(coverImage.scaledToWidth(125,Qt::SmoothTransformation));
//cover->repaint();
if(aspectRatio<1)
{
sWidth = static_cast<int>(sHeight*1.4);
//this->resize(sWidth,sHeight);
this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2));
_cover->resize(static_cast<int>((sa->height())*aspectRatio),
(sa->height()));
}
else
{
sWidth = static_cast<int>(sHeight/1.16);
//this->resize(sWidth,sHeight);
this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2));
_cover->resize((width()-25),
static_cast<int>((width()-25)/aspectRatio));
}
//float aspectRatio = (float)coverImage.width()/coverImage.height();
//int heightDesktopResolution = QApplication::desktop()->screenGeometry().height();
//int widthDesktopResolution = QApplication::desktop()->screenGeometry().width();
//int sHeight,sWidth;
//sHeight = static_cast<int>(heightDesktopResolution*0.65);
//if(aspectRatio<1)
//{
// sWidth = static_cast<int>(sHeight*1.4);
// //this->resize(sWidth,sHeight);
// this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2));
// //sa->resize(sa->width(),sa->width()*1.333);
// /*cover->resize(static_cast<int>((sa->height())*aspectRatio),
// (sa->height()));*/
//}
//else
//{
// sWidth = static_cast<int>(sHeight/1.16);
// //this->resize(sWidth,sHeight);
// this->move(QPoint((widthDesktopResolution-sWidth)/2,((heightDesktopResolution-sHeight)-40)/2));
// cover->resize((width()-25),
// static_cast<int>((width()-25)/aspectRatio));
//}
}
void PropertiesDialog::setFilename(const QString & name)
void PropertiesDialog::setFilename(const QString & nameString)
{
_name->setText(tr("Name : ") + name);
title->setText(nameString);
}
void PropertiesDialog::setNumpages(int pages)
void PropertiesDialog::setNumpages(int pagesNum)
{
_pages->setText(tr("Number of pages : ") + QString::number(pages));
pages->setText(QString::number(pagesNum));
}
void PropertiesDialog::setSize(float size)
void PropertiesDialog::setSize(float sizeFloat)
{
_size->setText(tr("Size : ") + QString::number(size,'f',2) + " MB");
size->setText(QString::number(sizeFloat,'f',2) + " MB");
}

View File

@ -1,35 +1,67 @@
#ifndef __PROPERTIES_DIALOG_H
#define __PROPERTIES_DIALOG_H
#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>
#include "comic.h"
class PropertiesDialog : public QDialog
{
Q_OBJECT
private:
QLabel * _cover;
QLabel * _name;
QLabel * _pages;
QLabel * _size;
QScrollArea * sa;
public:
PropertiesDialog(QWidget * parent = 0);
public slots:
void setComics(QList<Comic> comics);
void updateComics(QList<Comic> comics);
//Deprecated
void setCover(const QPixmap & cover);
void setFilename(const QString & name);
void setNumpages(int pages);
void setSize(float size);
};
#endif
#ifndef __PROPERTIES_DIALOG_H
#define __PROPERTIES_DIALOG_H
#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>
#include <QGroupBox>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QTabWidget>
#include "comic.h"
class PropertiesDialog : public QDialog
{
Q_OBJECT
private:
QGridLayout * mainLayout;
QTabWidget * tabBar;
QGroupBox * coverBox;
QLabel * cover;
QScrollArea * sa;
QWidget * generalInfoBox;
QLineEdit * title;
QLineEdit * pages;
QLabel * size;
QWidget * authorsBox;
QWidget * publishingBox;
QWidget * plotBox;
QDialogButtonBox *buttonBox;
QPushButton *closeButton;
QPushButton *saveButton;
QPushButton *restoreButton; //??
void createTabBar();
void createCoverBox();
void createGeneralInfoBox();
void createAuthorsBox();
void createPublishingBox();
void createPlotBox();
void createButtonBox();
public:
PropertiesDialog(QWidget * parent = 0);
public slots:
void setComics(QList<Comic> comics);
void updateComics(QList<Comic> comics);
//Deprecated
void setCover(const QPixmap & cover);
void setFilename(const QString & name);
void setNumpages(int pages);
void setSize(float size);
};
#endif