Permalink
Browse files

Refaktoryzacja

Przetłumaczono klasę Kategorie na angielski. Teraz to Categories.
Naniesiono poprawki proporcjonalne i kosmetyczne w oknie testu.
Usunięto zbędne pliki.

Poprawa widoczności, czytelności kodu.

Usunięto 9 zmiennych pomoczniczych w klasach. Zmniejszono zakres
widoczności zmiennej pomocniczej n przy zliczaniu liczby elementów dla
siatki kategorii.
  • Loading branch information...
Barto-Paja committed May 10, 2017
1 parent 3ae0d95 commit 36c35f58294a4f894916842797db92f767cfa1ff
12 SHS.pro
@@ -15,26 +15,26 @@ TEMPLATE = app

SOURCES += main.cpp\
mainwindow.cpp \
kategorie.cpp \
album.cpp \
myqlabel.cpp \
item.cpp \
dialog.cpp \
dialogt.cpp
dialogt.cpp \
categories.cpp

HEADERS += mainwindow.h \
kategorie.h \
album.h \
myqlabel.h \
item.h \
dialog.h \
dialogt.h
dialogt.h \
categories.h

FORMS += mainwindow.ui \
kategorie.ui \
album.ui \
dialog.ui \
dialogt.ui
dialogt.ui \
categories.ui

RESOURCES += \
zasoby.qrc
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.1.0, 2017-04-17T14:06:58. -->
<!-- Written by QtCreator 4.1.0, 2017-05-10T22:42:38. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@@ -7,23 +7,21 @@ Album::Album(QWidget *parent) :
{
ui->setupUi(this);
form = new Dialog(this);
connect(this,SIGNAL(info(QPixmap,QString,QString)),form,SLOT(odbior(QPixmap,QString,QString)));
connect(this,SIGNAL(item(QPixmap,QString,QString)),form,SLOT(SetItem(QPixmap,QString,QString)));
}

Album::~Album()
{
delete ui;
}

void Album::odbiornik(QString n1)
void Album::Reception(QString s_iteminfo)
{
basa.clear();
ns=n1;
if(n1!=0)
v_categoryItems.clear();
if(s_iteminfo!=0)
{
ns=n1;
Item::import(basa,ns);
spawanie(ns);
Item::Import(v_categoryItems,s_iteminfo);
SetupGui(s_iteminfo);
}
else
{
@@ -35,32 +33,32 @@ void Album::odbiornik(QString n1)

}

void Album::Pressed(int t)
void Album::Pressed(int index)
{
QPixmap img = basa[t].SeeImg();
QString name = basa[t].SeeName();
QString sound = basa[t].SeeWsk();
QPixmap img = v_categoryItems[index].SeeImg();
QString name = v_categoryItems[index].SeeName();
QString sound = v_categoryItems[index].SeePtr();

emit info(img,name,sound);
emit item(img,name,sound);

form->setModal(true);
form->exec();
}


void Album::spawanie(QString &f)
void Album::SetupGui(QString &f)
{
int n;
QFile p(f);
Item::ilewierszy(p,n=0);
Item::CountLines(p,n=0);
n=n/3;
for(int i=0; i<n; i++)
{
tab << new myQLabel(this);
tab.at(i)->SetRef(i);
tab.at(i)->setPixmap(basa[i].SeeImg().scaled(300,164,Qt::KeepAspectRatio));
tab.at(i)->setFrameStyle(3);
ui->gridLayout->addWidget(tab.at(i),(i/3),(i%3));
connect(tab.at(i),SIGNAL(Pressed(int)),this,SLOT(Pressed(int)));
l_myLabels << new myQLabel(this);
l_myLabels.at(i)->SetRef(i);
l_myLabels.at(i)->setPixmap(v_categoryItems[i].SeeImg().scaled(300,164,Qt::KeepAspectRatio));
l_myLabels.at(i)->setFrameStyle(3);
ui->gridLayout->addWidget(l_myLabels.at(i),(i/3),(i%3));
connect(l_myLabels.at(i),SIGNAL(Pressed(int)),this,SLOT(Pressed(int)));
}
}
13 album.h
@@ -2,7 +2,7 @@
#define ALBUM_H

#include <myqlabel.h>
#include <kategorie.h>
#include <categories.h>
#include <item.h>
#include <dialog.h>

@@ -23,21 +23,22 @@ class Album : public QDialog, private Item
public:
explicit Album(QWidget *parent = 0);
~Album();

QString ns;
QVector<Item> basa;
QList<myQLabel *> tab;
QVector<Item> v_categoryItems;
QList<myQLabel *> l_myLabels;

Dialog* form;
int n;

signals:
void info(QPixmap,QString,QString);
void item(QPixmap,QString,QString);
public slots:
void odbiornik(QString);
void Reception(QString);
void Pressed(int);

private:
void spawanie(QString &f);
void SetupGui(QString &f);
Ui::Album *ui;
};

