How to view a table of tables in Qt? - qt

I using Qt library. And I need to show a table of tables, and sort data in each sub-table.
For examlple something like this (2x2 table of 3x3 tables)
sub 1 | sub 2
-------------------------
| i | 0 | 0 | c | 0 | 0 | s
------------------------- u
| j | 0 | 0 | d | 0 | 0 | b
------------------------- 1
| k | 0 | 0 | e | 0 | 0 |
-------------------------------
| a | 0 | 0 | c | 0 | 0 |
------------------------- s
| b | 0 | 0 | d | 0 | 0 | u
------------------------- b
| c | 0 | 0 | e | 0 | 0 | 2
-------------------------
Any solutions are welcome.
ps. My idea is to implement a custom model with 2d array of models.

You can nest QTableView instances through use of the QAbstractItemView::setIndexWidget method. The data structure you use to maintain the QAbstractTableModel instances is inconsequential as long as each QTableView is assigned an appropriate model instance.

Related

Overlap two equally dimension matrices in R

I have two matrices A and B, both have the same dimensions and are binary in nature. I want to overlap matrix A on matrix B.
Matrix A:
| Gene A | Gene B |
| -------- | ----------- |
| 0 | 1 |
| 0 | 1 |
Matrix B:
| Gene A | Gene B |
| -------- | ----------- |
| 1 | 0 |
| 0 | 0 |
Result:
Matrix C:
| Gene A | Gene B |
| -------- | ----------- |
| 1 | 1 |
| 0 | 1 |
The resultant matrix will also have the same dimension as the input.
How can this be done?
Please let me know.

Sqlite count occurence per year

