341 lines
8.4 KiB
C++
341 lines
8.4 KiB
C++
/**
|
|
* @author Rick Chan (cy187lion@sina.com)
|
|
* @date 2020-08-28
|
|
*/
|
|
|
|
#include "qtproaddfilehelper.h"
|
|
#include "ui_qtproaddfilehelper.h"
|
|
#include <QDir>
|
|
#include <QMessageBox>
|
|
#include <QTextStream>
|
|
#include <QFileDialog>
|
|
#include <QStandardPaths>
|
|
|
|
QtProAddFileHelper::QtProAddFileHelper(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::QtProAddFileHelper)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
StatusLabel = new QLabel(this);
|
|
StatusLabel->adjustSize();
|
|
ui->statusBar->addWidget(StatusLabel);
|
|
StatusLabel->setText("By: Rick Chan @Giraffe Beta:2.3.1");
|
|
|
|
CheckBoxes.clear();
|
|
CheckBoxes.append(ui->cCheckBox);
|
|
CheckBoxes.append(ui->CpupuCheckBox);
|
|
CheckBoxes.append(ui->cppCheckBox);
|
|
CheckBoxes.append(ui->cxxCheckBox);
|
|
CheckBoxes.append(ui->ccCheckBox);
|
|
CheckBoxes.append(ui->tccCheckBox);
|
|
CheckBoxes.append(ui->hCheckBox);
|
|
CheckBoxes.append(ui->hpupuCheckBox);
|
|
CheckBoxes.append(ui->hppCheckBox);
|
|
CheckBoxes.append(ui->hxxCheckBox);
|
|
CheckBoxes.append(ui->MkfCheckBox);
|
|
CheckBoxes.append(ui->asmCheckBox);
|
|
CheckBoxes.append(ui->sCheckBox);
|
|
CheckBoxes.append(ui->xmlCheckBox);
|
|
|
|
for(QList<QCheckBox*>::Iterator itr=CheckBoxes.begin();
|
|
itr!=CheckBoxes.end();
|
|
itr++)
|
|
connect(*itr, &QCheckBox::clicked, this, &QtProAddFileHelper::OnCheckBoxesClicked);
|
|
}
|
|
|
|
QtProAddFileHelper::~QtProAddFileHelper()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void QtProAddFileHelper::SetUiEnable(bool en)
|
|
{
|
|
ui->OKButton->setEnabled(en);
|
|
ui->ProEdit->setEnabled(en);
|
|
ui->PathEdit->setEnabled(en);
|
|
|
|
ui->cCheckBox->setEnabled(en);
|
|
ui->CpupuCheckBox->setEnabled(en);
|
|
ui->cppCheckBox->setEnabled(en);
|
|
ui->cxxCheckBox->setEnabled(en);
|
|
ui->ccCheckBox->setEnabled(en);
|
|
ui->tccCheckBox->setEnabled(en);
|
|
|
|
ui->hCheckBox->setEnabled(en);
|
|
ui->hpupuCheckBox->setEnabled(en);
|
|
ui->hppCheckBox->setEnabled(en);
|
|
ui->hxxCheckBox->setEnabled(en);
|
|
|
|
ui->MkfCheckBox->setEnabled(en);
|
|
ui->asmCheckBox->setEnabled(en);
|
|
ui->sCheckBox->setEnabled(en);
|
|
ui->xmlCheckBox->setEnabled(en);
|
|
|
|
ui->RelaPthcheckBox->setEnabled(en);
|
|
}
|
|
|
|
void QtProAddFileHelper::on_OKButton_clicked()
|
|
{
|
|
SetUiEnable(false);
|
|
|
|
/**
|
|
* @brief 获取搜索路径
|
|
*/
|
|
QDir schDir(ui->PathEdit->text());
|
|
/** 判断路径是否合法 */
|
|
if (schDir.path().isEmpty() || !schDir.exists())
|
|
{
|
|
QMessageBox WrrMsg;
|
|
WrrMsg.setInformativeText("请输入有效的搜索路径!");
|
|
WrrMsg.show();
|
|
WrrMsg.exec();
|
|
|
|
SetUiEnable(true);
|
|
return;
|
|
}
|
|
ui->PathEdit->setText(schDir.path());
|
|
|
|
/**
|
|
* @brief 获取项目文件
|
|
*/
|
|
QFileInfo proFileInfo(ui->ProEdit->text());
|
|
/** 判断项目文件是否合法 */
|
|
if(proFileInfo.filePath().isEmpty() || false==proFileInfo.exists() || "pro"!=proFileInfo.suffix().toLower() || false==proFileInfo.isFile())
|
|
{
|
|
QMessageBox WrrMsg;
|
|
WrrMsg.setInformativeText("请输入有效的项目文件!");
|
|
WrrMsg.show();
|
|
WrrMsg.exec();
|
|
|
|
SetUiEnable(true);
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* | H |----------------------------| L |
|
|
* | | tcc | cc | cxx | cpp | c++ | c |
|
|
* | 00 | 1 | 1 | 1 | 1 | 1 | 1 |
|
|
*
|
|
* | | hxx | hpp | h++ | h |
|
|
* | 0000 | 1 | 1 | 1 | 1 |
|
|
*
|
|
* | |.xml.|.s.|.asm.|.Makefile.|
|
|
* | 0000 | 1 | 1 | 1 | 1 |
|
|
*/
|
|
FILE_TYPES selectedFile;
|
|
/**< Sources */
|
|
if(ui->cCheckBox->isChecked())
|
|
{
|
|
selectedFile.Source |= 0x01;
|
|
}
|
|
if(ui->CpupuCheckBox->isChecked())
|
|
{
|
|
selectedFile.Source |= 0x02;
|
|
}
|
|
if(ui->cppCheckBox->isChecked())
|
|
{
|
|
selectedFile.Source |= 0x04;
|
|
}
|
|
if(ui->cxxCheckBox->isChecked())
|
|
{
|
|
selectedFile.Source |= 0x08;
|
|
}
|
|
if(ui->ccCheckBox->isChecked())
|
|
{
|
|
selectedFile.Source |= 0x10;
|
|
}
|
|
if(ui->tccCheckBox->isChecked())
|
|
{
|
|
selectedFile.Source |= 0x20;
|
|
}
|
|
|
|
/**< Headers */
|
|
if(ui->hCheckBox->isChecked())
|
|
{
|
|
selectedFile.Header |= 0x01;
|
|
}
|
|
if(ui->hpupuCheckBox->isChecked())
|
|
{
|
|
selectedFile.Header |= 0x02;
|
|
}
|
|
if(ui->hppCheckBox->isChecked())
|
|
{
|
|
selectedFile.Header |= 0x04;
|
|
}
|
|
if(ui->hxxCheckBox->isChecked())
|
|
{
|
|
selectedFile.Header |= 0x08;
|
|
}
|
|
|
|
/**< Others */
|
|
if(ui->MkfCheckBox->isChecked())
|
|
{
|
|
selectedFile.Other |= 0x01;
|
|
}
|
|
if(ui->asmCheckBox->isChecked())
|
|
{
|
|
selectedFile.Other |= 0x02;
|
|
}
|
|
if(ui->sCheckBox->isChecked())
|
|
{
|
|
selectedFile.Other |= 0x04;
|
|
}
|
|
if(ui->xmlCheckBox->isChecked())
|
|
{
|
|
selectedFile.Other |= 0x08;
|
|
}
|
|
|
|
if(0==selectedFile.Source && 0==selectedFile.Header && 0==selectedFile.Other)
|
|
{
|
|
QMessageBox WrrMsg;
|
|
WrrMsg.setInformativeText("没有选中任何文件类型!");
|
|
WrrMsg.show();
|
|
WrrMsg.exec();
|
|
|
|
SetUiEnable(true);
|
|
return;
|
|
}
|
|
|
|
if(ui->RelaPthcheckBox->isChecked())
|
|
{
|
|
KEngine = new Engine(proFileInfo.absolutePath(), schDir.path(), proFileInfo.filePath(), selectedFile, this);
|
|
}
|
|
else
|
|
{
|
|
KEngine = new Engine("", schDir.path(), proFileInfo.filePath(), selectedFile, this);
|
|
}
|
|
connect(KEngine, SIGNAL(EngineProcessing(bool,int)), this, SLOT(on_EngineProcessing(bool,int)));
|
|
KEngine->start();
|
|
}
|
|
|
|
void QtProAddFileHelper::on_EngineProcessing(bool done, int processedCount)
|
|
{
|
|
if(done)
|
|
{
|
|
if(NULL!=KEngine)
|
|
{
|
|
delete KEngine;
|
|
KEngine = NULL;
|
|
}
|
|
SetUiEnable(true);
|
|
StatusLabel->setText("处理完成!");
|
|
}
|
|
else
|
|
{
|
|
StatusLabel->setText("已处理文件数:"+QString::number(processedCount,10));
|
|
}
|
|
}
|
|
|
|
void QtProAddFileHelper::on_ProButton_clicked()
|
|
{
|
|
QFileDialog *fileDialog = new QFileDialog(this);
|
|
fileDialog->setWindowTitle("打开Qt项目件");
|
|
|
|
QString lastOpenPth;
|
|
if(!ui->PathEdit->text().isEmpty())
|
|
{
|
|
lastOpenPth = ui->PathEdit->text();
|
|
}
|
|
else
|
|
{
|
|
lastOpenPth = QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).at(0);
|
|
}
|
|
|
|
QDir tstPth(lastOpenPth);
|
|
if(tstPth.exists())
|
|
{
|
|
fileDialog->setDirectory(lastOpenPth);
|
|
}
|
|
else
|
|
{
|
|
fileDialog->setDirectory(QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).at(0));
|
|
}
|
|
|
|
fileDialog->setNameFilter("Qt项目件(*.pro)");
|
|
if(fileDialog->exec() == QDialog::Accepted)
|
|
{
|
|
ui->ProEdit->setText(fileDialog->selectedFiles().at(0));
|
|
}
|
|
}
|
|
|
|
void QtProAddFileHelper::on_PathButton_clicked()
|
|
{
|
|
QFileDialog *fileDialog = new QFileDialog(this);
|
|
fileDialog->setWindowTitle("选择搜索路径");
|
|
|
|
QString lastOpenPth;
|
|
if(!ui->ProEdit->text().isEmpty())
|
|
{
|
|
lastOpenPth = ui->ProEdit->text();
|
|
}
|
|
else if(!ui->PathEdit->text().isEmpty())
|
|
{
|
|
lastOpenPth = ui->PathEdit->text();
|
|
}
|
|
else
|
|
{
|
|
lastOpenPth = QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).at(0);
|
|
}
|
|
|
|
QDir tstPth(lastOpenPth);
|
|
if(tstPth.exists())
|
|
{
|
|
fileDialog->setDirectory(lastOpenPth);
|
|
}
|
|
else
|
|
{
|
|
fileDialog->setDirectory(QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).at(0));
|
|
}
|
|
|
|
fileDialog->setFileMode(QFileDialog::Directory);
|
|
if(fileDialog->exec() == QDialog::Accepted)
|
|
{
|
|
ui->PathEdit->setText(fileDialog->selectedFiles().at(0));
|
|
}
|
|
}
|
|
|
|
void QtProAddFileHelper::on_PathEdit_editingFinished()
|
|
{
|
|
ui->PathEdit->setText(ui->PathEdit->text().replace("\\","/"));
|
|
if(ui->ProEdit->text().isEmpty())
|
|
{
|
|
ui->ProEdit->setText(ui->PathEdit->text());
|
|
}
|
|
}
|
|
|
|
void QtProAddFileHelper::on_SeleAllcheckBox_clicked(bool checked)
|
|
{
|
|
if(checked)
|
|
{
|
|
for(QList<QCheckBox*>::Iterator itr=CheckBoxes.begin();
|
|
itr!=CheckBoxes.end();
|
|
itr++)
|
|
(*itr)->setChecked(true);
|
|
}
|
|
else
|
|
{
|
|
for(QList<QCheckBox*>::Iterator itr=CheckBoxes.begin();
|
|
itr!=CheckBoxes.end();
|
|
itr++)
|
|
(*itr)->setChecked(false);
|
|
}
|
|
}
|
|
|
|
void QtProAddFileHelper::OnCheckBoxesClicked(bool checked)
|
|
{
|
|
if(checked)
|
|
{
|
|
for(QList<QCheckBox*>::Iterator itr=CheckBoxes.begin();
|
|
itr!=CheckBoxes.end();
|
|
itr++)
|
|
{
|
|
if(!(*itr)->isChecked())
|
|
return;
|
|
}
|
|
ui->SeleAllcheckBox->setChecked(true);
|
|
}
|
|
else
|
|
ui->SeleAllcheckBox->setChecked(false);
|
|
}
|