Skip to content

Commit 065b10e

Browse files
author
Alexander Bychuk
committed
add : tooltip for export table item
1 parent 924ac47 commit 065b10e

File tree

5 files changed

+43
-48
lines changed

5 files changed

+43
-48
lines changed

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "mainwindow.h"
22
#include <QApplication>
33
#include <QCommandLineParser>
4-
#include "qldd.h"
54

65
int main(int argc, char *argv[]) {
6+
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
77
QApplication app(argc, argv);
88

99
QApplication::setApplicationName("Qldd");

mainwindow.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "mainwindow.h"
22
#include "ui_mainwindow.h"
3-
#include <QFile>
43
#include <QTextStream>
5-
#include <iostream>
64
#include <QFileDialog>
75
#include <QShortcut>
86
#include <QMessageBox>
@@ -54,7 +52,7 @@ void MainWindow::reset(const QString &fileName) {
5452
QTreeWidgetItem *header = ui->treeWidget->headerItem();
5553
header->setText(0, "Dependency");
5654
qldd->fillDependency(*ui->treeWidget);
57-
qldd->fillExportTable(*ui->listWidgetExportTable);
55+
qldd->fillExportTable(*ui->listWidgetExportTable, "");
5856

5957
ui->lineEditFileName->setText(qldd->getBinaryName());
6058
ui->lineEditFileSize->setText(qldd->getStringFileSize() + "( " + QString::number(qldd->getFileSize()) + " bytes )");

mainwindow.ui

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,7 @@
2424
</property>
2525
<widget class="QWidget" name="centralWidget">
2626
<layout class="QGridLayout" name="gridLayout_6">
27-
<item row="0" column="0" rowspan="4" colspan="2">
28-
<widget class="QGroupBox" name="groupBoxDependency">
29-
<property name="font">
30-
<font>
31-
<family>Ubuntu Mono</family>
32-
</font>
33-
</property>
34-
<property name="title">
35-
<string/>
36-
</property>
37-
<property name="alignment">
38-
<set>Qt::AlignJustify|Qt::AlignTop</set>
39-
</property>
40-
<layout class="QGridLayout" name="gridLayout">
41-
<property name="leftMargin">
42-
<number>3</number>
43-
</property>
44-
<property name="topMargin">
45-
<number>0</number>
46-
</property>
47-
<property name="bottomMargin">
48-
<number>0</number>
49-
</property>
50-
<property name="verticalSpacing">
51-
<number>12</number>
52-
</property>
53-
</layout>
54-
</widget>
55-
</item>
56-
<item row="1" column="0">
27+
<item row="0" column="0">
5728
<widget class="QTabWidget" name="tabWidget">
5829
<property name="currentIndex">
5930
<number>0</number>
@@ -69,6 +40,12 @@
6940
<enum>Qt::Horizontal</enum>
7041
</property>
7142
<widget class="QTreeWidget" name="treeWidget">
43+
<property name="sizePolicy">
44+
<sizepolicy hsizetype="Maximum" vsizetype="Expanding">
45+
<horstretch>0</horstretch>
46+
<verstretch>0</verstretch>
47+
</sizepolicy>
48+
</property>
7249
<column>
7350
<property name="text">
7451
<string notr="true">1</string>
@@ -77,6 +54,9 @@
7754
</widget>
7855
<widget class="QWidget" name="layoutWidget">
7956
<layout class="QVBoxLayout" name="verticalLayout">
57+
<property name="sizeConstraint">
58+
<enum>QLayout::SetDefaultConstraint</enum>
59+
</property>
8060
<property name="topMargin">
8161
<number>18</number>
8262
</property>
@@ -599,7 +579,6 @@
599579
</rect>
600580
</property>
601581
</widget>
602-
<widget class="QStatusBar" name="statusBar"/>
603582
</widget>
604583
<layoutdefault spacing="6" margin="11"/>
605584
<resources/>

qldd.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
#include <QDateTime>
1212
#include <QTextStream>
1313
#include <QDir>
14-
#include <QProcess>
1514
#include <cxxabi.h>
1615

17-
#define MAXBUFFER 512
18-
1916
#ifdef __APPLE__
2017
#define CMD_LDD "otool -L"
2118
#define NM "nm -g"
@@ -33,10 +30,14 @@ void execAndDoOnEveryLine(const std::string &execString, const Action &action) {
3330
QTextStream nmOutStream(stream.get());
3431
QString line;
3532
do {
36-
line = nmOutStream.readLine().trimmed();
33+
line = nmOutStream.readLine();
3734
if (line.isNull()) {
3835
break;
3936
}
37+
line = line.trimmed();
38+
if (line.isEmpty()) {
39+
break;
40+
}
4041
action(line);
4142
} while (!line.isNull());
4243
}
@@ -64,6 +65,9 @@ QLdd::QLdd(QString fileName, QString lddDirPath)
6465
_ownerName.append(_fileInfo.owner());
6566
_groupName.append(_fileInfo.group());
6667

68+
_fileSize = getHumanReadableDataSize();
69+
}
70+
QString QLdd::getHumanReadableDataSize() const {
6771
auto size = static_cast<double>(_fileInfo.size());
6872
int i = 0;
6973
const char *units[] = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
@@ -73,11 +77,10 @@ QLdd::QLdd(QString fileName, QString lddDirPath)
7377
}
7478
char buf[512] = {0};
7579
sprintf(buf, "%.*f %s", i, size, units[i]);
76-
_fileSize.clear();
77-
_fileSize.append(buf);
80+
return QString::fromLocal8Bit(buf);
7881
}
7982