So let's say I have a table in my Sqlite database with some information about some files, with the following structure:
| id | file format | creation date |
----------------------------------------------------------
| 1 | Word | 2010:02:12 13:31:33+01:00 |
| 2 | PSD | 2021:02:23 15:44:51+01:00 |
| 3 | Word | 2019:02:13 14:18:11+01:00 |
| 4 | Word | 2010:02:12 13:31:20+01:00 |
| 5 | Word | 2003:05:25 18:55:10+02:00 |
| 6 | PSD | 2014:07:20 20:55:58+02:00 |
| 7 | Word | 2014:07:20 21:09:24+02:00 |
| 8 | TIFF | 2011:03:30 11:56:56+02:00 |
| 9 | PSD | 2015:07:15 14:34:36+02:00 |
| 10 | PSD | 2009:08:29 11:25:57+02:00 |
| 11 | Word | 2003:05:25 20:06:18+02:00 |
I would like results that show me a chronology of how many of each file format were created in a given year – something along the lines of this:
|Format| 2003 | 2009 | 2010 | 2011 | 2014 | 2015 | 2019 | 2021 |
----------------------------------------------------------------
| Word | 2 | 0 | 0 | 2 | 0 | 0 | 2 | 0 |
| PSD | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| TIFF | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
I've gotten kinda close (I think) with this, but am stuck:
SELECT
file_format,
COUNT(CASE file_format WHEN creation_date LIKE '%2010%' THEN 1 ELSE 0 END),
COUNT(CASE file_format WHEN creation_date LIKE '%2011%' THEN 1 ELSE 0 END),
COUNT(CASE file_format WHEN creation_date LIKE '%2012%' THEN 1 ELSE 0 END)
FROM
fileinfo
GROUP BY
file_format;
When I do this I am getting unique amounts for each file format, but the same count for every year…
|Format| 2010 | 2011 | 2012 |
-----------------------------
| Word | 4 | 4 | 4 |
| PSD | 1 | 1 | 1 |
| TIFF | 6 | 6 | 6 |
Why am I getting that incorrect tally, and moreover, is there a smarter way of querying that doesn't rely on the year being statically searched for as a string for every single year? If it helps, the column headers and row headers could be switched – doesn't matter to me. Please help a n00b :(
Use SUM() aggregate function for conditional aggregation:
SELECT file_format,
SUM(creation_date LIKE '2010%') AS `2010`,
SUM(creation_date LIKE '2011%') AS `2011`,
..........................................
FROM fileinfo
GROUP BY file_format;
See the demo.

(AVB)&(AV~B) is logically equivalent to ~~A, it that true or false?

(AVB)&(AV~B) is logically equivalent to ~~A?
It kind of confused me since they are in different dimension.
Starting from:
(A∨B)∧(A∨¬B)
One can first apply one of De Morgan's laws to the AND:
¬(¬(A∨B)∨¬(A∨¬B))
Next, one of De Morgan's laws can be applied to each side:
¬((¬A∧¬B)∨(¬A∧B))
By applying distributivity of AND over OR in reverse, ¬A can be extracted:
¬(¬A∧(¬B∨B))
By complementation, ¬B∨B is 1:
¬(¬A∧1)
By identity for AND:
¬¬A
Applying double negation:
A
This goes through your target ¬¬A without going through simple A. It's much simpler not to do that.
Starting again from:
(A∨B)∧(A∨¬B)
By applying distributivity of OR over AND in reverse, A can be extracted:
A∨(B∧¬B)
By complementation, B∨¬B is 1:
A∧1
By identity for AND:
A
Applying double negation in reverse:
¬¬A
Since you mention doing it by truth table, here's my go at showing that they're equivalent that way:
+---+---+----+----+-------+--------+--------------+-----+
| A | B | ¬A | ¬B | (A∨B) | (A∨¬B) | (A∨B)∧(A∨¬B) | ¬¬A |
+---+---+----+----+-------+--------+--------------+-----+
| 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 |
+---+---+----+----+-------+--------+--------------+-----+

Can modal operator be defined as a boolean function?

Let us consider for simplicity only Kripke structures with a single agent whose knowledge is described by the modal operator K. We know that in all the corresponding Kripke structures where K is interpreted by equivalence there holds for any formula A
a) the formula KA -> A (Knowledge Axiom) is valid ,
b) but the formulas A -> KA and ¬KA are not valid.
Utilize these facts to show that such a behaviour of the modal operator K cannot be encoded by any boolean function (ie. Truth values defined by a table).
Hint: Suppose the truth value of KA can be calculated from the truth value of A using a truth table for K (in the same way as ¬A is calculated form A). Consider all possible truth tables for K and show that none of them grants the properties a) and b) mentioned above.
I dont understand that hint... making truth table of K is like constructing truth table of negation symbol ¬ , which in my mind doesnt make sense I think it makes sense only to make negation of something and not just negation
Consider all possible truth tables for K:
| A | K₁A | K₂A | K₃A | K₄A |
—————————————————————————————
| 1 | 1 | 1 | 0 | 0 |
—————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
Show that none of them grants the properties a) and b) mentioned above.
Case 1
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 1 | 1 | 1 | 0 |
—————————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
In this case, KA->A is not a tautology.
Case 2
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 1 | 1 | 1 | 0 |
—————————————————————————————————
| 0 | 0 | 1 | 1 | 1 |
In this case, A->KA is a tautology.
Case 3
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 0 | 1 | 0 | 1 |
—————————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
In this case, KA->A is not a tautology.
Case 4
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 0 | 1 | 0 | 1 |
—————————————————————————————————
| 0 | 0 | 1 | 1 | 1 |
In this case, ¬KA is a tautology.
Can desired behaviour of K be encoded by many-valued matrix?
For alethic modal systems, the answer is the following:
3 values are insufficient,
4 values are sufficient for the so-called basic modal logic,
any finite number of values is insufficient for syntactically “full” and deductively “natural” modal system.
See, e. g., introductory parts in the article by Jean-Yves Beseau.
I hope these results are relevant for epistemic modal systems.

Is there an sqlite function that can check if a field matches a certain value and return 0 or 1?

Consider the following sqlite3 table:
+------+------+
| col1 | col2 |
+------+------+
| 1 | 200 |
| 1 | 200 |
| 1 | 100 |
| 1 | 200 |
| 2 | 400 |
| 2 | 200 |
| 2 | 100 |
| 3 | 200 |
| 3 | 200 |
| 3 | 100 |
+------+------+
I'm trying to write a query that will select the entire table and return 1 if the value in col2 is 200, and 0 otherwise. For example:
+------+--------------------+
| col1 | SOMEFUNCTION(col2) |
+------+--------------------+
| 1 | 1 |
| 1 | 1 |
| 1 | 0 |
| 1 | 1 |
| 2 | 0 |
| 2 | 1 |
| 2 | 0 |
| 3 | 1 |
| 3 | 1 |
| 3 | 0 |
+------+--------------------+
What is SOMEFUNCTION()?
Thanks in advance...
In SQLite, boolean values are just integer values 0 and 1, so you can use the comparison directly:
SELECT col1, col2 = 200 AS SomeFunction FROM MyTable
Like described in Does sqlite support any kind of IF(condition) statement in a select you can use the case keyword.
SELECT col1,CASE WHEN col2=200 THEN 1 ELSE 0 END AS col2 FROM table1

Resources