Commit 98102f0e authored by frysch's avatar frysch

add files

parent af2082e8
### C++ ###
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
*.exp
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# Qt-es
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
qrc_*.cpp
ui_*.h
Makefile*
*-build-*
# QtCreator
*.autosave
*.cpp.*
*.c.*
*.cc.*
*.h.*
*.hpp.*
#QtCtreator Qml
*.qmlproject.user
*.qmlproject.user.*
# Binary Data
*.bin
*.nrrd
*.spec
*.den
\ No newline at end of file
#-------------------------------------------------
#
# Project created by QtCreator 2017-05-04T08:43:52
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = LineCounter
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
static QStringList subDirs(const QDir &dir);
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->checkBox_subFolders,&QCheckBox::toggled,this,&MainWindow::updateFolderList);
connect(ui->checkBox_emptyLines,&QCheckBox::toggled,this,&MainWindow::updateFolderList);
connect(this,&MainWindow::updateFolderList,this,&MainWindow::lines);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_addFolder_clicked()
{
auto name = QFileDialog::getExistingDirectory(this,"Select a folder to add");
if(!name.isEmpty()) ui->textBrowser->append(name);
emit updateFolderList();
}
void MainWindow::on_pushButton_removeLast_clicked()
{
auto folderList = folders();
if(!folderList.isEmpty())
{
folderList.removeLast();
ui->textBrowser->setPlainText(folderList.join("\n"));
emit updateFolderList();
}
}
void MainWindow::on_pushButton_removeFirst_clicked()
{
auto folderList = folders();
if(!folderList.isEmpty())
{
folderList.removeFirst();
ui->textBrowser->setPlainText(folderList.join("\n"));
emit updateFolderList();
}
}
void MainWindow::lines()
{
auto folderList = folders();
if(folderList.isEmpty()){
ui->label_number->setText("0");
ui->textBrowser_analysis->setText("");
return;
}
if(ui->checkBox_subFolders->isChecked())
{
QStringList subs;
for(const auto& f : folderList)
subs.append(subDirs(f));
folderList.append(subs);
}
auto count = countLines(folderList);
ui->label_number->setText(QString::number(count));
}
QStringList subDirs(const QDir &dir)
{
QStringList ret;
auto subs = dir.entryList(QDir::Dirs);
subs.removeOne(".");
subs.removeOne("..");
for(auto &s : subs)
s = dir.absolutePath()+"/"+s;
for(const auto &s : subs)
ret.append(subDirs(s));
return subs + ret;
}
QStringList MainWindow::folders()
{
auto content = ui->textBrowser->toPlainText();
return content.isEmpty() ? QStringList() : content.split("\n");
}
int MainWindow::countLines(const QStringList &folders)
{
QStringList filters = QStringList() << "*.cpp" << "*.h" << "*.cl";
QString analysis("$$$$$ ANALYSIS $$$$$\n\n"
"located folders:\n" + folders.join("\n") + "\n\n" +
"located files (" + filters.join(", ") + "):\n");
int lineCounter = 0;
foreach(QString folder, folders)
{
QDir codeDir(folder);
QStringList fileList = codeDir.entryList(filters);
foreach(QString fileN, fileList)
{
QFile file(codeDir.path()+"/" +fileN);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QString allLines = file.readAll();
auto theLines = allLines.split("\n");
if(!ui->checkBox_emptyLines->isChecked())
theLines.removeAll("");
auto curLength = theLines.length();
analysis.append(fileN + ": " + QString::number(curLength) + "\n");
lineCounter += curLength;
file.close();
}
}
ui->textBrowser_analysis->setText(analysis);
return lineCounter;
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_addFolder_clicked();
void on_pushButton_removeLast_clicked();
void on_pushButton_removeFirst_clicked();
signals:
void updateFolderList();
private:
void lines();
int countLines(const QStringList &folders);
QStringList folders();
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1024</width>
<height>384</height>
</rect>
</property>
<property name="windowTitle">
<string>Line Counter</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QTextBrowser" name="textBrowser"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="pushButton_addFolder">
<property name="text">
<string>add folder...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_removeFirst">
<property name="text">
<string>remove first</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_removeLast">
<property name="text">
<string>remove last</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_subFolders">
<property name="text">
<string>include subfolders</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_emptyLines">
<property name="text">
<string>count empty lines</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>total lines:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_number">
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QTextBrowser" name="textBrowser_analysis"/>
</item>
</layout>
</widget>
<action name="actionExit">
<property name="text">
<string>Exit</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
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