80-
QLdd::~QLdd() {}
83+
QLdd::~QLdd() = default;
8184

8285
int64_t QLdd::getFileSize() const { return _fileInfo.size(); }
8386

@@ -157,13 +160,13 @@ void QLdd::fillDependency(QTreeWidget &treeWidget) {
157160
QDir::setCurrent(_lddDirPath);
158161
}
159162

160-
void QLdd::fillExportTable(QListWidget &listWidget) {
163+
void QLdd::fillExportTable(QListWidget &listWidget, const QString &filter) {
161164
listWidget.clear();
162165
int status = 0;
163166
std::stringstream ss;
164167
ss << NM << " " << _fileName.toStdString() << " | grep \\ T\\ ";
165168

166-
execAndDoOnEveryLine(ss.str(), [&status, &listWidget](const QString &line) {
169+
execAndDoOnEveryLine(ss.str(), [&status, &listWidget, &filter](const QString &line) {
167170
QStringList info = line.split(" ");
168171
QString demangled(info.at(2));
169172
char *realname = abi::__cxa_demangle(info.at(2).toStdString().c_str(), nullptr, nullptr, &status);
@@ -174,7 +177,13 @@ void QLdd::fillExportTable(QListWidget &listWidget) {
174177
demangled.replace(":__cxx11:", "");
175178
demangled.replace("std::basic_string<char, std::char_traits<char>, std::allocator<char> >", "std::string");
176179
}
177-
listWidget.addItem(new QListWidgetItem(info.at(0) + " " + demangled));
180+
QScopedPointer<QListWidgetItem> item(new QListWidgetItem(info.at(0) + " " + demangled));
181+
item->setToolTip(demangled);
182+
if (!filter.isEmpty() && demangled.contains(filter, Qt::CaseInsensitive)) {
183+
listWidget.addItem(item.take());
184+
} else if (filter.isEmpty()) {
185+
listWidget.addItem(item.take());
186+
}
178187
});
179188
}
180189

qldd.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,34 @@
66
#include <QListWidget>
77
#include <QFileInfo>
88

9-
typedef struct _QMOD {
9+
struct QMOD {
1010
bool read;
1111
bool write;
1212
bool execute;
13-
} QMOD;
13+
};
1414

1515
class QLdd {
1616
public:
17+
1718
QLdd(QString fileName, QString lddDirPath);
1819
virtual ~QLdd();
20+
1921
int64_t getFileSize() const;
2022
const QString &getStringFileSize() const;
23+
2124
void fillDependency(QTreeWidget &treeWidget);
22-
void fillExportTable(QListWidget &listWidget);
25+
26+
void fillExportTable(QListWidget &listWidget, const QString& filter);
27+
2328
QString getPathOfBinary();
2429
QString getBinaryName();
30+
2531
const QString &getCreatedTime();
2632
const QString &getAccessTime();
2733
const QString &getModifyTime();
34+
2835
QString getInfo();
36+
2937
const QMOD &getOwnerMod() const;
3038
void setOwnerMod(const QMOD &ownerMod);
3139

@@ -55,6 +63,7 @@ class QLdd {
5563
QMOD _otherMod{};
5664
QString _ownerName;
5765
QString _groupName;
66+
QString getHumanReadableDataSize() const;
5867
};
5968

6069
#endif // QLDD_H

0 commit comments

Comments
 (0)