@@ -0,0 +1,71 @@
#include "categories.h"
#include "ui_categories.h"

Categories::Categories(QWidget *parent) :
QDialog(parent),
ui(new Ui::Categories)
{
ui->setupUi(this);
form = new Album(this);
form2 = new DialogT(this);

SetupGui(v_items,t_setofcategory);
}

Categories::~Categories()
{
info = false;
delete ui;
}

void Categories::Pressed(int index)
{
emit send(v_items[index].SeePtr());

if(info==false)
{
form->setModal(true);
form->exec();
}
else
{
form2->setModal(true);
form2->exec();
}
}

void Categories::bInfo(bool b)
{
info = b;
}

void Categories::SetupGui(QVector<Item>& v_it, QString& file)
{
file = ":/txt/txt/zestawy.txt";

QFile f(file);
int n;

Item::Import(v_it,file);
Item::CountLines(f,n=0);

ui->gridLayout->setSpacing(10);
n=n/3;

for(int i=0;i<n;i++)
{
l_myLabels << new myQLabel(this);
l_myLabels.at(i)->SetRef(i);
l_myLabels.at(i)->setPixmap(v_it[i].SeeImg().scaled(300,164,Qt::KeepAspectRatio));
l_myLabels.at(i)->setFrameStyle(3);
}

for(int i=0;i<n;i++)
{
ui->gridLayout->addWidget(l_myLabels.at(i),(i/3),(i%3));
connect(l_myLabels.at(i),SIGNAL(Pressed(int)),this,SLOT(Pressed(int)));
}

connect(this,SIGNAL(send(QString)),form,SLOT(Reception(QString)));
connect(this,SIGNAL(send(QString)),form2,SLOT(questsource(QString)));
}
@@ -0,0 +1,46 @@
#ifndef CATEGORIES_H
#define CATEGORIES_H

#include <item.h>
#include <myqlabel.h>
#include <album.h>
#include <dialogt.h>

#include <QDialog>
#include <QVector>
#include <QList>

namespace Ui {
class Categories;
}
class Album;
class DialogT;
class Categories : public QDialog, private Item
{
Q_OBJECT

public:
explicit Categories(QWidget *parent = 0);
~Categories();

Album* form;
DialogT* form2;
QString t_setofcategory;

QVector<Item> v_items;
QList<myQLabel *> l_myLabels;

bool info = false;

signals:
void send(QString);
private slots:
void Pressed(int);
void bInfo(bool);

private:
Ui::Categories *ui;
void SetupGui(QVector<Item>& v_it, QString& file);
};

#endif // CATEGORIES_H
@@ -1,10 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Kategorie</class>
<widget class="QDialog" name="Kategorie">
<property name="windowModality">
<enum>Qt::NonModal</enum>
</property>
<class>Categories</class>
<widget class="QDialog" name="Categories">
<property name="geometry">
<rect>
<x>0</x>
@@ -14,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Kategorie</string>
</property>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
@@ -19,16 +19,13 @@ Dialog::~Dialog()
{
delete ui;
}
void Dialog::odbior(QPixmap n1, QString n2, QString n3)
void Dialog::SetItem(QPixmap image, QString name, QString sound)
{
ns1 = n1; // img
ns2 = n2; // name
ns3 = n3; // sound
Dialog::windowTitle() = name;


ui->label->setPixmap(ns1.scaled(760,430,Qt::KeepAspectRatio));
player->setMedia(QUrl::fromLocalFile(ns3));
ui->label_2->setText(ns2);
ui->label->setPixmap(image.scaled(760,430,Qt::KeepAspectRatio));
player->setMedia(QUrl::fromLocalFile(sound));
ui->label_2->setText(name);
}

void Dialog::Pressed(int)
@@ -21,13 +21,10 @@ class Dialog : public QDialog
explicit Dialog(QWidget *parent = 0);
~Dialog();

QPixmap ns1;
QString ns2,ns3;

void closeEvent ( QCloseEvent * event );

public slots:
void odbior(QPixmap,QString,QString);
void SetItem(QPixmap,QString,QString);
void Pressed(int);
private slots:
void statusChanged(QMediaPlayer::MediaStatus); // obsługa zmian statusów
@@ -17,9 +17,9 @@
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>761</width>
<height>431</height>
<y>20</y>
<width>760</width>
<height>430</height>
</rect>
</property>
<property name="frameShape">
@@ -35,10 +35,10 @@
<widget class="myQLabel" name="label_2">
<property name="geometry">
<rect>
<x>270</x>
<x>200</x>
<y>470</y>
<width>371</width>
<height>71</height>
<width>400</width>
<height>70</height>
</rect>
</property>
<property name="font">
Oops, something went wrong.

0 comments on commit 36c35f5

Please sign in to comment.