Switched the method of how the Designer UI file is used in the LogView class to "The Single Inheritance Approach" (with "Using a Pointer Member Variable"). This is the method which Qt recommends for large projects.

This commit is contained in:
LoRd_MuldeR 2013-01-14 00:37:19 +01:00
parent 4a8dd85d7e
commit 21e1fd7945
3 changed files with 53 additions and 13 deletions

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 7
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 7
#define VER_LAMEXP_BUILD 1223
#define VER_LAMEXP_BUILD 1224
///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!)

View File

@ -21,29 +21,38 @@
#include "Dialog_LogView.h"
//UIC includes
#include "../tmp/UIC_LogViewDialog.h"
//Internal
#include "Global.h"
//Qt includes
#include <QClipboard>
#include <QFileDialog>
#include <QMimeData>
#include <QTimer>
LogViewDialog::LogViewDialog(QWidget *parent)
:
QDialog(parent)
QDialog(parent),
m_acceptIcon(new QIcon(":/icons/accept.png")),
m_oldIcon(new QIcon()),
ui(new Ui::LogViewDialog)
{
//Init the dialog, from the .ui file
setupUi(this);
ui->setupUi(this);
setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
//Translate
headerText->setText(QString("<b>%1</b><br>%2").arg(tr("Log File"), tr("The log file shows detailed information about the selected job.")));
ui->headerText->setText(QString("<b>%1</b><br>%2").arg(tr("Log File"), tr("The log file shows detailed information about the selected job.")));
//Clear
textEdit->clear();
ui->textEdit->clear();
//Enable buttons
connect(buttonCopy, SIGNAL(clicked()), this, SLOT(copyButtonClicked()));
connect(buttonSave, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
connect(ui->buttonCopy, SIGNAL(clicked()), this, SLOT(copyButtonClicked()));
connect(ui->buttonSave, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
//Init flags
m_clipboardUsed = false;
@ -55,20 +64,28 @@ LogViewDialog::~LogViewDialog(void)
{
QApplication::clipboard()->clear();
}
LAMEXP_DELETE(m_oldIcon);
LAMEXP_DELETE(m_acceptIcon);
LAMEXP_DELETE(ui);
}
int LogViewDialog::exec(const QStringList &logData)
{
textEdit->setPlainText(logData.join("\n"));
ui->textEdit->setPlainText(logData.join("\n"));
return QDialog::exec();
}
void LogViewDialog::copyButtonClicked(void)
{
QMimeData *mime = new QMimeData();
mime->setData("text/plain", textEdit->toPlainText().toUtf8().constData());
mime->setData("text/plain", ui->textEdit->toPlainText().toUtf8().constData());
QApplication::clipboard()->setMimeData(mime);
m_clipboardUsed = true;
m_oldIcon->swap(ui->buttonCopy->icon());
ui->buttonCopy->setIcon(*m_acceptIcon);
ui->buttonCopy->blockSignals(true);
QTimer::singleShot(1250, this, SLOT(restoreIcon()));
MessageBeep(MB_ICONINFORMATION);
}
@ -81,10 +98,20 @@ void LogViewDialog::saveButtonClicked(void)
QFile file(fileName);
if(file.open(QIODevice::WriteOnly))
{
QByteArray data = textEdit->toPlainText().toUtf8();
QByteArray data = ui->textEdit->toPlainText().toUtf8();
data.replace("\n", "\r\n");
file.write(data.constData(), data.size());
file.close();
}
}
}
void LogViewDialog::restoreIcon(void)
{
if(!m_oldIcon->isNull())
{
ui->buttonCopy->setIcon(*m_oldIcon);
ui->buttonCopy->blockSignals(false);
m_oldIcon->swap(QIcon());
}
}

View File

@ -21,11 +21,17 @@
#pragma once
#include "..\tmp\UIC_LogViewDialog.h"
#include <QDialog>
class LogViewDialog : public QDialog, private Ui::LogViewDialog
//Class declarations
class QIcon;
//UIC forward declartion
namespace Ui {
class LogViewDialog;
}
class LogViewDialog : public QDialog
{
Q_OBJECT
@ -39,6 +45,13 @@ public slots:
void copyButtonClicked(void);
void saveButtonClicked(void);
private slots:
void restoreIcon(void);
private:
Ui::LogViewDialog *ui; //for Qt UIC
bool m_clipboardUsed;
const QIcon *m_acceptIcon;
QIcon *m_oldIcon;
};