Commit 25d716c2 authored by frysch's avatar frysch

custom file extensions

add also some more default c++ file extensions
parent 9b38547b
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog>
static auto FILTERS = QStringList() << "*.cpp" << "*.cc" << "*.cxx" << "*.c++" << "*.c" << "*.tpp"
<< "*.hpp" << "*.hh" << "*.hxx" << "*.h++" << "*.h" << "*.cl";
static QStringList subDirs(const QDir &dir); static QStringList subDirs(const QDir &dir);
...@@ -48,6 +52,33 @@ void MainWindow::on_pushButton_removeFirst_clicked() ...@@ -48,6 +52,33 @@ void MainWindow::on_pushButton_removeFirst_clicked()
} }
} }
void MainWindow::on_pushButton_addExtension_clicked()
{
bool ok;
auto text = QInputDialog::getText(this, "Insert file extension",
"*.", QLineEdit::Normal, "txt", &ok);
if(ok) {
FILTERS << "*."+text;
emit updateFolderList();
}
}
void MainWindow::on_pushButton_removeFirstExtension_clicked()
{
if(!FILTERS.isEmpty()) {
FILTERS.removeFirst();
emit updateFolderList();
}
}
void MainWindow::on_pushButton_removeLastExtension_clicked()
{
if(!FILTERS.isEmpty()) {
FILTERS.removeLast();
emit updateFolderList();
}
}
void MainWindow::lines() void MainWindow::lines()
{ {
auto folderList = folders(); auto folderList = folders();
...@@ -88,28 +119,29 @@ QStringList MainWindow::folders() ...@@ -88,28 +119,29 @@ QStringList MainWindow::folders()
void MainWindow::countLines(const QStringList &folders) void MainWindow::countLines(const QStringList &folders)
{ {
auto filters = QStringList() << "*.cpp" << "*.h" << "*.cl";
QString analysis("$$$$$ ANALYSIS $$$$$\n\n" QString analysis("$$$$$ ANALYSIS $$$$$\n\n"
"located folders:\n" + folders.join("\n") + "\n\n" + "located folders:\n" + folders.join("\n") + "\n\n" +
"located files (" + filters.join(", ") + "):\n"); "located files with extensions\n" + FILTERS.join(", ") + ":\n\n");
QFile curFile; QFile curFile;
auto lineCounter = 0; auto lineCounter = 0;
for(QDir curDir : folders) if(!FILTERS.isEmpty()) {
{ for(QDir curDir : folders)
auto fileList = curDir.entryList(filters);
for(const auto &fileN : fileList)
{ {
curFile.setFileName(curDir.path()+"/" +fileN); auto fileList = curDir.entryList(FILTERS);
curFile.open(QIODevice::ReadOnly | QIODevice::Text); for(const auto &fileN : fileList)
auto allLines = QString(curFile.readAll()); {
auto listOFLines = allLines.split("\n"); curFile.setFileName(curDir.path()+"/" +fileN);
if(!ui->checkBox_emptyLines->isChecked()) curFile.open(QIODevice::ReadOnly | QIODevice::Text);
listOFLines.removeAll(""); auto allLines = QString(curFile.readAll());
auto curLength = listOFLines.length(); auto listOFLines = allLines.split("\n");
analysis.append(fileN + ": " + QString::number(curLength) + "\n"); if(!ui->checkBox_emptyLines->isChecked())
lineCounter += curLength; listOFLines.removeAll("");
curFile.close(); auto curLength = listOFLines.length();
analysis.append(fileN + ": " + QString::number(curLength) + "\n");
lineCounter += curLength;
curFile.close();
}
} }
} }
ui->textBrowser_analysis->setText(analysis); ui->textBrowser_analysis->setText(analysis);
......
...@@ -19,6 +19,11 @@ private slots: ...@@ -19,6 +19,11 @@ private slots:
void on_pushButton_addFolder_clicked(); void on_pushButton_addFolder_clicked();
void on_pushButton_removeLast_clicked(); void on_pushButton_removeLast_clicked();
void on_pushButton_removeFirst_clicked(); void on_pushButton_removeFirst_clicked();
void on_pushButton_addExtension_clicked();
void on_pushButton_removeFirstExtension_clicked();
void on_pushButton_removeLastExtension_clicked();
signals: signals:
void updateFolderList(); void updateFolderList();
private: private:
......
...@@ -61,6 +61,27 @@ ...@@ -61,6 +61,27 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton_addExtension">
<property name="text">
<string>add file extension</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_removeFirstExtension">
<property name="text">
<string>remove first extension</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_removeLastExtension">
<property name="text">
<string>remove last extension</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment